# Example 7.3 # 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 # Version 1, 13/08/2014 # Set working directory - use setwd() function or from Session menu in RStudio # e.g. setwd("d:/stats4biol/data) ### Plot-level measurements # Read data from file in working directory oedoplot <- read.table("oedoplot.dat", sep="", header=TRUE) # assign factors oedoplot$Block <- as.factor(oedoplot$Block) oedoplot$Plot <- as.factor(oedoplot$Plot) summary(oedoplot) # Multi-stratum ANOVA (one-way ANOVA with blocks and psuedo-replication) oedoplot.msaov <- aov(PlotCount ~ Treatment + Error(Block/Plot), data=oedoplot) summary(oedoplot.msaov) # Equivalent single-stratum ANOVA to get residuals oedoplot.aov <- aov(PlotCount ~ Block + Treatment, data=oedoplot) summary(oedoplot.aov) # Residual plots plot(oedoplot.aov, ask=FALSE) hist(residuals(oedoplot.aov)) # Treatment means model.tables(oedoplot.aov, type="means", se=TRUE) ### Trap-level counts # Read data from file in working directory oedotrap <- read.table("oedotrap.dat", sep="", header=TRUE) # assign factors oedotrap$Block <- as.factor(oedotrap$Block) oedotrap$Plot <- as.factor(oedotrap$Plot) oedotrap$Trap <- as.factor(oedotrap$Trap) summary(oedotrap) # Multi-stratum ANOVA (one-way ANOVA with blocks and psuedo-replication) oedotrap.msaov <- aov(TrapCount ~ Treatment + Error(Block/Plot/Trap), data=oedotrap) summary(oedotrap.msaov) # Equivalent single-stratum ANOVA to get residuals oedotrap.aov <- aov(TrapCount ~ Block + Treatment + Block:Plot, data=oedotrap) summary(oedotrap.aov) # Residual plots plot(oedotrap.aov, ask=FALSE) hist(residuals(oedotrap.aov)) # End of file