# # Exercise 12.4 # # 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 I Shield, Rothamsted Research # Version 1, 15/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(ggplot2) # for plotting # Read data willowstems <- read.table("willowstems.dat",sep="",header=T) summary(willowstems) # Plot DryMatter against MaxLength qplot(y=DryMatter, x=MaxLength, data=willowstems) # Fit SLR model willowstems.slr <- lm(DryMatter~MaxLength, data=willowstems) # Use ANOVA to check for strength of relationship anova(willowstems.slr) # Summarise using adjusted R-squared summary(willowstems.slr)$adj.r.squared # Plot residuals plot(willowstems.slr, ask=FALSE) # Get fitted model plot plot.obs <- ggplot(data=willowstems.slr, aes(y=DryMatter, x=MaxLength) ) plot.obs + geom_point() + geom_line(aes(y=fitted(willowstems.slr))) + ggtitle("Observed data with fitted SLR") # End of file - but see also Exercises 13.5 and 14.5