5

The goal: calculate 95% confidence intervals for eta values from a repeated measures ANOVA.

The design is a two factor design (Factor 1 has 3 levels, Factor 2 has 7 levels) that is fully crossed with 30 subjects. However, I am unsure I am doing the bootstrapping correctly to calculate confidence intervals for eta. I use the boot() function to bootstrap sample by subjects, but leave the factors and the levels within the factors alone. So I'm not sure if I am doing this correctly or not - do I need to do a more complicated bootstrapping/resampling where I resample by factor/levels or is it okay to just do at the level of subjects. My code seems to give reasonable results...

library(ez)
library(boot)
library(reshape2)

###create a data.frame for a 2-factor (Factor1-3 levels, Factor2-7 levels) fully crossed design with 30 subjects & fill fake data values
subject.number<-factor(rep(1:30,each=21))
factor1.levels<-rep(rep(c("level1","level2","level3"),each=7),30)
factor2.levels<-rep(rep(c("level1","level2","level3","level4","level5","level6","level7"),3),30)
set.seed(1234)
fake.data<-rnorm(630,mean=3)
dframe<-data.frame(subject.number,factor1.levels,factor2.levels,fake.data)
names(dframe)<-c("Subject","Factor1","Factor2","OutcomeValue")


###to work with boot() convert from long to wide format
dframe.wide<-dcast(dframe,Subject~Factor1+Factor2,value.var="OutcomeValue")


###function to use with boot() to calculate generalized eta value for Factor1, Factor2, and Factor1xFactor2 interaction in a repeated measures ANOVA

generalized_eta<-function(data,indices){
  d.wide<-data[indices,] #use boot() indices to sample data

  #now that have used indices from boot(), convert data back to long with correct Factor labeling
  dframe.long<-melt(d.wide,value.name="OutcomeValue",id="Subject")
  dframe.long<-cbind(dframe.long,colsplit(dframe.long$variable,"_",c("Factor1","Factor2")))
  dframe.long$Factor1<-factor(dframe.long$Factor1)
  dframe.long$Factor2<-factor(dframe.long$Factor2)
  dframe.long$Subject<-factor(dframe.long$Subject)

  #do repeated measures ANOVA with ezANOVA() which calculates generalized eta
  aov.ez = ezANOVA(data = dframe.long, dv = .(OutcomeValue), wid = .(Subject), within = .(Factor1,Factor2), type = 1)
  #return the three generalized eta values - Factor1, Factor2, Factor1xFactor2
  return(aov.ez[[1]]$ges)
}


###call boot() to do the bootstrap - only 200 to make it fast
results<-boot(data=dframe.wide,statistic=generalized_eta,R=200)


###plot the bootstrap results
plot(results,index=1) #for Factor1
plot(results,index=2) #for Factor2
plot(results,index=3) #for Factor1xFactor2

###create 95%-CI from bootstrap results
boot.ci(results,type="bca",index=1) #for Factor1
boot.ci(results,type="bca",index=2) #for Factor2
boot.ci(results,type="bca",index=3) #for Factor3
  • Did you manage to confirm if this is the correct way of applying bootstrap? Bootstrapping seems to be a complete different paradigm of the other tests, and I am failing to translate from one to the other – toto_tico Oct 27 '15 at 04:20

0 Answers0