# Exercise 8.2 # 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 M. Wilkinson, Rothamsted Research # Version 1, 26/06/2015 # Set working directory - use setwd() function or from Session menu in RStudio # e.g. setwd("d:/stats4biol/data) # load external packages - availabel from CRAN library(ggplot2) library(lsmeans) # tables of predicted means & contrasts # Read data & assign factors callus <- read.table('callus.dat', sep="", header=TRUE) callus$Tray <- as.factor(callus$Tray) callus$Container <- as.factor(callus$Container) callus$Conc <- as.factor(callus$Conc) summary(callus) # Plot data qplot(data=callus, y=Weight, x=Age, colour=Conc, facets=Type~.) # Multi-stratum ANOVA callus.msaov <- aov(Weight ~ Age*Conc*Type + Error(Tray/Container), data=callus) summary(callus.msaov) # Equivalent ANOVA to get residuals callus.aov <- aov(Weight ~ Tray + Age*Conc*Type, data=callus) summary(callus.aov) # Residual plots plot(callus.aov, ask=FALSE) hist(residuals(callus.aov)) # Get table of predicted means with CI for main effects lsmeans(callus.aov, ~Age) lsmeans(callus.aov, ~Conc) lsmeans(callus.aov, ~Type) # End of file