trend,
serial dependence, and
stationarity
blowfly <- read.table("c:\\temp\\blowfly.txt",header=T)
attach(blowfly)
names(blowfly)
flies <- ts(flies)
plot(flies)
length(flies)
par(mfrow=c(2,2))
sapply(1:4, function(x) plot(flies[-c(361: (361-x+1))], flies[-c(1:x)] ) )
sapply(7:10, function(x) plot(flies[-c((361-x+1):361)], flies[-c(1:x)] ) )
par(mfrow=c(1,1))
acf(flies,main="",col="red")
acf(flies,type="p",main="",col="red")
second <- flies[201:361]
summary(lm(second~I(1:length(second))))
detrended <- second - predict(lm(second~I(1:length(second))))
par(mfrow=c(2,2))
ts.plot(detrended)
acf(detrended,main="")
acf(detrended,type="p",main="")
par(mfrow=c(1,1))
ma3 <- function (x) {
y <- numeric(length(x)-2)
for (i in 2:(length(x)-1)) {
y[i] <- (x[i-1]+x[i]+x[i+1])/3
}
y }
temperature <- read.table("c:\\temp\\temp.txt",header=T)
attach(temperature)
tm <- ma3(temps)
plot(temps)
lines(tm[2:158],col="blue")
weather <- read.table("c:\\temp\\SilwoodWeather.txt",header=T)
attach(weather)
names(weather)
plot(upper,type="l")
length(upper)
index <- 1:6940
6940/19
time <- index/365.2632
model <- lm(upper~sin(time*2*pi)+cos(time*2*pi))
plot(time, upper, pch=".")
lines(time, predict(model),col="red",lwd=2)
summary(model)
plot(model$resid,pch=".")
windows(7,4)
par(mfrow=c(1,2))
acf(model$resid,main="")
acf(model$resid,type="p",main="")
temp <- ts(as.vector(tapply(upper,list(month,yr),mean)))
windows(7,7)
acf(temp,main="")
ytemp <- ts(as.vector(tapply(upper,yr,mean)))
acf(ytemp,main="")