# R para principiantes # PUCE, Quito, 5-8 enero 2010 # Simon Queenborough # JUEVES: clase 14 ############ ANOVA ################## # Recall, the t-test was used to test hypotheses about the means of two independent samples. For example, to test # if there is a diFFerence between control and treatment groups. The method called analysis of variance (ANOVA) # allows one to compare means for more than 2 independent samples. x = c(4,3,4,5,2,3,4,5) y = c(4,4,5,5,4,5,4,4) z = c(3,4,2,4,5,5,4,4) scores = data.frame(x,y,z) boxplot(scores) # Analysis of variance allows us to investigate if all the graders have the same mean. The R function to do the # analysis of variance hypothesis test (oneway.test) requires the data to be in a different format. It wants to have the # data with a single variable holding the scores, and a factor describing the grader or category. The stack command # will do this for us: scores = stack(scores) # look at scores if not clear names(scores) head(scores) m <- aov(values ~ ind, data=scores) summary(m) # kruskal-wallis test # non-parametric kruskal.test(values ~ ind, data=scores) ######## two-way anova ############# gr <- read.table("growth.txt", header=T) barplot(tapply(gr$gain,list(gr$diet,gr$supplement),mean), beside=T,ylim=c(0,30),col=rainbow(3)) tapply(gain,list(diet,supplement),mean) model<-aov(gain~diet*supplement, data=gr) summary(model) model2 <-aov(gain~diet+supplement, data=gr) summary.lm(model2) anova(model, model2) ######################################################################################## # # EJERCICIOS # ######################################################################################## # 14.1 # The dataset InsectSpray has data on the count of insects in areas treated with one of 6 di erent types of # sprays. The dataset is already in the proper format for the oneway analysis of variance { a vector with the # data (count), and one with a factor describing the level (spray). First make a side-by-side boxplot to see if # the means are equal. Then perform a oneway ANOVA to check if they are. Do they agree?