Lynx abundances through time
I used simple summary statistics and plotting to look at trends in the data, including:
data(lynx)
plot(lynx)
summary(lynx)
class(lynx)
The data was collected over a roughly 100 year period from 1821-1934. The plot reveals some very large fluctuations in trappings of Canadian lynx, with sharp increases and decreases every decade or so. class(lynx) reveals that the data set is in fact a time series (‘ts’).
kt <-kurtosis(lynx)
sk <- skewness(lynx)
my.xlim <- range(lynx)
h<-hist(lynx, breaks=10, col="lightblue", xlab="lynx numbers",main="",xlim=my.xlim)
xfit<-seq(min(lynx),max(lynx),length=100)
yfit<-dnorm(xfit,mean=mean(lynx),sd=sd(lynx))
yfit <- yfit*diff(h$mids[1:2])*length(lynx)
lines(xfit, yfit, col="darkblue", lwd=2)
boxplot(lynx, horizontal=TRUE, outline=TRUE, axes=FALSE,ylim=my.xlim, col = "lightgreen", add = TRUE, boxwex=3)
text(x =3200 , y=40, labels = paste("Kurtosis=",round(kt,2)),pos = 4)
text(x =3200 , y=33, labels = paste("Skewness=",round(sk,2)),pos = 4)
I fit the data to a linear model to determine the extent to which the number of trapped lynx varied from year to year.
lynxtime <- time(lynx)
lynx.lm <- lm(lynx ~ lynxtime)
summary(lynx.lm)
I interpreted the lm output to mean that the number of trapped lynx increased annually by 3 animals over the length of the data set.
I then used a moving average filtering method in order to smooth the data.
ma10 <- filter(x=lynx, filter=rep(x=1/10,times=10), sides=2)
ma5 <- filter(x=lynx, filter=rep(x=1/5,times=5), sides=2)
plot(lynx,col="grey")
lines(ma10,col="red",lwd=2)
lines(ma5,col="blue",lwd=2)
abline(lynx.lm, col="black",lwd=2, lty="dashed")
Note the trend line has a very slight increase over the time period.
I took some advise and played around with the filter lengths a little.
ma8 <- filter(x=lynx, filter=rep(x=1/8,times=8), sides=2)
ma5 <- filter(x=lynx, filter=rep(x=1/5,times=5), sides=2)
plot(lynx,col="grey")
lines(ma8,col="red",lwd=2)
lines(ma5,col="blue",lwd=2)
abline(lynx.lm, col="black",lwd=2, lty="dashed")
ma6 <- filter(x=lynx, filter=rep(x=1/6,times=6), sides=2)
ma5 <- filter(x=lynx, filter=rep(x=1/5,times=5), sides=2)
plot(lynx,col="grey")
lines(ma6,col="red",lwd=2)
lines(ma5,col="blue",lwd=2)
abline(lynx.lm, col="black",lwd=2, lty="dashed")
It seems that a filter rep of 1/8 is better than that of 10 or 6, and is a more of a median value.
What are the forecasts for lynx trappings given the data?
lynxforecasts <- HoltWinters(lynx, beta=FALSE, gamma=FALSE)
lynxforecasts
lynxforecasts$fitted
plot(lynxforecasts)
I’m not really sure what these forecasts are revealing, but there seems to be a consistent skew to the right for the forecasted data.