Context: I'm trying to do a fairly complicated power calculation in advance of an experiment involving a blocked treatment assignment. I have data from a previous run of the experiment. I'm thinking:
- Sample from the prior data with replacement to generate SAMPLESIZE observations
- Blocked treatment assignment as in experimental protocol
- Generate predicted outcomes assuming a particular EFFECTSIZE
- Generate estimate, test-statistic, significance
Repeat steps 1-4 5000 times to estimate experimental power, with grid search over values of SAMPLESIZE and EFFECTSIZE, plot
I'm following the vignettes for doing this with paramtest
setting boot=TRUE
; their minimal example is:
t_func_boot <- function(data, indices) {
sample_data <- data[indices, ]
treatGroup <- sample_data[sample_data$group == 'trt2', 'weight']
ctrlGroup <- sample_data[sample_data$group == 'ctrl', 'weight']
t <- t.test(treatGroup, ctrlGroup, var.equal=TRUE)
stat <- t$statistic
p <- t$p.value
return(c(t=stat, p=p, sig=(p < .05)))
}
power_ttest_boot <- run_test(t_func_boot, n.iter=5000, output='data.frame', boot=TRUE,
bootParams=list(data=PlantGrowth))
results(power_ttest_boot) %>%
summarise(power=mean(sig))
However, I cannot figure out how to adapt this to resample so that each replication has a larger (or smaller) sample size than data being sampled from.