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`

:

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
`ar`

.

Argument | Description | |
---|---|---|

x | A time series. | |

aic | A logical value that specifies whether the Akaike information criterion is used to choose the order of the model. | `TRUE` |

order.max | A numeric value specifying the maximum order of the model to fit. | `NULL` |

method | A character value that specifies the method to use for
fitting the model. Specify `method="yw"` (or `method="yule-walker"` ) for the
Yule-Walker method, `method="burg"` for the Burg method,
`method="ols"` for ordinary least
squares, or `method="mle"` for
maximum likelihood estimation. | ```
c("yule-walker", "burg", "ols",
"mle", "yw")
``` |

na.action | A function that specifies how to handle missing values. | |

series | A character ... |

Start Free Trial

No credit card required