when I'm simulating clinical trial data to compare the performance of bootstrap CI with wald CI, I find my simulation takes hours. Here is the structure of my code
rep = bootstrap = 1000
effectsize = 0.6
estimate = numeric(bootstrap )
coverage = logic(rep)
for(i in 1:rep){
df = SimulateOneTrial(...) # this is a func that can yield one virtual clinical trial dataset
for (j in 1:bootstrap){
index = sample(1:nrow(df),nrow(df), TRUE)
estimate[j] = analysis(df[index,]) # some func that can perform the analysis and produce an estimate
}
bootstrap.CI = quantile(estimate,0.025,0.975)
coverage[i] = (bootstrap.CI[1]<=effectsize && bootstrap.CI[1]>=effectsize)
}
sum(coverage )/rep
I'm wondering if there is a way to speed it up? thx in advance!