###################INTRODUCTION############################# #Based on the calculated TEm (Table 1) we simulate mitochondrial respiration values we could obtain in a study with n participants #Each participant is measured PRE and POST for mito respiration, with two chambers for each timepoint. #We will see how large an effect size we can detect with 80% power #Note that we do NOT simulate trainability (i.e. all individuals increased their TRUE mito resp by the same amount after training). #################CREATE THE FUNCTION TO CALCULATE DETECTABLE EFFECT SIZE##### detectable_ES=function(pow=80,mean,sd,TEm){ #function returning detectable effect sizes for a range of sample sizes at a given power (default=80%). Input values are the mean and SD of mitochondrial respiration, and TEm the within-subject standard deviation. ns=seq(5,100)#simulate sample sizes from 5 to 100 individuals ES=seq(1,1.5,by=0.01) #create a range of effect sizes from 1% to 50% (i.e. we will simulate interventions that increase mito resp by 1%, 2%, 3%, etc.) detectable_ES=c() #empty object where we will store values further on for (n in ns) #create a loop in which simmulation will be runned for all participants { power=c() #empty object where we will store values from loop based on effect sizes for (e in ES) { pvals=c() #empty object where we will store p-values for a 1000 simulations for (i in 1:1000) { ###############simulate individual TRUE values############################## PRE_TRUE=rnorm(n=n,mean=mean,sd=sd) #simulate n true PRE values with a mean of 128 and SD of 45 (Table 1) POST_TRUE=PRE_TRUE*e #simulate n POST values by multiplying the PRE values by the effect size e. For simplicity, we do NOT simulate trainability here (i.e. the true increase from PRE to POST after training is the same for all individuals (it is multiplied by e). ###############simulate individual OBSERVED values############################## PRE_OBS=c() POST_OBS=c() for (p in PRE_TRUE) PRE_OBS=c(PRE_OBS,mean(rnorm(n=2,mean=p,sd=TEm))) #we simulate 2 duplicate measurements with a mean equal to the TRUE value, and with an SD equal to the TE we calculated in the Gene SMART samples (Table 1) for (p in POST_TRUE) POST_OBS=c(POST_OBS,mean(rnorm(n=2,mean=p,sd=TEm))) #we simulate 2 duplicate measurements with a mean equal to the TRUE value, and with an SD equal to the TE we calculated in the Gene SMART samples (Table 1) #Now we have a list of observed PRE and POST values for each individual ################Paired t-test############################## #We will now perform a paired t-test to see whether we can detect the effect size test=t.test(PRE_OBS,POST_OBS,paired=TRUE) pvals=c(pvals,test$p.value) } power=c(power,length(which(pvals<0.05))/10) #power is divided by 10 to convert the simulations into % since we runned the loop 000 times } detectable_ES=c(detectable_ES,ES[min(which(power>pow))]) #identify effect sizes that are detected at least 80% of the time (i.e. 80% power) } detectable_ES=100*(detectable_ES-1) return(detectable_ES) } ###################CI+CIIp######################## mean=128 sd=45 TEm=23.1 detectable_ES=detectable_ES(mean=mean,sd=sd,TEm=TEm) ###################CI+CIIe######################## mean=160 sd=55 TEm=27 detectable_ES=detectable_ES(mean=mean,sd=sd,TEm=TEm) #################CREATE THE FUNCTION TO CALCULATE POWER FOR A GIVEN SAMPLE SIZE##### power=function(n=20,mean,sd,TEm){#simulate sample size of n individuals (default=20) ES=seq(1,1.5,by=0.01) #create a range of effect sizes from 1% to 50% (i.e. we will simulate interventions that increase mito resp by 1%, 2%, 3%, etc.) power=c() for (e in ES) { pvals=c() for (i in 1:1000) { PRE_TRUE=rnorm(n=n,mean=mean,sd=sd) #simulate n true PRE values POST_TRUE=PRE_TRUE*e #simulate n POST values by multiplying the PRE values by the effect size e. For simplicity, we do NOT simulate trainability here (i.e. the true increase from PRE to POST after training is the same for everyone (it is multiplied by e) #simulate now measuring each individual's PRE and POST value with the error of measurement we know PRE_OBS=c() POST_OBS=c() for (p in PRE_TRUE) PRE_OBS=c(PRE_OBS,mean(rnorm(n=2,mean=p,sd=TEm))) #we simulate 2 duplicate measurements with a mean equal to the TRUE value, and with an SD equal to the TE we calculated in the Gene SMART samples for (p in POST_TRUE) POST_OBS=c(POST_OBS,mean(rnorm(n=2,mean=p,sd=TEm))) #we simulate 2 duplicate measurements with a mean equal to the TRUE value, and with an SD equal to the TE we calculated in the Gene SMART samples #Now we have a list of observed PRE and POST values for each individual #We will now perform a paired t-test to see whether we can detect the effect size test=t.test(PRE_OBS,POST_OBS,paired=TRUE) pvals=c(pvals,test$p.value) } power=c(power,length(which(pvals<0.05))/10) } return(power) }