Analyzing a factorial ANOVA
Always remember to first test for significance of the presentation order for your within-subjects factors.
If it is significant, it means you need to revisit your counterbalancing method.
Only if it is not significant you may proceed to test for the actual factor.
Always remember to test for sphericity when using within-subjects factors.
If the Mauchly test for sphericity is significant, that means your factor violates the sphericity assumption, and you need to apply the Greenhouse-Geyser correction
Note: “ges” in m$ANOVA
is the generalized eta-squared measure of effect size, preferred to eta-squared or partial eta-squared.
1
2mbltxt = read.csv("mbltxt.csv")
3View(mbltxt)
4mbltxt$Subject = factor(mbltxt$Subject) # convert to nominal factor
5mbltxt$Keyboard = factor(mbltxt$Keyboard) # Rv4
6mbltxt$Posture = factor(mbltxt$Posture) # Rv4
7mbltxt$Posture_Order = factor(mbltxt$Posture_Order) # convert to nominal factor
8summary(mbltxt)
9
10library(plyr)
11ddply(mbltxt, ~ Keyboard * Posture, function(data) summary(data$WPM))
12ddply(mbltxt, ~ Keyboard * Posture, summarise, WPM.mean=mean(WPM), WPM.sd=sd(WPM))
13
14hist(mbltxt[mbltxt$Keyboard == "iPhone" & mbltxt$Posture == "Sit",]$WPM)
15hist(mbltxt[mbltxt$Keyboard == "iPhone" & mbltxt$Posture == "Stand",]$WPM)
16hist(mbltxt[mbltxt$Keyboard == "iPhone" & mbltxt$Posture == "Walk",]$WPM)
17hist(mbltxt[mbltxt$Keyboard == "Galaxy" & mbltxt$Posture == "Sit",]$WPM)
18hist(mbltxt[mbltxt$Keyboard == "Galaxy" & mbltxt$Posture == "Stand",]$WPM)
19hist(mbltxt[mbltxt$Keyboard == "Galaxy" & mbltxt$Posture == "Walk",]$WPM)
20boxplot(WPM ~ Keyboard * Posture, data=mbltxt, xlab="Keyboard.Posture", ylab="WPM") # boxplots
21with(mbltxt, interaction.plot(Posture, Keyboard, WPM, ylim=c(0, max(mbltxt$WPM)))) # interaction plot
22
23library(ez)
24m = ezANOVA(dv=WPM, between=Keyboard, within=Posture_Order, wid=Subject, type=3, data=mbltxt)
25m$Mauchly # n.s.
26m$ANOVA
27
28m = ezANOVA(dv=WPM, between=Keyboard, within=Posture, wid=Subject, type=3, data=mbltxt)
29m$Mauchly # sig. so use GGe correction
30m$ANOVA
31pos = match(m$`Sphericity Corrections`$Effect, m$ANOVA$Effect) # positions of within-Ss efx in m$ANOVA
32m$Sphericity$GGe.DFn = m$Sphericity$GGe * m$ANOVA$DFn[pos] # Greenhouse-Geisser
33m$Sphericity$GGe.DFd = m$Sphericity$GGe * m$ANOVA$DFd[pos]
34m$Sphericity$HFe.DFn = m$Sphericity$HFe * m$ANOVA$DFn[pos] # Huynh-Feldt
35m$Sphericity$HFe.DFd = m$Sphericity$HFe * m$ANOVA$DFd[pos]
36m$Sphericity # show results
37
38m = aov(WPM ~ Keyboard * Posture + Error(Subject/Posture), data=mbltxt) # fit model
39summary(m) # show table
40
41library(reshape2)
42mbltxt.wide = dcast(mbltxt, Subject + Keyboard ~ Posture, value.var="WPM") # go wide
43View(mbltxt.wide)
44sit = t.test(mbltxt.wide$Sit ~ Keyboard, data=mbltxt.wide) # iPhone vs. Galaxy WPM sitting
45std = t.test(mbltxt.wide$Stand ~ Keyboard, data=mbltxt.wide) # iPhone vs. Galaxy WPM standing
46wlk = t.test(mbltxt.wide$Walk ~ Keyboard, data=mbltxt.wide) # iPhone vs. Galaxy WPM walking
47p.adjust(c(sit$p.value, std$p.value, wlk$p.value), method="holm")
48
49t.test(mbltxt.wide[mbltxt.wide$Keyboard == "iPhone",]$Sit, mbltxt.wide[mbltxt.wide$Keyboard == "iPhone",]$Walk, paired=TRUE)
50boxplot(mbltxt.wide[mbltxt.wide$Keyboard == "iPhone",]$Sit, mbltxt.wide[mbltxt.wide$Keyboard == "iPhone",]$Walk,xlab="iPhone.Sit vs. iPhone.Walk", ylab="WPM") # custom boxplot
References
#interactions #rlang #statistics #designing_running_and_analyzing_experiments #anova #week7 #counterbalancing #experiment #theory #sphericity #coursera #design #test #greenhouse_geyser #eta_squared