Cover by Joseph Adler

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Time Series Models

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).

Extrapolating times series ()

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.

ArgumentDescription 
xA time series. 
aicA logical value that specifies whether the Akaike information criterion is used to choose the order of the model.TRUE
order.maxA numeric value specifying the maximum order of the model to fit.NULL
methodA 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.actionA function that specifies how to handle missing values. 
seriesA character ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required