##################################### ##################################### ###### BRAVEST: power analysis ###### ##################################### ##################################### #For info or support contact: elvio.blini@inserm.fr ; blini.elvio@hotmail.it #This document reports GPower analyses outcomes for our design, with varying sample and effect sizes #Values refer to post-hoc power for repeated measures ANOVA (F tests family, within factors) #We tested a range of different Effect Sizes, Sample Sizes, and Correlations among repeated measures #Alpha level was set to 0.05 #Our design considers 1 group of subjects with 18 measurements (GVS by Reward by Validity, 3x3x2). #We assumed no correction due to violation of sphericity (1) #This (commented) cleans the current environment #Please assure that you saved everything before executing # rm(list = ls()) #Required packages: #Need to be installed once before e.g. via install.packages("psych") if necessary library(plyr) library(ggplot2) #This is the range of effect size, sample size, and correlations we tested ES= seq(0.15, 0.2, by= 0.01) SS= 24:30 r= seq(0.4, 0.6, by=0.1) #Summarise in a dataframe DF= expand.grid(SS= SS, ES= ES, r= r) DF$ES= as.factor(DF$ES); DF$SS= as.factor(DF$SS);DF$r= as.factor(DF$r) #Here we report the results we obtained, for each correlation value #Each row is a different effect size, each column a different sample size Power0.4= c(0.6728352, 0.6969220, 0.7198449, 0.7415847, 0.7621338, 0.7814953, 0.7996817, #ES= 0.15 0.7456390, 0.7686659, 0.7901597, 0.8101435, 0.8286535, 0.8457363, 0.8614470, #0.16 0.8098950, 0.8307081, 0.8497100, 0.8669818, 0.8826149, 0.8967075, 0.9093618, #0.17 0.8637666, 0.8815333, 0.8973544, 0.9113741, 0.9237393, 0.9345962, 0.9440877, #0.18 0.9066086, 0.9209182, 0.9333118, 0.9439882, 0.9531379, 0.9609404, 0.9675627, #0.19 0.9388859, 0.9497502, 0.9588762, 0.9664968, 0.9728246, 0.9780504, 0.9823440) #0.2 Power0.5= c(0.7745595, 0.7967569, 0.8172863, 0.8361945, 0.8535405, 0.8693929, 0.8838274, #ES= 0.15 0.8396551, 0.8589405, 0.8763239, 0.8919197, 0.9058494, 0.9182376, 0.9292097, #0.16 0.8917267, 0.9073614, 0.9210500, 0.9329724, 0.9433048, 0.9522165, 0.9598677, #0.17 0.9307902, 0.9426030, 0.9526146, 0.9610509, 0.9681207, 0.9740141, 0.9789021, #0.18 0.9582301, 0.9665389, 0.9733323, 0.9788515, 0.9833086, 0.9868871, 0.9897444, #0.19 0.9762535, 0.9816888, 0.9859611, 0.9892961, 0.9918824, 0.9938754, 0.9954021) #0.2 Power0.6= c(0.8809527, 0.8974606, 0.9120149, 0.9247817, 0.9359260, 0.9456088, 0.9539841, #0.15 0.9270466, 0.9392773, 0.9496825, 0.9584843, 0.9658893, 0.9720868, 0.9772476, #0.16 0.9583768, 0.9666644, 0.9734387, 0.9789411, 0.9833835, 0.9869493, 0.9897957, #0.17 0.9779620, 0.9830910, 0.9871017, 0.9902163, 0.9926189, 0.9944605, 0.9958635, #0.18 0.9892029, 0.9920984, 0.9942551, 0.9958493, 0.9970192, 0.9978718, 0.9984890, #0.19 0.9951174, 0.9966069, 0.9976590, 0.9983962, 0.9989085, 0.9992619, 0.9995040) #0.2 #Concatenate the values DF$Power= c(Power0.4, Power0.5, Power0.6) #Summarise values as to have a range given by different values of R, Power being the average r= 0.5 DF.summary= ddply(DF, c("SS", "ES"), summarise, min= min(Power), max= max(Power), Power= Power[r== 0.5]) #Plot: points and interpolation for r=0.5, bands given by different correlation values ggplot(DF.summary, aes(x= SS, y= Power, group= ES, color= ES, fill= ES)) + theme_bw() + labs(x= "Sample Size", y= "Power", color= "Effect Size") + theme(text= element_text(size=20, face="bold")) + geom_ribbon(aes(ymin= min, ymax= max), alpha= 0.2, show.legend= F, colour= NA) + geom_smooth(method= "loess", se= F, size= 1.8) + geom_point(shape=19, size=4) + scale_color_manual(values= rev(heat.colors(length(ES))), breaks=rev(as.character(ES))) + guides(fill= F) #Turned out to be too crowded, thus we snapped back to a simpler one ggplot(DF.summary, aes(x= SS, y= Power, group= ES, color= ES)) + theme_bw() + labs(x= "Sample Size", y= "Power", color= "Effect Size") + theme(text= element_text(size=20, face="bold")) + geom_smooth(method= "loess", se= F, size= 1.8) + geom_point(shape=19, size=4) + scale_color_manual(values= rev(heat.colors(length(ES))), breaks=rev(as.character(ES))) #An alternative approach exploiting the "pwr" package library(pwr) ################### ### user prompt ### ################### #Degrees of freedom for the Numerator #For interactions in a within factorial design: #(Lv1 -1) * (Lv2-1) * (Ln -1); where L is the number of levels of each variable DfN= (3-1) * (3-1) * (2-1) #3 by 3 by 2 design #Range for the effect sizes to test pwrES= seq(0.10, 0.2, by= 0.01) #Range for the sample sizes to test pwrSS= 24:30 #Alpha level alpha= 0.05 ################### ### end prompt ### ################### #Summarise dataframe pwrDF= expand.grid(SS= pwrSS, ES= pwrES) pwrDF$Power= pwr.f2.test(DfN, DfN*(pwrDF$SS-1), pwrDF$ES, alpha, NULL)$power pwrDF$ES= as.factor(pwrDF$ES); pwrDF$SS= as.factor(pwrDF$SS) #Plot ggplot(pwrDF, aes(x= SS, y= Power, group= ES, color= ES)) + theme_bw() + labs(x= "Sample Size", y= "Power", color= "Effect Size") + theme(text= element_text(size=20, face="bold")) + geom_smooth(method= "loess", se= F, size= 1.8) + geom_point(shape=19, size=4) + scale_color_manual(values= rev(heat.colors(length(pwrES))), breaks=rev(as.character(pwrES)))