# Exercise 9.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 E. Wright, 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) # Read data & assign factors size <- read.table('size.dat', sep="", header=TRUE) size$Incubator <- as.factor(size$Incubator) size$Occasion <- as.factor(size$Occasion) size$Dish <- as.factor(size$Dish) size$Temperature <- as.factor(size$Temperature) summary(size) # Plot data qplot(data=size, y=Size, x=Temperature) # Multi-stratum ANOVA size.msaov <- aov(Size ~ Temperature + Error((Incubator*Occasion)/Dish), data=size) summary(size.msaov) # ANOVA with same terms to get residuals (note: variance ratios wrong - compared to wrong residual) size.aov <- aov(Size ~ Incubator + Occasion + Temperature + Incubator:Occasion, data=size) summary(size.aov) # Residual plots plot(size.aov, ask=FALSE) hist(residuals(size.aov)) # get log-transformation size$log10Size <- log10(size$Size) # Multi-stratum ANOVA size2.msaov <- aov(log10Size ~ Temperature + Error((Incubator*Occasion)/Dish), data=size) summary(size2.msaov) # ANOVA with same terms to get residuals (note: variance ratios wrong - compared to wrong residual) size2.aov <- aov(log10Size ~ Incubator + Occasion + Temperature + Incubator:Occasion, data=size) summary(size2.aov) # Residual plots plot(size.aov, ask=FALSE) hist(residuals(size.aov)) # means for temperature treatments size.means <- model.tables(size2.aov, type="means", SE=TRUE) size.means$tables$"Temperature" size.means$se$"Temperature" # SEs not available # not possible to get correct SEs from ANOVA here? could use mixed models instead? # End of file