Estimate the autoregressive (AR) model
For a given time series x
we can fit the autoregressive (AR) model using the arima()
command and setting order
equal to c(1, 0, 0)
. Note for reference that an AR model is an ARIMA(1, 0, 0) model.
In this exercise, you'll explore additional qualities of the AR model by practicing the arima()
command on a simulated time series x
as well as the AirPassengers
data. This command allows you to identify the estimated slope (ar1
), mean (intercept
), and innovation variance (sigma^2
) of the model.
Both x
and the AirPassengers
data are preloaded in your environment. The time series x
is shown in the figure on the right.
This is a part of the course
“Time Series Analysis in R”
Exercise instructions
- Use
arima()
to fit the AR model to the seriesx
. Closely examine the output from this command. - What are the slope (
ar1
), mean (intercept
), and innovation variance (sigma^2
) estimates from your previous command? Type them into your R workspace. - Now, fit the AR model to
AirPassengers
, saving the results asAR
. Useprint()
to display the fitted modelAR
. - Finally, use the commands provided to plot the
AirPassengers
, calculate the fitted values, and add them to the figure.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Fit the AR model to x
arima(___, order = ___)
# Copy and paste the slope (ar1) estimate
# Copy and paste the slope mean (intercept) estimate
# Copy and paste the innovation variance (sigma^2) estimate
# Fit the AR model to AirPassengers
AR <-
print(AR)
# Run the following commands to plot the series and fitted values
ts.plot(AirPassengers)
AR_fitted <- AirPassengers - residuals(AR)
points(AR_fitted, type = "l", col = 2, lty = 2)