Moving Average (MA) Models

Chapter 6: Lesson 1

Learning Outcomes

Characterize the properties of moving average (MA) models
  • Define a moving average (MA) process
  • Write an MA(q) model in terms of the backward shift operator
  • State the mean and variance of an MA(q) process
  • Explain the autocorrelation function of an MA(q) process
  • Define an invertible MA process
Fit time series models to data and interpret fitted parameters
  • Determine an appropriate MA(q) model to fit to a time series based on the ACF plot
  • Fit an MA(q) model to data in R using the arima() function
  • Assess model fit by examining residual diagnostic plots
  • Interpret the fitted MA coefficients

Preparation

  • Read Sections 6.1-6.4

Learning Journal Exchange (10 min)

  • Review another student’s journal

  • What would you add to your learning journal after reading another student’s?

  • What would you recommend the other student add to their learning journal?

  • Sign the Learning Journal review sheet for your peer

Class Activity: Introduction to Moving Average (MA) Models (15 min)

Stationary Processes

In previous chapters, we have explored how to identify and remove the trend and seasonal components of a time series. After the trend and seasonal component have been properly removed, the residual should be stationary. However, these residual components may still contain autocorrelation.

In this chapter, we will explore stationary models that are appropriate when there are no obvious trends or seasonal elements. Combining the fitted stationary model with the estimated trend and seasonal components can improve our ability to make forecasts. We will build on the autoregressive (AR) models we learned in Chapter 4.

Strictly Stationary Series

First, we define a strictly stationary series.

Definition of Strict Stationarity

A time series model {xt} is said to be strictly stationary if the joint distribution of the random variables xt1,xt2,,xtn is the same as the joint distribution of xt1+m,xt2+m,,xtn+m for all t1,t2,,tn and m, so that the distribution of the values in the time series is the same after an arbitrary time shift.

If a time series is strictly stationary, then its mean and variance are constant in time. Hence, the autocovariance cov(xt,xs) depends only on the lag, k=|ts|. We can therefore denote the covariance function as γ(k)=cov(xt,xt+k).

Note: It is possible that a series could have a constant mean and variance in time and the autocovariance depends only on the lag, but the series is not strictly stationary. This is called second-order stationary.

We will focus on the second-order properties of the time series, even though all the series we will explore in this chapter are strictly stationary.

Note: if a white noise process is Gaussian, the stochastic process is completely determined by the mean and covariance structure. This is similar to how a (univariate or multivariate) normal distribution is completely specified by the mean and variance-covariance matrix.

The concept of stationarity is a property of time series models. When we use certain models, we are assuming stationarity. Before we apply these models, it is important to check for stationarity in the time series. In other words, we check to see if there is evidence of a trend or seasonality and if so, we remove these components. We can use methods such as decomposition, Holt-Winters, or regression to remove the trend and seasonality. Hence, it is typically reasonable to consider the residual series as a stationary series. Typically the models in this chapter are applied to the residual series from a regression or similar analysis.

Moving Average (MA) Models

Recall in Chapter 4, Lesson 3, we learned the definition of an AR model:

Definition of an Autoregressive (AR) Model

The time series {xt} is an autoregressive process of order p, denoted as AR(p), if xt=α1xt1+α2xt2+α3xt3++αp1xt(p1)+αpxtp+wt                       (4.15)

where {wt} is white noise and the αi are the model parameters with αp0.

The AR(p) model can be expressed in terms of the backward shift operator: (1α1Bα2B2αpBp)xt=wt

Now, we consider a different, but related model, the moving average (MA) model

Definition of a Moving Average (MA) Model

We say that a time series {xt} is a moving average process of order q, denoted as MA(q), if each term in the time series is a linear combination of the current white noise term and the q most recent past white noise terms.

It is given as: xt=wt+β1wt1+β2wt2+β3wt3++βq1wt(q1)+βqwtq                       (6.1)

where {wt} is white noise with zero mean and variance σw2, and the βi are the model parameters with βq0.

Check Your Understanding
  • Write Equation (6.1) in terms of the backward shift operator. Your answer will be of the form:

