Fitting an AR(2) model
For this exercise, we generated data from the AR(2) model, $$X_t = 1.5 X_{t-1} - .75 X_{t-2} + W_t,$$ using x <- arima.sim(model = list(order = c(2, 0, 0), ar = c(1.5, -.75)), n = 200)
. Look at the simulated data and the sample ACF and PACF pair to determine the model order. Then fit the model and compare the estimated parameters to the true parameters.
This is a part of the course
“ARIMA Models in R”
Exercise instructions
- The package astsa is preloaded.
x
contains the 200 AR(2) observations. - Use
plot()
to plot the generated data inx
. - Plot the sample ACF and PACF pair using
acf2()
from theastsa
package. - Use
sarima()
to fit an AR(2) to the previously generated data inx
. Examine the t-table and compare the estimates to the true values.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# astsa is preloaded
# Plot x
# Plot the sample P/ACF of x
# Fit an AR(2) to the data and examine the t-table
This exercise is part of the course
ARIMA Models in R
Become an expert in fitting ARIMA (autoregressive integrated moving average) models to time series data using R.
You will discover the wonderful world of ARMA models and how to fit these models to time series data. You will learn how to identify a model, how to choose the correct model, and how to verify a model once you fit it to data. You will learn how to use R time series commands from the stats and astsa packages.
Exercise 1: AR and MA modelsExercise 2: Fitting an AR(1) modelExercise 3: Fitting an AR(2) modelExercise 4: Fitting an MA(1) modelExercise 5: AR and MA togetherExercise 6: Fitting an ARMA modelExercise 7: Identify an ARMA modelExercise 8: Model choice and residual analysisExercise 9: Model choice - IExercise 10: Model choice - IIExercise 11: Residual analysis - IExercise 12: Residual analysis - IIExercise 13: ARMA get inWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.