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)
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")
dframe.wide<-dcast(dframe,Subject~Factor1+Factor2,value.var="OutcomeValue")
generalized_eta<-function(data,indices){
d.wide<-data[indices,]
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)
aov.ez = ezANOVA(data = dframe.long, dv = .(OutcomeValue), wid = .(Subject), within = .(Factor1,Factor2), type = 1)
return(aov.ez[[1]]$ges)
}
results<-boot(data=dframe.wide,statistic=generalized_eta,R=200)
plot(results,index=1)
plot(results,index=2)
plot(results,index=3)
boot.ci(results,type="bca",index=1)
boot.ci(results,type="bca",index=2)
boot.ci(results,type="bca",index=3)