Get Started

Compare the random walk (RW) and autoregressive (AR) models

The random walk (RW) model is a special case of the autoregressive (AR) model, in which the slope parameter is equal to 1. Recall from previous chapters that the RW model is not stationary and exhibits very strong persistence. Its sample autocovariance function (ACF) also decays to zero very slowly, meaning past values have a long lasting impact on current values.

The stationary AR model has a slope parameter between -1 and 1. The AR model exhibits higher persistence when its slope parameter is closer to 1, but the process reverts to its mean fairly quickly. Its sample ACF also decays to zero at a quick (geometric) rate, indicating that values far in the past have little impact on future values of the process.

In this exercise, you'll explore these qualities by simulating and plotting additional data from an AR model.

This is a part of the course

“Time Series Analysis in R”

View Course

Exercise instructions

  • Use arima.sim() to simulate 200 observations from an AR model with slope 0.9. Save this to x.
  • Use ts.plot() to plot x and use acf() to view its sample ACF.
  • Now do the same from an AR model with slope 0.98. Save this to y.
  • Now do the same from a RW model (z), and compare the time series and sample ACFs generated by these three models.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Simulate and plot AR model with slope 0.9 
x <- arima.sim(model = ___, n = ___)
ts.plot(___)
acf(___)

# Simulate and plot AR model with slope 0.98
y <- 
ts.plot(___)
acf(___)

# Simulate and plot RW model
z <- 
ts.plot(___)
acf(___)
Edit and Run Code

This exercise is part of the course

Time Series Analysis in R

IntermediateSkill Level
4.5+
8 reviews

Learn the core techniques necessary to extract meaningful insights from time series data.

In this chapter, you will learn the autoregressive (AR) model and several of its basic properties. You will also practice simulating and estimating the AR model in R, and compare the AR model with the random walk (RW) model.

Exercise 1: The autoregressive modelExercise 2: Simulate the autoregressive modelExercise 3: Estimate the autocorrelation function (ACF) for an autoregressionExercise 4: Persistence and anti-persistenceExercise 5: Compare the random walk (RW) and autoregressive (AR) models
Exercise 6: AR model estimation and forecastingExercise 7: Estimate the autoregressive (AR) modelExercise 8: Simple forecasts from an estimated AR model

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free