# Example Student # Example SN # Assignment 1 # STAT 464 setwd("~/doc/STAT464_11/data") LakeHuron <- read.csv("~/doc/STAT464_11/data/LakeHuron.csv") # Set plots to 2 rows, 1 column (single page plotting!) par(mfrow=c(1,2)) # Plot Lake Huron data with Least-Squares Fit plot(LakeHuron[,1],LakeHuron[,2], type="b", xlab="Years", ylab="Water Level in metres", main="Lake Huron Water Levels") LSfit <- lm(LakeHuron[,2] ~ LakeHuron[,1]) # ... if you forget where the fit is stored ... # attributes(LSfit) lines(LakeHuron[,1],LSfit$fitted.values,type="l",col="red") # Need first difference of Xt => first difference of LakeHuron[,2] len <- length(LakeHuron[,2]) diff <- LakeHuron[2:len,2] - LakeHuron[1:(len-1),2] # Add plot of first differences plot(LakeHuron[2:len,1],diff,type="l",xlab="Years", ylab="First Difference in metres",main="First Difference for Lake Huron data")