Fitting an AR(1) model
Recall that you use the ACF and PACF pair to help identify the orders \(p\) and \(q\) of an ARMA model. The following table is a summary of the results:
AR(\(p\)) | MA(\(q\)) | ARMA(\(p,q\)) | |
---|---|---|---|
ACF | Tails off | Cuts off after lag \(q\) |
Tails off |
PACF | Cuts off after lag \(p\) |
Tails off | Tails off |
In this exercise, you will generate data from the AR(1) model, $$X_t = .9 X_{t-1} + W_t,$$ look at the simulated data and the sample ACF and PACF pair to determine the order. Then, you will fit the model and compare the estimated parameters to the true parameters.
Throughout this course, you will be using sarima()
from the astsa
package to easily fit models to data. The command produces a residual diagnostic graphic that can be ignored until diagnostics is discussed later in the chapter.
This is a part of the course
“ARIMA Models in R”
Exercise instructions
- The package astsa is preloaded.
- Use the prewritten
arima.sim()
command to generate 100 observations from an AR(1) model with AR parameter .9. Save this tox
. - Plot the generated data using
plot()
. - Plot the sample ACF and PACF pairs using the
acf2()
command from theastsa
package. - Use
sarima()
fromastsa
to fit an AR(1) to the previously generated data. Examine the t-table and compare the estimates to the true values. For example, if the time series is inx
, to fit an AR(1) to the data, usesarima(x, p = 1, d = 0, q = 0)
or simplysarima(x, 1, 0, 0)
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Generate 100 observations from the AR(1) model
x <- arima.sim(model = list(order = c(1, 0, 0), ar = .9), n = 100)
# Plot the generated data
# Plot the sample P/ACF pair
# Fit an AR(1) to the data and examine the t-table