R: It is not clear how to load the eta value for repeated measurements. Anova

Purpose: Calculate 95% confidence intervals for eta values ​​from repeated ANOVA measurements.

The design is a two-factor design (factor 1 has 3 levels, factor 2 - 7 levels), which completely intersects with 30 subjects. However, I'm not sure if I am loading correctly to calculate confidence intervals for eta. I use the boot () function to load a sample on topics, but leave factors and levels only inside factors. Therefore, I’m not sure if I am doing it right or not - I need to do a more complex reboot / oversampling, where I recalculate the coefficient / levels or it is normal to do this only at the item level. 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
+5

All Articles