# Exercise 9.8 # 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 Cochran, W.G. & Cox, G.M. (1957) Experimental designs (2nd Edition). # J. Wiley & Sons, New York. (Table 11.2) # Version 1, 01/08/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 corn <- read.table('corn.dat', sep="", header=TRUE) corn$Block <- as.factor(corn$Block) corn$Plot <- as.factor(corn$Plot) corn$Variety <- as.factor(corn$Variety) summary(corn) # Plot data qplot(data=corn, y=Yield, x=Variety, colour=Block) # Multi-stratum ANOVA corn.msaov <- aov(Yield ~ Variety+Error(Block/Plot), data=corn) summary(corn.msaov) # Intra-block analysis to get residuals corn.aov <- aov(Yield ~ Block + Variety, data=corn) summary(corn.aov) # Residual plots plot(corn.aov, ask=FALSE) hist(residuals(corn.aov)) # Get table of predicted means from intra-block analysis corn.lsm <- lsmeans(corn.aov, ~Variety) corn.lsm # contrasts of two treatments with control (untreated) contrast(corn.lsm, method="pairwise") # Need to use mixed models to get variety estimates combined across strata # End of file