摘要:我的模拟与我的功率计算不符。
(这个问题已经变得相当长,所以你可能没有读到底部。我认为这是一个样本量问题。)
我正在运行一些模拟来帮助设计一项研究,但我遇到了一些让我感到困惑的事情。
有两组,治疗组和未治疗组,结果是崩溃的。
我们估计未治疗组的崩溃率为 0.1,并且认为我们可以将其降低到 0.08。小样本(且不可行)为每组 100 个样本。
所以我跑去power.prop.test()估计功率。
power.prop.test(p1=0.1, p2=0.08, n=100)
power.prop.test(p1=0.1, p2=0.08, n=100)
Two-sample comparison of proportions power calculation
n = 100
p1 = 0.1
p2 = 0.08
sig.level = 0.05
power = 0.07122973
alternative = two.sided
NOTE: `n` is number in *each* group
然后我进行了模拟,因为我想探索我们在最佳治疗方面做出错误决定的频率。
library(Exact)
#Create a data frame called d, populate it with the numbers
#above.
set.seed(12345)
nTreated <- 100
nUntreated <- 100
probTreated <- 0.1
probUntreated <- 0.08
d <- data.frame(id = 1:10000)
d$nTreated <- nTreated
d$nUntreated <- nUntreated
d$probTreated <- probTreated
d$probUntreated <- probUntreated
#Generate some random results using rbinom()
d$treatedCrashes <- apply(cbind(d$nTreated, d$probTreated),
1, function(x) sum(rbinom(x[1], 1, x[2])))
d$untreatedCrashes <- apply(cbind(d$nUntreated,
d$probUntreated), 1, function(x) sum(rbinom(x[1], 1,
x[2])))
#Do fisher's exact test on each replication:
d$fisher <- apply(cbind(d$nTreated - d$treatedCrashes,
d$treatedCrashes,
d$nUntreated - d$untreatedCrashes,
d$untreatedCrashes), 1,
function(x) fisher.test(matrix(x,
nrow=2))$p.value)
#test power
mean(d$fisher < 0.05)
我得到了 4.8% 的功率,低于power.prop.test函数所说的,并且小于 0.05 - 这似乎有点错误。
mean(d$fisher < 0.05)
[1] 0.0478
这是关于小样本近似吗?这是一个愚蠢的编码错误吗?(我不认为是这样,但我以前经常犯错)。这是我没有想到的吗?
为了回应这是因为 Fisher 的精确检验以边际为条件的建议,我用 Barnard 的检验(在 Exact 库中)重新运行了模型。(但我减少到 1000 次复制,因为这需要 40 分钟)。
d$exact <- apply(cbind(d$nTreated - d$treatedCrashes,
d$treatedCrashes,
d$nUntreated - d$untreatedCrashes,
d$untreatedCrashes), 1,
function(x) exact.test(matrix(x, nrow=2),
to.plot=F, cond.row=T)$p.value)
d$exact <- lapply(d$exact, function(x) x[1][[1]])
mean(d$exact < 0.05)
mean(d$exact < 0.05)
[1] 0.049
我有几乎相同的力量。
但是,我还使用该power.exact.test()函数对功率进行了精确测试,也在 Exact 库中,它提供了非常相似的功率水平:
power.exact.test(p1=0.1, p2=0.08, n1=100,
n2=100,simulation=T, nsim=1000, method="Boschloo")
$power
[1] 0.045
$alternative
[1] "two.sided"
$method
[1] "Boschloo"
这让我认为这是一个样本量问题。