# # Exercise 11.6 # # 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 Pearce (1965, Section 6.2) # Version 1, 1/08/2015 # Set working directory - use setwd() function or from Session menu in RStudio # e.g. setwd("d:/stats4biol/data) # Set up packages to be used later - available from CRAN library(lsmeans) # for calculating predicted means library(ggplot2) # for plotting # Read data & assign factors shoot <- read.table("shoot.dat",sep="",header=T) shoot$Tree <- as.factor(shoot$Tree) shoot$DBranch <- as.factor(shoot$DBranch) shoot$Treatment <- as.factor(shoot$Treatment) summary(shoot) # Plot data qplot(y=Length, x=Treatment, colour=Tree, data=shoot) # Look at number of observations per tree table(shoot$Tree, shoot$Treatment) # Structural component: Tree # Explanatory component: Treatment # Fit intra-block model, accounting for Treatments after removing Tree effects shoot.lm <- lm(Length~Tree+Treatment, data=shoot) # Check residuals plot(shoot.lm, ask=FALSE) # Check ANOVA table - no evidence of real treatment differences anova(shoot.lm) # Get table of predicted means from intra-block analysis shoot.lsm <- lsmeans(shoot.lm, ~Treatment) shoot.lsm # pairwise contrasts contrast(shoot.lsm, method="pairwise") # A mixed model, which combines information across trees as well as within trees # would use all of the treatment information - see Exercise 16.3 # End of file