注意:这个问题已作为this GitHub问题交叉发布。
我正在根据以前的实验(包括40名参与者)的数据估算样本量。
我使用simr::powerCurve
处理了几个小于原始样本的样本:
pc <- powerCurve(fit = model, nsim = 100, alpha=0.02,
breaks = c(10, 20, 30, 40), along = 'subject_id')
所有尺寸的结果均相同,接近100%。我认为这是由于模拟的样本量小于原始样本量。
是否有一种方法可以估计比用于拟合模型的样本量小的样本的功效?
以下是使用合成数据(从https://humburg.github.io/Power-Analysis/simr_power_analysis.html提取并稍作修改的代码)的可复制示例:
library(simr)
subj <- factor(1:40)
class_id <- letters[1:5]
time <- 0:2
group <- c("control", "intervention")
subj_full <- rep(subj, 15)
class_full <- rep(rep(class_id, each=10), 3)
time_full <- rep(time, each=50)
group_full <- rep(rep(group, each=5), 15)
covars <- data.frame(id=subj_full, class=class_full, treat=group_full, time=factor(time_full))
## Intercept and slopes for intervention, time1, time2, intervention:time1, intervention:time2
fixed <- c(5, 2, 0.1, 0.2)
## Random intercepts for participants clustered by class
rand <- list(0.5, 0.1)
## residual variance
res <- 2
model <- makeLmer(y ~ treat + time + (1|class/id), fixef=fixed, VarCorr=rand, sigma=res, data=covars)
pc <- powerCurve(model, test = fixed('treat'), nsim=100, along='subj', breaks = c(10, 20, 30, 40))
print(pc)
输出为
Power for predictor 'treat', (95% confidence interval),
by number of levels in subj:
10: 100.0% (96.38, 100.0) - 150 rows
20: 100.0% (96.38, 100.0) - 300 rows
30: 100.0% (96.38, 100.0) - 450 rows
40: 100.0% (96.38, 100.0) - 600 rows
Time elapsed: 0 h 0 m 55 s