# ONE FACTOR REPEATED MEASURES ANOVA
####
hinton.keyboard.altformat = data.frame(errors=c(5,1,0,2,6,2,4,4,10,3,5,6),kb=c("one","one","one","one","two","two",
"two","two","three","three","three","three"),part=c("a","b","c","d","a","b","c","d",
"a","b","c","d"))
bwplot(errors ~ as.factor(kb),data=hinton.keyboard.altformat)
bwplot(errors ~ as.factor(kb)|part,data=hinton.keyboard.altformat)
#Again we'll use a slightly different format to work through this
hinton.keyboard = data.frame(
kb1=c(5,1,0,2),kb2=c(6,2,4,4),kb3=c(10,3,5,6)
)
numberofdatapoints = 12
numberofconditions = 3
numberofparticipants = 4
df_total = numberofdatapoints - 1
df_between = numberofconditions - 1
df_err = (numberofparticipants-1)*(numberofconditions-1)
SS_total = sum((hinton.keyboard - (sum(hinton.keyboard)/numberofdatapoints))^2)
SS_between_conditions = sum((mean(hinton.keyboard) - (sum(hinton.keyboard)/numberofdatapoints))^2*numberofparticipants)
SS_within_conditions = SS_total - SS_between_conditions
SS_between_subjs = sum((rowMeans(hinton.keyboard) - mean(mean(hinton.keyboard)))^2)*numberofconditions
SS_error = SS_within_conditions - SS_between_subjs
MS_between_conditions= SS_between_conditions/df_between
MS_error = SS_error/df_err
F = MS_between_conditions/MS_error
1 - pf(F,df_between,df_err)
# We can do this without all of the steps...
kb.aov = aov(errors ~ kb + Error(part/kb),data=hinton.keyboard.altformat)
#And to relate this back to regression again....The following command gives us the
# same thing!
anova(lm(errors ~ part,data=hinton.keyboard.altformat),lm(errors ~ part + kb,data=hinton.keyboard.altformat))
#And again we need additional tests to locate the differences..
pairwise.t.test(hinton.keyboard.altformat$errors,hinton.keyboard.altformat$kb,paired=T,
p.adj="bonferroni")