Fitting a vector autoregression (VAR) to two related series

Today let's learn how to forecast two related series together, using a model called a vector autoregression.

Let's say you follow the Canadian economy. For every quarter from 1980Q1 to 2000Q4 you have two numbers: the unemployment rate in percent, called U, and an employment index called e. That is 84 quarters of each.

The index e is 100 times the natural log of employment, and it climbs from 929.6 to 961.8 over these years. U starts at 7.53% in 1980Q1, peaks at 12.77% in 1982Q4 and ends at 6.87% in 2000Q4.

Now, you want to forecast U. The usual approach is to use the past of U itself. But employment moves at the same time as unemployment. So here is the question for this lesson: does the past of e add anything to a forecast of U, beyond what U's own past already gives?

The line above is U, quarter by quarter, from 7.53 in 1980Q1 through the peak of 12.77 in 1982Q4 to 6.87 in 2000Q4. This is the series we will forecast, first on its own and then with help from e.

How to predict a series from its own past with an AR(2)

Before adding employment, let's build the simplest forecast of U: one that uses only U's own past. The code below loads the Canada data from the vars package, keeps the two series and plots them.

RInteractive R
# Load the Canada data and plot employment and unemployment over time library(vars) data(Canada) y <- Canada[, c("e", "U")] plot(y, main = "Canada, 1980Q1 to 2000Q4") dim(y) #> [1] 84 2 start(y) #> [1] 1980 1 end(y) #> [1] 2000 4

  

plot() draws one panel per series, with e on top and U below. The output confirms 84 rows, from the first quarter of 1980 to the fourth quarter of 2000.

To forecast U from its own past we need its lags. A lag is the same series shifted back in time. The lag 1 of U is U one quarter earlier, and the lag 2 is U two quarters earlier.

Regressing a series on its own lags is called an autoregression, and the number of lags it uses is its order. So an AR(2) predicts U this quarter from a constant, U one quarter back and U two quarters back.

The first two quarters do not have both lags, so 2 rows are lost and 84 - 2 = 82 rows are usable. The code below builds the lag columns for both series into a data frame called L, then fits one AR(2) per series with lm(). Each row of L is one quarter from 1980Q3 on: e and U are that quarter, U.l1 and U.l2 are U one and two quarters earlier, and e.l1 and e.l2 are the same for e.

RInteractive R
# Build the lag columns and fit an AR(2) to each series on its own n <- nrow(y) L <- data.frame( e = y[3:n, "e"], U = y[3:n, "U"], e.l1 = y[2:(n - 1), "e"], U.l1 = y[2:(n - 1), "U"], e.l2 = y[1:(n - 2), "e"], U.l2 = y[1:(n - 2), "U"] ) nrow(L) #> [1] 82 ar_U <- lm(U ~ U.l1 + U.l2, data = L) ar_e <- lm(e ~ e.l1 + e.l2, data = L) round(coef(ar_U), 3) #> (Intercept) U.l1 U.l2 #> 0.515 1.542 -0.597 round(coef(ar_e), 3) #> (Intercept) e.l1 e.l2 #> 1.567 1.727 -0.729 round(c(U = summary(ar_U)$sigma, e = summary(ar_e)$sigma), 3) #> U e #> 0.354 0.410

  

The U fit predicts U this quarter as 0.515, plus 1.542 times last quarter's U, minus 0.597 times U from two quarters back. The e fit has the same form, with its own three coefficients.

The last line prints the residual standard error of each fit. It is the typical size of a residual, the gap between an actual quarter and its fitted value. It is in the units of the series: 0.354 for U and 0.410 for e. We will keep these two numbers as the baseline.

Each fit uses only its own series. The U fit has no e term in it, and the e fit has no U term.