xt=(some qth degree polynomial in B)wt=ϕq(B)wt

Note

An MA(q) process is comprised of a finite summation of stationary white noise terms. Hence, an MA(q) process will be stationary with a time-invariante mean and autocovariance.

The mean and variance of {xt} are easily derived. The mean must be zero, because each term is a sum of scaled white noise terms with mean zero.

The variance of an MA(q) process is σw2(1+β12+β22+β32++βq12+βq2). This can be seen, because the white noise terms are independent with the same variance.

So, the autocorrelation function is

ρ(k)=cor(xt,xt+k)={1,k=0 i=0qkβiβi+ki=0qβi2,k=1,2,,q 0,k>q where β0=1.

Note that the autocorrelation function is zero if k>q, because xt and xt+k would be independent weighted summations of white noise processes and hence the covariance between them would be zero.

We now define an invertible MA process.

Definition of an Invertible MA Process

An MA process is said to be invertible if it can be expressed as a stationary autoregressive process (of infinite order) with no error term.

Example of an Invertible MA Process

Recall that (1x)(1+x+x2+x3+)=1

or,

(1x)1=(1+x+x2+x3+) if |x|<1.

Now, note that the MA process

xt=(1βB)wt

can be written as:

(1βB)1xt=wt(1+βB+β2B2+β3B3+)xt=wtxt+βxt1+β2xt2+β3xt3+=wtxt=(βxt1β2xt2β3xt3)+wt

assuming that |β|<1. Note that this series will not converge unless |β|<1.

We have just shown that the MA process xt=(1βB)wt is invertible.

Theorem: Invertibility of an MA(q) Process

The MA(q) process xt=ϕq(B)wt will be invertible if the solutions to the equation ϕq(B)=0 are all greater than 1 in absolute value.

Does this remind you of the test for the stationarity of an AR(p) model?

Note that the autocovariance function (acvf) will identify a unique MA(q) process only if the process is invertible. Fortunately, the algorithm R uses to estimate an MA(q) process always leads to an invertible model.

Class Activity: Simulating an MA(q) Model (5 min)

The textbook gives a simulation of an MA(3) process:

xt=wt+β1wt1+β2wt2+β3wt3

where β1=0.7, β1=0.5, and β3=0.2. This shiny app allows you to simulate from this process.

Check Your Understanding

Use the simulation above to do the following:

  • Generate the theoretical acf plot for the MA(3) model xt=wt0.7wt1+0.5wt20.2wt3
  • How does the value of the β’s affect the acf?
  • Simulate 1000 observations from this MA(3) process.
    • Give the time plot of the simulated data
    • Plot the acf of the simulated data.
  • Compare the acf from the simulated data with the theoretical acf.

Class Activity: Identifying AR and MA Models from the ACF and PACF (5 min)

AR Process

Recall that on page 81, the textbook states that in general, the partial autocorrelation at lag k is the kth coefficient of a fitted AR(k) model. This implies that if the underlying process is AR(p), then all the coefficients αk will equal 0 whenever k>p. So, an AR(p) process will result in partial correlations that are zero after lag p. So, we can look at the correlogram of partial autocorrelations to determine the order of an appropriate AR process to model a time series.

MA Process

Similarly, for an MA(q) process, the coefficients βk will equal 0 whenever k>q. Hence, an MA(q) process will demonstrate autocorrelations that are 0 after lag q. So, considering the correlogram of autocorrelations, we can assess if an MA(q) model would be appropriate.

Bless their hearts, the textbook authors give a bad example in Section 6.4.2. They even state that it is “not a realistic realisation.” MA processes naturally arise in ratios of observed data. Multi-period asset returns (i.e. ratios of some previous term’s value) tend to follow an MA process.

For example, if there are 252 trading days in a year, then the daily series of year-over-year returns (this year’s value divided by last year’s value) follows an MA(2521) process. If we are comparing values observed to those from one week ago, we would have an MA(71) process.

Comparison

ACF and PACF of an AR(p) Process

We can use the pacf and acf plots to assess if an AR(p) or MA(q) model is appropriate. For an AR(p) or MA(q) process, we observe the following:

AR(p) MA(q)
ACF Tails off Cuts off after lag q
PACF Cuts off after lag p Tails off

Class Activity: Fitting an MA(q) Model to GDP Year-Over-Year Ratios (5 min)

To fit an MA(q) model, we look at the acf to determine if it cuts off after q lags.

Show the code
# gdp_ts <- rio::import("https://byuistats.github.io/timeseries/data/gdp_fred.csv") |>
gdp_ts <- rio::import("data/gdp_fred.csv") |>
  select(-comments) |>
  mutate(year_over_year = gdp_millions / lag(gdp_millions, 4)) |>
  mutate(quarter = yearquarter(mdy(quarter))) |>
  filter(quarter >= yearquarter(my("Jan 1990")) & quarter < yearquarter(my("Jan 2025"))) |>
  na.omit() |>
  mutate(t = 1:n()) |>
  mutate(std_t = (t - mean(t)) / sd(t)) |>
  as_tsibble(index = quarter)

gdp_ts |>
  autoplot(.vars = gdp_millions) +
    labs(
      x = "Quarter",
      y = "GDP (Millions of $US)",
      title = "U.S. Gross Domestic Product (GDP) in Millions of Dollars"
    ) +
    theme_minimal() +
    theme(plot.title = element_text(hjust = 0.5))

Show the code
gdp_ts |>
  autoplot(.vars = year_over_year) +
  stat_smooth(method = "lm", 
              formula = y ~ x, 
              geom = "smooth",
              se = FALSE,
              color = "#E69F00",
              linetype = "dotted") +
    labs(
      x = "Quarter",
      y = "Ratio",
      title = "Year-Over-Year Change in U.S. GDP"
    ) +
    theme_minimal() +
    theme(plot.title = element_text(hjust = 0.5))

Show the code
gdp_ts |>
  select(year_over_year) |>
  acf()

Show the code
gdp_ts |>
  select(year_over_year) |>
  pacf()

Check Your Understanding
  • What process would you use to model the year-over-year GDP ratios?
  • Modify the code below to implement your model.
gdp_ma <- gdp_ts |>
  model(arima = ARIMA(year_over_year ~ 1 + pdq(0,0,1) + PDQ(0, 0, 0)))

tidy(gdp_ma)

gdp_ma |>
  residuals() |>
  ACF() |>
  autoplot()
  • What are the values of the model coefficients?
  • Based on the acf of the residuals, is the MA model you identified a good fit to the data?

Small-Group Activity: Fitting an MA(q) Model to the Trade Data (15 min)

Vessels Cleared in Foreign Trade for United States

In the homework for Chapter 1 Lesson 5, you explored data on the thousands of net tons cleared in foreign trade for the United States each month from January 1902 to December 1940. The code below computes the year-over-year change in the amount of cargo cleared for trade. This is stored in the variable ratio.

Show the code
vessels_ts <- rio::import("https://byuistats.github.io/timeseries/data/Vessels_Trade_US.csv") |>
  # filter(-comments) |>
  mutate(
    date = yearmonth(dmy(date)),
    ratio = vessels / lag(vessels, 12)
  ) |>
  na.omit() |>
  as_tsibble(index = date)

vessels_ts |>
  autoplot(.vars = ratio) +
    labs(
      x = "Month",
      y = "Ratio",
      title = "Year-Over-Year Change in Net Tons on Vessels Cleared for Trade"
    ) +
    theme_minimal() +
    theme(plot.title = element_text(hjust = 0.5))

Check Your Understanding

Practice applying an MA(q) model using the year-over-year amounts.

  • Determine which MA model is most appropriate for these data.
  • Fit the model you deem most appropriate.
  • Assess the appropriateness of applying your model to the data.

Homework Preview (5 min)

  • Review upcoming homework assignment
  • Clarify questions
Download Homework

MA(q) process in terms of the backward shift operator

Simulating an MA(3) process

Class Activity: Fitting an MA(q) Model to GDP Year-Over-Year Ratios

Small-Group Activity: Fitting an MA(q) Model to the Trade Data