高校数学の質問スレ(医者・東大卒専用) Part438 (894レス)
高校数学の質問スレ(医者・東大卒専用) Part438 http://rio2016.5ch.net/test/read.cgi/math/1723152147/
上
下
前
次
1-
新
通常表示
512バイト分割
レス栞
843: 132人目の素数さん [sage] 2025/05/24(土) 08:17:52.86 ID:VetM3rz7 library(rjags) # Fit a Bayesian logistic regression model using JAGS and return predictions and posterior summaries fit_bayesian_logistic_jags <- function(data, formula, newdata, n.chains = 3, n.iter = 5000, n.burnin = 1000) { # Extract response variable name from the formula response_var <- all.vars(formula)[1] y <- data[[response_var]] # Convert factor response to binary numeric (0/1) if (is.factor(y)) y <- as.numeric(y) - 1 y <- as.numeric(y) # Construct design matrices for training and new data X <- model.matrix(formula, data) new_X <- model.matrix(delete.response(terms(formula)), newdata) # Prepare data list for JAGS jags_data <- list( y = y, X = X, n = nrow(X), p = ncol(X), new_X = new_X, scale_beta = rep(2.5, ncol(X)) # Prior scale for each coefficient ) # Define the JAGS model model_string <- " model { for (j in 1:p) { beta[j] ~ dt(0, 1 / pow(scale_beta[j], 2), 1) } for (i in 1:n) { logit_p[i] <- inprod(X[i,], beta[]) y[i] ~ dbern(1 / (1 + exp(-logit_p[i]))) } new_logit <- inprod(new_X[1,], beta[]) new_p <- 1 / (1 + exp(-new_logit)) } " # Initialize and run the JAGS model model <- jags.model(textConnection(model_string), data = jags_data, n.chains = n.chains, quiet = TRUE) update(model, n.burnin) # Draw posterior samples samples <- coda.samples(model, c("beta", "new_p"), n.iter - n.burnin) mat <- as.matrix(samples) # Return results list( model = samples, predicted_prob = mean(mat[, "new_p"]), summary = summary(samples) ) } http://rio2016.5ch.net/test/read.cgi/math/1723152147/843
メモ帳
(0/65535文字)
上
下
前
次
1-
新
書
関
写
板
覧
索
設
栞
歴
あと 51 レスあります
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.010s