Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 40 ยท ARIMA and SARIMA

Multivariate Series: VAR and Granger Causality

Model several related time series together with a VAR in statsmodels: lag selection, forecasting, impulse responses and the Granger causality test, with the warnings that come with it.

So far every model had one series. Real systems have several that influence each other: advertising and sales, interest rates and inflation, temperature and electricity demand. A vector autoregression (VAR) models all of them at once. Each series is regressed on the past values of itself and of every other series, so the model captures feedback in both directions.

For two series y1 and y2 and one lag, a VAR(1) is two equations:

  • y1[t] = c1 + a11 y1[t-1] + a12 y2[t-1] + e1[t]
  • y2[t] = c2 + a21 y1[t-1] + a22 y2[t-1] + e2[t]

A VAR(p) uses p lags of every series. The number of parameters grows quickly (k series, p lags: k x (k x p + 1) coefficients), so VARs suit a handful of series and a decent amount of data. Like AR models, a VAR requires stationary inputs, so difference or transform first.

Simulate and fit a VAR

We build two series where y1 is an AR process and y2 reacts to y1's previous value, but y1 does not react to y2.

Python Fitting a VAR(1)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The table has one column per equation. In the y2 column the coefficient on L1.y1 is near 0.6 (the true value), while in the y1 column the coefficient on L1.y2 is near zero.

Choosing the lag order

Use information criteria, just as for ARIMA. select_order fits models up to maxlags and reports the best lag for each criterion.

Python Selecting the VAR order

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

BIC tends to pick the smallest adequate lag and AIC a little more; with a true lag of 1 both should land near 1 or 2.

Forecasting several series

forecast needs the last p observations as a starting point and returns an array with one column per series.

Python Forecast two series together

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Forecasts of a stationary VAR decay toward the series means as the horizon grows, exactly like a stationary AR model.

Granger causality

Series X Granger-causes Y if the past of X helps predict Y beyond what the past of Y already does. The test compares a model for Y with and without lags of X. A small p-value means X's history carries predictive information about Y.

Python Which way does the information flow?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first p-value is essentially zero and the second is large, matching how the data were built.

"Granger causality" is predictive precedence, not real causation. A hidden third variable that moves X first and Y later produces the same result. Treat a significant test as a hint to investigate, never as proof that one thing causes another.

Impulse responses

An impulse response function shows how a one-time shock to one series spreads to all series over the following periods. It is the standard way to read a VAR, because the coefficient table alone is hard to interpret.

Python Response of y2 to a shock in y1

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The response of y2 is zero at step 0, jumps at step 1 (the one-period lag) and then fades. Responses are orthogonalized in some tools, so the ordering of columns can matter when the residuals are correlated: state your assumption.

Practical rules

  • Make every series stationary first (differences or log returns). If series are individually non-stationary but share a long-run relationship (cointegration), a VECM is the proper model; plain differencing would throw that relationship away.
  • Keep the system small. Add a series only when you have a reason.
  • Check residual autocorrelation for each equation, as in residual diagnostics.
  • Compare against univariate baselines: a VAR must beat separate ARIMA models on a time-ordered validation to justify its complexity.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does each equation of a VAR(1) with two series contain?

    A VAR regresses each series on lagged values of all series, capturing cross-series feedback.
  2. 2. A Granger test of X on Y gives p = 0.001. The correct reading is:

    Granger causality only measures predictive usefulness, not real-world causation.
  3. 3. Why is the lag order of a VAR kept small?

    With k series and p lags each equation has k x p coefficients, so the model overfits fast on short data.
  4. 4. What does an impulse response function show?

    It traces the effect of a single shock through the system step by step.

Summary

  • A VAR models several stationary series together, each regressed on the lags of all series.
  • Pick the order with information criteria; forecasts revert to the means.
  • Granger causality tests predictive precedence, not true causation.
  • Impulse responses are the readable summary of a fitted VAR.
  • Keep systems small and compare against univariate baselines.

Next: Lag Features and Supervised Framing