高校数学の質問スレ(医者・東大卒専用) Part438 (883レス)
高校数学の質問スレ(医者・東大卒専用) Part438 http://rio2016.5ch.net/test/read.cgi/math/1723152147/
上
下
前次
1-
新
通常表示
512バイト分割
レス栞
抽出解除
必死チェッカー(本家)
(べ)
自ID
レス栞
あぼーん
822: 132人目の素数さん [sage] 2025/05/02(金) 10:48:45.43 ID:+8QO9mMm set.seed(123) library(fmsb) alpha <- 0.05 N <- 1000 sim <- function() { # 群ごとのサンプルサイズ(不均等で可) n1 <- sample(250:350, 1) # 低用量 n2 <- sample(250:350, 1) # 高用量 n3 <- N - n1 - n2 # プラセボ # 各群の成功率設定(ペアでは差なし、プラセボ vs 合算で差あり) p1 <- 0.30 # 低用量 p2 <- 0.31 # 高用量 p3 <- 0.22 # プラセボ(低め) x1 <- rbinom(1, n1, p1) x2 <- rbinom(1, n2, p2) x3 <- rbinom(1, n3, p3) m <- rbind(success = c(x1, x2, x3), failure = c(n1 - x1, n2 - x2, n3 - x3)) bonf_p <- suppressWarnings(min(as.vector(pairwise.fisher.test(m[1,], colSums(m), p.adj="bonf")$p.value), na.rm=TRUE)) combined <- matrix(c(x1 + x2, n1 + n2 - x1 - x2, x3, n3 - x3), nrow=2) comb_p <- fisher.test(combined)$p.value list(m = m, bonf = bonf_p, combined_p = comb_p, sizes = c(n1, n2, n3)) } # 条件を満たすデータが出るまでループ res <- sim() while (!(res$bonf > alpha && res$combined_p < alpha)) { res <- sim() } # 結果出力 res$m cat("Bonferroni-adjusted pairwise p-value (min):", res$bonf, "\n") cat("Combined treatment vs placebo p-value:", res$combined_p, "\n") cat("Sample sizes:", res$sizes, "\n") http://rio2016.5ch.net/test/read.cgi/math/1723152147/822
823: 132人目の素数さん [sage] 2025/05/02(金) 11:02:18.75 ID:+8QO9mMm set.seed(123) library(fmsb) alpha <- 0.05 N <- 1000 # Simulation function sim <- function() { # Random group sizes n1 <- sample(250:350, 1) # Low-dose n2 <- sample(250:350, 1) # High-dose n3 <- N - n1 - n2 # Placebo if (n3 < 100) return(NULL) # Skip too-small placebo # Success rates from uniform distribution p1 <- runif(1) p2 <- runif(1) p3 <- runif(1) # Binomial draws x1 <- rbinom(1, n1, p1) x2 <- rbinom(1, n2, p2) x3 <- rbinom(1, n3, p3) # 3-group matrix m3 <- rbind(success = c(x1, x2, x3), failure = c(n1 - x1, n2 - x2, n3 - x3)) colnames(m3) <- c("Low", "High", "Placebo") # Add 4th group = combined (low + high) x4 <- x1 + x2 n4 <- n1 + n2 m4 <- cbind(m3, Combined = c(x4, n4 - x4)) # Perform pairwise Fisher's exact tests across 4 groups pw <- suppressWarnings(pairwise.fisher.test(m4[1,], colSums(m4), p.adj="bonf")$p.value) pw_vals <- as.vector(pw) pw_vals <- pw_vals[!is.na(pw_vals)] names_all <- names(pw_vals) # Identify significant pairs sig_idx <- which(pw_vals < alpha) sig_names <- names(pw_vals)[sig_idx] # Check if only Combined vs Placebo is significant is_valid <- length(sig_idx) == 1 && any(grepl("Placebo-Combined|Combined-Placebo", sig_names)) if (is_valid) { return(list(m = m4, probs = c(p1, p2, p3), sizes = c(n1, n2, n3), pvals = pw)) } else { return(NULL) } } # Run until condition met res <- NULL while (is.null(res)) { res <- sim() } # Output results print(res$m) cat("Success probabilities (Low, High, Placebo):", round(res$probs, 3), "\n") cat("Sample sizes (Low, High, Placebo):", res$sizes, "\n") cat("Pairwise Bonferroni-adjusted p-values:\n") print(res$pvals) http://rio2016.5ch.net/test/read.cgi/math/1723152147/823
メモ帳
(0/65535文字)
上
下
前次
1-
新
書
関
写
板
覧
索
設
栞
歴
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
Google検索
Wikipedia
ぬこの手
ぬこTOP
1.711s*