# Exercise 8.6 # Statistical Methods in Biology: Design and Analysis of Experiments and Regression # by S.J. Welham, S.A. Gezan, S.J. Clark & A. Mead (2014) # Chapman & Hall/CRC Press, Boca Raton, Florida. ISBN: 978-1-4398-0878-8 # Data from R. Curtis, Rothamsted Research/Bionemax # Version 1, 30/06/2015 # Set working directory - use setwd() function or from Session menu in RStudio # e.g. setwd("d:/stats4biol/data) # load external packages - available from CRAN library(ggplot2) library(lsmeans) # tables of predicted means & contrasts # Read data & assign factors nematode <- read.table('nematodes.dat', sep="", header=TRUE) summary(nematode) # Plot data qplot(data=nematode, y=Distance, x=Treatment) # ANOVA nematode.aov <- aov(Distance ~ Treatment, data=nematode) summary(nematode.aov) # Residual plots plot(nematode.aov, ask=FALSE) hist(residuals(nematode.aov)) # Treatment means and contrasts nematode.lsm <- lsmeans(nematode.aov, ~Treatment) # Treatment means nematode.lsm # Contrasts contrast(nematode.lsm, method=list(c1=c(0.5,0.5,-1), c2=c(1,-1,0))) # To partition treatment SS in ANOVA table, need to define new factor to partion # lectins vs control treatment nematode$Control <- rep(1,length(nematode$Treatment)) nematode$Control[nematode$Treatment=='PBS'] <- 2 nematode$Control <- as.factor(nematode$Control) # ANOVA with partitioned treatment factor nematode2.aov <- aov(Distance ~ Control/Treatment, data=nematode) summary(nematode2.aov) # End of file