Get Started

Simulating ARMA models

As we saw in the video, any stationary time series can be written as a linear combination of white noise. In addition, any ARMA model has this form, so it is a good choice for modeling stationary time series.

R provides a simple function called arima.sim() to generate data from an ARMA model. For example, the syntax for generating 100 observations from an MA(1) with parameter .9 is arima.sim(model = list(order = c(0, 0, 1), ma = .9 ), n = 100). You can also use order = c(0, 0, 0) to generate white noise.

In this exercise, you will generate data from various ARMA models. For each command, generate 200 observations and plot the result.

This is a part of the course

“ARIMA Models in R”

View Course

Exercise instructions

  • Use arima.sim() and plot() to generate and plot white noise.
  • Use arima.sim() and plot() to generate and plot an MA(1) with parameter .9.
  • Use arima.sim() and plot() to generate and plot an AR(2) with parameters 1.5 and -.75.

Hands-on interactive exercise

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

# Generate and plot white noise
WN <- 


# Generate and plot an MA(1) with parameter .9 
MA <- 


# Generate and plot an AR(2) with parameters 1.5 and -.75
AR <- 

This exercise is part of the course

ARIMA Models in R

IntermediateSkill Level
4.6+
16 reviews

Become an expert in fitting ARIMA (autoregressive integrated moving average) models to time series data using R.

You will investigate the nature of time series data and learn the basics of ARMA models that can explain the behavior of such data. You will learn the basic R commands needed to help set up raw time series data to a form that can be analyzed using ARMA models.

Exercise 1: First things firstExercise 2: Data playExercise 3: Elements of time seriesExercise 4: Stationarity and nonstationarityExercise 5: DifferencingExercise 6: Detrending dataExercise 7: Dealing with trend and heteroscedasticityExercise 8: Stationary time series: ARMAExercise 9: Simulating ARMA models

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