moa=c(6.8,4.1,7.3,14.2,18.8,9.9,7.4,11.9,5.2,7.8,7.8,8.7,12.7,14.5,10.7,8.4,9.7, 10.6,7.8,4.4,11.4,3.1,4.3,10.1,1.5,7.4,5.2,10.0,3.7,5.5,8.5,7.7,6.8,3.1, 6.4,10.8,1.1,2.9,4.5,5.8,9.4,6.8) group=c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3) group=factor(group) boxplot(moa~group,names=c("Schizo I","Schizo II","Schizo III")) f=aov(moa~group) summary(f) # Rejecting H0: mu1=mu2=mu3 is only half the story! # Usually want to know WHICH means are different... # Tukey's method finds which pairs of means are different # bounding the "family error rate" at 5% # Find pairs of means with adjusted p-values smaller than 0.05 TukeyHSD(f) # 3 is different from 1, 2 is different from 1 # 3 not different from 2 # gives "lines" plot: # III II I # ------ - ############################################# # ANOVA on hours of homework and hours of # exercise by political ideology and president ############################################# pr=factor(c("t","t","c","c","c","c","c","c","c","c","c","o","c","o","c","c","o","t")) po=factor(c("m","c","l","l","m","l","l","l","l","l","l","c","l","c","l","l","m","c")) hw=c(22,15,7,10,10,15,14,10,20,20,5,14,20,10,5,10,15,10) ex=c(5,15,4,4,10,5,0,6,5,7,1,6,90,3,3,5,0,14) ex[13]=floor(median(ex)) # replace '90' with imputed value # homework by president boxplot(hw~pr) summary(aov(hw~pr)) # homework by political ideology boxplot(hw~po) summary(aov(hw~po)) # exercise by president boxplot(ex~pr) summary(aov(ex~pr)) TukeyHSD(aov(ex~pr)) # lines: # other clinton trump # ------------- ----- ############################################# # Constant variance? ############################################# qqnorm(ex[pr=="o"]) qqnorm(ex[pr=="c"]) qqnorm(ex[pr=="t"]) # formal hypothesis test of H0: sigma1=sigma2=sigma3 bartlett.test(ex~pr) ############################################# # NOTE: if variances *are* different, can use ############################################# oneway.test(ex~pr) # oneway.test allows variances to be different across groups # but also assumes normality. If you don't have normal data kruskal.test(ex~pr) # The Kruskall-Wallace does not assume *anything* and is always valid # exercise by political ideology boxplot(ex~po) summary(aov(ex~po)) TukeyHSD(aov(ex~po)) # lines: # liberal moderate conservative # ---------------- ------------