高校数学の質問スレ(医者・東大卒専用) Part438 (894レス)
高校数学の質問スレ(医者・東大卒専用) Part438 http://rio2016.5ch.net/test/read.cgi/math/1723152147/
上
下
前次
1-
新
通常表示
512バイト分割
レス栞
抽出解除
必死チェッカー(本家)
(べ)
自ID
レス栞
あぼーん
リロード規制
です。10分ほどで解除するので、
他のブラウザ
へ避難してください。
854: 132人目の素数さん [sage] 2025/05/30(金) 06:24:20.07 ID:zoAuXcvc par(bty="l") y = c(43, 24, 100, 35, 85) yn = max(y) n = length(y) B = 200 like = numeric(B) for(i in yn:B) { like[i] = 1 / (i^n) } pmf = like / sum(like) mean = sum((1:B) * pmf) plot(pmf, main="Posterior PMF of N", xlab="N", ylab="Probability", type="h", col="blue") plot(cumsum(pmf), main="Posterior CDF of N", xlab="N", ylab="Cumulative Probability", type="s", col="blue") abline(h=0.95, lty=3) c(lower=yn, mean=mean, upper=which(cumsum(pmf) > 0.95)[1]) sd = sqrt(sum(((1:B) - mean)^2 * pmf)) prob_N_gt_150 = sum(pmf[151:B]) cat("Posterior Mean:", mean, "\n") cat("Posterior Standard Deviation:", sd, "\n") cat("P(N > 150):", prob_N_gt_150, "\n") http://rio2016.5ch.net/test/read.cgi/math/1723152147/854
855: 132人目の素数さん [sage] 2025/05/30(金) 19:44:31.38 ID:zoAuXcvc (* pbetat関数の定義 *) pbetat[p0_, prob_, ab_, data_] := Module[{a, b, s, f, lbf, bf, post}, a = ab[[1]]; b = ab[[2]]; s = data[[1]]; f = data[[2]]; lbf = s * Log[p0] + f * Log[1 - p0] + Log@Beta[a, b] - Log@Beta[a + s, b + f]; bf = Exp[lbf]; post = prob * bf / (prob * bf + 1 - prob); <|"bf" -> bf, "post" -> post|> ] (* 関数fの定義 *) f[alpha_] := pbetat[1/6, 0.5, {alpha, 5*alpha - 4}, {4, 50 - 4}]["post"] (* 最小化 *) result = NMinimize[{f[alpha], 0 <= alpha <= 20}, alpha] http://rio2016.5ch.net/test/read.cgi/math/1723152147/855
856: 132人目の素数さん [sage] 2025/05/30(金) 20:13:47.71 ID:zoAuXcvc p_post_null <- function(p0, prior, alpha, beta, success, failure){ # Calculate the total number of trials from successes and failures. total = success + failure # Calculate the likelihood of the data under the null hypothesis (H0). # This assumes a binomial distribution where the success probability is p0. m0 = dbinom(success, total, p0) # Calculate the marginal likelihood of the data under the alternative hypothesis (H1). # Under H1, the success probability is assumed to follow a Beta distribution # with parameters alpha and beta. This function (from the 'extraDistr' package) # computes the marginal likelihood by integrating over all possible success probabilities. m1 = extraDistr::dbbinom(success, total, alpha, beta) # Calculate the Bayes Factor (BF01). # This is the ratio of the likelihood under the null hypothesis (m0) # to the marginal likelihood under the alternative hypothesis (m1). BF01 = m0 / m1 # Calculate the posterior probability of the null hypothesis. # This updates the prior belief (prior) based on the evidence from the data (BF01). p_post = prior * BF01 / (prior * BF01 + 1 - prior) # Return both the Bayes Factor and the posterior probability as a named vector. c(BF01 = BF01, p_post = p_post) } # Optimize the 'alpha' parameter to maximize the posterior probability of the null hypothesis. # We're trying to find the 'alpha' value (within the range 0 to 1e6) that makes the # null hypothesis most plausible, given the data and the relationship beta = 5*alpha - 4. # p_post_null(...)[2] specifically extracts the 'p_post' value from the function's output. optimize(function(alpha) p_post_null(p0 = 1/6, prior = 1/2, alpha, 5 * alpha - 4, # Beta parameter is a function of alpha success = 4, failure = 50 - 4)[2], c(0, 1e6)) # Search range for alpha # Calculate the Bayes Factor and posterior probability using specific alpha and beta values. # These specific values (alpha = 50/9, beta = 5*50/9 - 4) are likely the result of the # optimization step above, or pre-determined values that are of interest. p_post_null(1/6, 1/2, 50/9, 5 * 50/9 - 4, 4, 50 - 4) http://rio2016.5ch.net/test/read.cgi/math/1723152147/856
メモ帳
(0/65535文字)
上
下
前次
1-
新
書
関
写
板
覧
索
設
栞
歴
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.028s