Skip to Content
R in a Nutshell, 2nd Edition
book

R in a Nutshell, 2nd Edition

by Joseph Adler
October 2012
Beginner to intermediate
721 pages
21h 38m
English
O'Reilly Media, Inc.
Content preview from R in a Nutshell, 2nd Edition

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R in a Nutshell

R in a Nutshell

Joseph Adler
The R Book, 2nd Edition

The R Book, 2nd Edition

Michael J. Crawley
The R Book

The R Book

Michael J. Crawley
R Packages

R Packages

Hadley Wickham

Publisher Resources

ISBN: 9781449358204Errata Page