Predicting lynx trappings

Our second data set, known as the lynx data set, is a very famous data set and is provided with the core distribution of R. This was first presented in a 1942 paper by C. Elton and M. Nicholson, titled The ten year cycle in numbers of Canadian lynx, which appears in the Journal of Animal Ecology. The data consist of the number of Canadian lynx trapped in the MacKenzie river over the period 1821-1934. We can load the data as follows:

> data(lynx)

The following diagram shows a plot of the lynx data:

Predicting lynx trappings

We will repeat the exact same series of analysis steps as we did with the earthquake data. First, we will create a grid of parameter combinations and use this to train multiple models. Then we will pick the best one on account of it having the smallest AIC value. Finally, we will use the chosen parameter combination to train a model and forecast the next few data points. The reader is encouraged to also experiment with auto.arima().

> d <- 0:2
> p <- 0:6
> q <- 0:6
> lynx_models <- expand.grid(p = p, d = d, q = q)
> lynx_models$aic <- mapply(function(x, y, z)
  getTSModelAICSafe(lynx, x, y, z), lynx_models$p, lynx_models$d, 
  lynx_models$q)
> subset(lynx_models,aic == min(aic))
    p d q      aic
124 4 2 5 1845.407
> lynx_model <- arima(lynx, order = c(4, 2, 5))
> plot(forecast(lynx_model, 10))
Predicting lynx trappings

This time, we predicted a higher order ARIMA model and the forecasted value seems intuitively very reasonable given the observed time series. Even though the peaks of the time series are different, there is a much clearer seasonal pattern in the data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.108.86