ANOVA for within-subjects in R
1srchscrl = read.csv("srchscrl.csv")
2View(srchscrl)
3srchscrl$Subject = factor(srchscrl$Subject) # convert to a nominal factor
4srchscrl$Technique = factor(srchscrl$Technique) # Rv4
5srchscrl$Order = factor(srchscrl$Order) # convert to a nominal factor
6summary(srchscrl)
7
8library(plyr)
9ddply(srchscrl, ~ Technique, function(data) summary(data$Time))
10ddply(srchscrl, ~ Technique, summarise, Time.mean=mean(Time), Time.sd=sd(Time))
11
12hist(srchscrl[srchscrl$Technique == "Search",]$Time) # histogram
13hist(srchscrl[srchscrl$Technique == "Scroll",]$Time) # histogram
14plot(Time ~ Technique, data=srchscrl) # boxplot
15
16shapiro.test(srchscrl[srchscrl$Technique == "Search",]$Time) # Shapiro-Wilk
17shapiro.test(srchscrl[srchscrl$Technique == "Scroll",]$Time)
18
19m = aov(Time ~ Technique + Error(Subject/Technique), data=srchscrl)
20shapiro.test(residuals(m$Subject))
21qqnorm(residuals(m$Subject)); qqline(residuals(m$Subject))
22shapiro.test(residuals(m$`Subject:Technique`))
23qqnorm(residuals(m$`Subject:Technique`)); qqline(residuals(m$`Subject:Technique`))
24
25library(car)
26leveneTest(Time ~ Technique, data=srchscrl, center=median) # Brown-Forsythe test
27
28library(reshape2)
29srchscrl.wide.order = dcast(srchscrl, Subject ~ Order, value.var="Time") # go wide
30View(srchscrl.wide.order) # verify
31t.test(srchscrl.wide.order$"1", srchscrl.wide.order$"2", paired=TRUE)
32
33srchscrl.wide.tech = dcast(srchscrl, Subject ~ Technique, value.var="Time") # go wide
34View(srchscrl.wide.tech)
35t.test(srchscrl.wide.tech$Search, srchscrl.wide.tech$Scroll, paired=TRUE)
36plot(Time ~ Technique, data=srchscrl) # confirm
References
#statistics #repeated_measures #within_subjects #designing_running_and_analyzing_experiments #week6 #assumptions #test #coursera #experiment #theory #design #anova #rlang