Moving Average (MA) Model in R

A Moving Average is a process where each value is a function of the noise in the past observations. These are the random error terms which follow a white noise process. The general form is MA(q), where xt depends on q past values.

Just like AR models, this also has a regression like structure, however, instead of the actual values, we are regressing each value on the noise/error in the previous observations.

We can use the arima.sim() function to simulate the MA model. For the MA model, we will specify model as list(ma = theta) , where theta is the slope parameter from the interval (-1, 1).

Below we create two sets of simulations with MA model, one with a slope of 0.5 and another with a slope of 0.8.

# Simulate AutoRegressive model with 0.5 slope
MA_1 <- arima.sim(model = list(ma = 0.5), n = 200)
# Simulate AutoRegressive model with 0.8 slope
MA_2 <- arima.sim(model = list(ma = 0.9), n = 200)
# Simulate AutoRegressive model with -0.6 slope
MA_3 <- arima.sim(model = list(ma = -0.6), n = 200)
plot.ts(cbind(MA_1 , MA_2, MA_3 ), main="MA Model Simulated Data")

ACF and PACF of Autoregressive Model

We can calculate the Autocorrelation and Partial Autocorrelation functions of the Moving Average model using the acf() and the pacf() functions.

The following are the respective ACF and PACF plots for the MA_1 series.

> acf(MA_1)
> pacf(MA_1)

Related Downloads

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book includes PDFs, explanations, instructions, data files, and R code for all examples.

Get the Bundle for $29 (Regular $57)
JOIN 30,000 DATA PROFESSIONALS

Free Guides - Getting Started with R and Python

Enter your name and email address below and we will email you the guides for R programming and Python.

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book comes with PDFs, detailed explanations, step-by-step instructions, data files, and complete downloadable R code for all examples.