# Exercise 9.4 # 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 L. Smart, Rothamsted Research # Version 1, 11/07/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 pollenbeetles <- read.table('pollenbeetles.dat', sep="", header=TRUE) pollenbeetles$Row <- as.factor(pollenbeetles$Row) pollenbeetles$Column <- as.factor(pollenbeetles$Column) pollenbeetles$Treatment <- as.factor(pollenbeetles$Treatment) summary(pollenbeetles) # Plot data qplot(data=pollenbeetles, y=Count, x=Treatment) # Multi-stratum ANOVA pollenbeetles.msaov <- aov(Count ~ Treatment + Error(Row*Column), data=pollenbeetles) summary(pollenbeetles.msaov) # Equivalent ANOVA to get residuals pollenbeetles.aov <- aov(Count ~ Row + Column + Treatment, data=pollenbeetles) summary(pollenbeetles.aov) # Residual plots plot(pollenbeetles.aov, ask=FALSE) hist(residuals(pollenbeetles.aov)) # Get table of predicted means with CI for main effects pb.lsm <- lsmeans(pollenbeetles.aov, ~Treatment) pb.lsm # contrasts of two treatments with control (untreated) contrast(pb.lsm, method="trt.vs.ctrl", ref=c(3)) # End of file