Time series models are a little different from other models that we’ve seen in R. With most other models, the goal is to predict a value (the response variable) from a set of other variables (the predictor variables). Usually, we explicitly assume that there is no autocorrelation—that the sequence of observations does not matter.
With time series, we assume the opposite: we assume that previous observations help predict future observations (see Figure 23-1).
Figure 23-1. Extrapolating times series (http://xkcd.com/605/)
To fit an autoregressive model to a time series, use the function
ar(x, aic = TRUE, order.max = NULL, method=c("yule-walker", "burg", "ols", "mle", "yw"), na.action, series, ...)
Here is a description of the arguments to
|x||A time series.|
|aic||A logical value that specifies whether the Akaike information criterion is used to choose the order of the model.|
|order.max||A numeric value specifying the maximum order of the model to fit.|
|method||A character value that specifies the method to use for
fitting the model. Specify |
|na.action||A function that specifies how to handle missing values.|
|series||A character ...|