library(fpp3)
library(vars)
select <- dplyr::select
library(astsa)Note 25: Granger Causality & Multivariate Forecast Benchmarking
Module 6: Multivariate & Breaks
Learning Objectives
- Define Granger causality rigorously as predictive precedence (distinct from structural causation) and write the exact matched-sample nested \(F\)-test.
- Verify a manual matched-sample Granger \(F\)-test against
lmtest::grangertest()and distinguish pairwise tests from joint block-exogeneity tests invars::causality()when \(K \ge 3\). - Construct a strict zero-leakage out-of-sample forecast benchmark comparing univariate
ARIMAandETSagainst bivariate and trivariateVARmodels onus_change. - Interpret RMSE, MAE, and MAPE carefully on stationary macroeconomic percentage-change series.
1. Granger Causality: Predictive Precedence, Not Structural Cause
In a multivariate system, knowing whether past lags of series \(X\) help predict future values of series \(Y\) guides both variable selection and economic interpretation. Granger (1969) formalized this idea:
A stationary series \(X\) Granger-causes a stationary series \(Y\) at lag order \(p\) if past values \((x_{t-1}, \dots, x_{t-p})\) yield a statistically significant improvement in predicting \(y_t\) beyond the information already contained in past values \((y_{t-1}, \dots, y_{t-p})\).
Crucially, Granger causality measures predictive precedence, not structural or physical causation. A rooster crowing Granger-causes sunrise, and holiday retail orders Granger-cause December shipping volume, yet neither causes the physical or calendar event. Forward-looking expectations, omitted common drivers, and temporal aggregation routinely generate Granger causality without a direct causal mechanism.
Exact Matched-Sample Nested \(F\)-Test
To test whether \(X\) Granger-causes \(Y\) at lag \(p\), estimate two nested regressions on the exact same effective sample \(t = p + 1, \dots, T\) (sample size \(T_{\text{eff}} = T - p\)):
\[ \begin{aligned} \text{Unrestricted (U):} \quad y_t &= c + \sum_{i=1}^p \alpha_i y_{t-i} + \sum_{i=1}^p \beta_i x_{t-i} + u_t, \\ \text{Restricted (R):} \quad y_t &= c + \sum_{i=1}^p \alpha_i y_{t-i} + e_t. \end{aligned} \]
The null hypothesis of no Granger causality is \(H_0: \beta_1 = \beta_2 = \dots = \beta_p = 0\). Comparing residual sums of squares \(\text{RSS}_R\) and \(\text{RSS}_U\) on the identical \(T_{\text{eff}}\) rows produces the exact \(F\)-statistic:
\[ F = \frac{(\text{RSS}_R - \text{RSS}_U) / p}{\text{RSS}_U / (T_{\text{eff}} - 2p - 1)} \sim F_{p, \, T_{\text{eff}} - 2p - 1} \quad \text{under } H_0. \]
Fitting the restricted regression on all \(T\) rows while fitting the unrestricted regression on \(T - p\) rows invalidates the \(F\)-test because the two models are no longer nested on the same observations.
2. Manual Verification vs. lmtest::grangertest() & vars::causality()
We test whether quarterly U.S. Consumption growth Granger-causes Production growth (\(p = 2\)) on us_change (1970 Q1–2019 Q2), verifying our manual matched-sample \(F\)-statistic directly against lmtest::grangertest().
uc_lags <- us_change |>
as_tibble() |>
mutate(
P_l1 = lag(Production, 1), P_l2 = lag(Production, 2),
C_l1 = lag(Consumption, 1), C_l2 = lag(Consumption, 2)
) |>
drop_na()
m_u <- lm(Production ~ P_l1 + P_l2 + C_l1 + C_l2, data = uc_lags)
m_r <- lm(Production ~ P_l1 + P_l2, data = uc_lags)
p_lag <- 2
t_eff <- nrow(uc_lags)
rss_r <- sum(resid(m_r)^2)
rss_u <- sum(resid(m_u)^2)
f_man <- ((rss_r - rss_u) / p_lag) / (rss_u / (t_eff - 2 * p_lag - 1))
p_man <- pf(f_man, df1 = p_lag, df2 = t_eff - 2 * p_lag - 1, lower.tail = FALSE)
gt_cp <- lmtest::grangertest(Production ~ Consumption, order = 2, data = us_change)
tibble(
Method = c("Manual matched-sample F-test", "lmtest::grangertest()"),
F_stat = c(f_man, gt_cp$F[2]),
df1 = c(p_lag, abs(gt_cp$Df[2])),
df2 = c(t_eff - 2 * p_lag - 1, gt_cp$Res.Df[1]),
p_value = c(p_man, gt_cp$`Pr(>F)`[2])
) |>
fmt_tbl(digits = 5, caption = "Exact match between manual matched-sample F-test and grangertest() for Consumption -> Production")| Method | F_stat | df1 | df2 | p_value |
|---|---|---|---|---|
| Manual matched-sample F-test | 10.79 | 2 | 191 | 0.00004 |
| lmtest::grangertest() | 10.79 | 2 | 191 | 0.00004 |
Both methods agree to every decimal place (\(F = 10.789, \, p = 3.6 \times 10^{-5}\)): past consumption growth strongly helps predict future industrial production growth.
Pitfall in \(K \ge 3\) Systems: Pairwise vs. Joint vars::causality()
Be careful when calling vars::causality(var_fit, cause = "X") on a VAR with \(K \ge 3\) variables. Unlike pairwise lmtest::grangertest(), vars::causality() tests the joint hypothesis that \(X\) fails to Granger-cause all remaining \(K - 1\) variables simultaneously, giving \(p(K - 1)\) numerator degrees of freedom!
n_tr <- floor(0.8 * nrow(us_change))
uc_tr <- us_change |> slice(1:n_tr)
uc_te <- us_change |> slice((n_tr + 1):n())
v2_tr <- vars::VAR(uc_tr |> as_tibble() |> select(Consumption, Income), p = 2, type = "const")
v3_tr <- vars::VAR(uc_tr |> as_tibble() |> select(Consumption, Income, Production), p = 2, type = "const")
c2 <- vars::causality(v2_tr, cause = "Income")$Granger
c3 <- vars::causality(v3_tr, cause = "Income")$Granger
gt_ic <- lmtest::grangertest(Consumption ~ Income, order = 2, data = uc_tr)
tibble(
Test = c("Pairwise grangertest: Income -> Consumption",
"Bivariate VAR causality: Income -> Consumption",
"Trivariate VAR causality: Income -> (Consumption, Production)"),
F_stat = c(gt_ic$F[2], unname(c2$statistic), unname(c3$statistic)),
df1 = c(2, unname(c2$parameter[1]), unname(c3$parameter[1])),
p_value = c(gt_ic$`Pr(>F)`[2], unname(c2$p.value), unname(c3$p.value))
) |>
fmt_tbl(digits = 4, caption = "Pairwise vs. joint Granger causality in 2-variable and 3-variable VARs (training set)")| Test | F_stat | df1 | p_value |
|---|---|---|---|
| Pairwise grangertest: Income -> Consumption | 0.8407 | 2 | 0.4334 |
| Bivariate VAR causality: Income -> Consumption | 0.8407 | 2 | 0.4324 |
| Trivariate VAR causality: Income -> (Consumption, Production) | 1.2159 | 4 | 0.3032 |
Notice that lmtest::grangertest() and the bivariate VAR yield the exact same \(F = 0.8407\) with df1 = 2, whereas the trivariate vars::causality() tests a 4-restriction joint hypothesis (df1 = 4, \(F = 1.2159\)) across both Consumption and Production. Never report a \(K \ge 3\) vars::causality() p-value as a pairwise test between two single variables.
3. Strict Zero-Leakage Out-of-Sample Benchmark on us_change
To evaluate whether multivariate coupling actually improves forecasting, we conduct a strictly chronological 80/20 split (158 training quarters from 1970 Q1 to 2009 Q2; 40 held-out test quarters from 2009 Q3 to 2019 Q2).
Crucially, we allow zero future-covariate leakage: unlike a dynamic regression that feeds actual future Income into the test window (an unfair oracle!), a VAR forecasts Consumption, Income, and Production jointly and recursively using only information available at 2009 Q2.
h_te <- nrow(uc_te)
fit_uni <- uc_tr |>
model(
ARIMA = ARIMA(Consumption),
ETS = ETS(Consumption)
)
fc_uni <- fit_uni |>
forecast(h = h_te) |>
as_tibble() |>
select(.model, Quarter, pred = .mean)
fc_v2 <- tibble(
.model = "VAR(2) Bivariate",
Quarter = uc_te$Quarter,
pred = predict(v2_tr, n.ahead = h_te)$fcst$Consumption[, "fcst"]
)
fc_v3 <- tibble(
.model = "VAR(2) Trivariate",
Quarter = uc_te$Quarter,
pred = predict(v3_tr, n.ahead = h_te)$fcst$Consumption[, "fcst"]
)
fc_all <- bind_rows(fc_uni, fc_v2, fc_v3) |>
left_join(uc_te |> as_tibble() |> select(Quarter, actual = Consumption), by = "Quarter")
fc_all |>
group_by(.model) |>
summarise(
RMSE = sqrt(mean((actual - pred)^2)),
MAE = mean(abs(actual - pred)),
MAPE = mean(abs((actual - pred) / actual)) * 100
) |>
arrange(RMSE) |>
fmt_tbl(digits = 3, caption = "Zero-leakage out-of-sample Consumption forecast accuracy (2009 Q3-2019 Q2, h = 40)")| .model | RMSE | MAE | MAPE |
|---|---|---|---|
| VAR(2) Trivariate | 0.334 | 0.274 | 100.9 |
| VAR(2) Bivariate | 0.336 | 0.276 | 102.4 |
| ARIMA | 0.345 | 0.284 | 101.5 |
| ETS | 0.996 | 0.946 | 181.4 |
ggplot(fc_all, aes(x = Quarter)) +
geom_line(data = uc_te, aes(y = Consumption, colour = "Actual"), linewidth = 0.8) +
geom_line(aes(y = pred, colour = .model), linewidth = 0.85) +
scale_colour_manual(
values = c(
"Actual" = "#1A252F",
"ARIMA" = unname(ts_pal["teal"]),
"ETS" = unname(ts_pal["crimson"]),
"VAR(2) Bivariate" = unname(ts_pal["orange"]),
"VAR(2) Trivariate" = unname(ts_pal["navy"])
),
breaks = c("Actual", "ARIMA", "ETS", "VAR(2) Bivariate", "VAR(2) Trivariate")
) +
labs(
title = "Zero-Leakage Out-of-Sample Benchmark: U.S. Consumption Growth",
subtitle = "ARIMA and VAR(2) revert to mean growth; ETS locks onto the 2009 trough",
x = "Quarter",
y = "Quarterly Consumption Growth (%)",
colour = "Model"
)
Three practical lessons emerge clearly:
- Multivariate gains:
VAR(2) Trivariateachieves the lowest RMSE (0.334) and MAE (0.274), edging outVAR(2) Bivariate(0.336) and univariateARIMA(0.345) by incorporating early post-recession signals from income and industrial production. - Why ETS struggles here: Because
ETStreats the level as a non-stationary random walk, it locks onto the depressed2009 Q2recession trough and forecasts negatively biased growth for a decade (RMSE = 0.996). - Why MAPE explodes: Quarterly percentage changes frequently pass near zero (here
min(|actual|) = 0.072), blowing up relative percentage errors (MAPE > 100%) even for accurate models. Prefer RMSE and MAE on growth-rate series.
Practice Exercises
Exercise 1: Bilateral Granger Causality in Weekly Energy Returns
Construct weekly log percentage returns oil_ret and gas_ret from astsa::oil and astsa::gas. Test both directions (oil_ret -> gas_ret and gas_ret -> oil_ret) at lag \(p = 3\) using lmtest::grangertest(). Is Granger causality unidirectional or bidirectional?
Solution
Both directions reject the null hypothesis strongly at the 1% level (oil_ret -> gas_ret: \(F = 4.56, p = 0.0037\); gas_ret -> oil_ret: \(F = 6.36, p = 0.0003\)), demonstrating bidirectional Granger causality in weekly energy markets (reflecting both upstream crude pass-through and retail demand feedback).
og <- tibble(
oil_ret = 100 * diff(log(as.numeric(astsa::oil))),
gas_ret = 100 * diff(log(as.numeric(astsa::gas)))
)
g_o2g <- lmtest::grangertest(gas_ret ~ oil_ret, order = 3, data = og)
g_g2o <- lmtest::grangertest(oil_ret ~ gas_ret, order = 3, data = og)
tibble(
Direction = c("oil_ret -> gas_ret (p = 3)", "gas_ret -> oil_ret (p = 3)"),
F_stat = c(g_o2g$F[2], g_g2o$F[2]),
p_value = c(g_o2g$`Pr(>F)`[2], g_g2o$`Pr(>F)`[2])
) |>
fmt_tbl(digits = 5, caption = "Bilateral Granger causality tests on weekly oil and gasoline returns")| Direction | F_stat | p_value |
|---|---|---|
| oil_ret -> gas_ret (p = 3) | 4.557 | 0.00365 |
| gas_ret -> oil_ret (p = 3) | 6.360 | 0.00031 |
Exercise 2: Multivariate vs. Univariate Forecasting of us_change$Income
Using the same 80/20 split (uc_tr, uc_te) and fitted v2_tr and v3_tr models from Section 3, compare univariate ARIMA(Income) against VAR(2) Bivariate and VAR(2) Trivariate for out-of-sample Income RMSE and MAE.
Solution
Consistent with the strong predictive link from consumption to income, both VAR(2) models outperform univariate ARIMA out of sample, with VAR(2) Trivariate achieving the lowest RMSE (0.976 vs. 1.011) and MAE (0.548 vs. 0.579).
fc_inc_a <- uc_tr |>
model(ARIMA = ARIMA(Income)) |>
forecast(h = h_te) |>
as_tibble() |>
select(.model, Quarter, pred = .mean)
fc_inc_v2 <- tibble(.model = "VAR(2) Bivariate", Quarter = uc_te$Quarter,
pred = predict(v2_tr, n.ahead = h_te)$fcst$Income[, "fcst"])
fc_inc_v3 <- tibble(.model = "VAR(2) Trivariate", Quarter = uc_te$Quarter,
pred = predict(v3_tr, n.ahead = h_te)$fcst$Income[, "fcst"])
bind_rows(fc_inc_a, fc_inc_v2, fc_inc_v3) |>
left_join(uc_te |> as_tibble() |> select(Quarter, actual = Income), by = "Quarter") |>
group_by(.model) |>
summarise(RMSE = sqrt(mean((actual - pred)^2)), MAE = mean(abs(actual - pred))) |>
arrange(RMSE) |>
fmt_tbl(digits = 3, caption = "Out-of-sample Income forecast benchmark (h = 40 quarters)")| .model | RMSE | MAE |
|---|---|---|
| VAR(2) Trivariate | 0.976 | 0.548 |
| VAR(2) Bivariate | 0.985 | 0.554 |
| ARIMA | 1.013 | 0.579 |
Key Takeaways
- Granger causality tests incremental linear predictability from lagged \(X\) to \(Y\) on an identical matched sample \(T_{\text{eff}} = T - p\); it never proves structural causation.
- In a \(K \ge 3\) VAR,
vars::causality(..., cause = "X")tests joint block exogeneity against all \(K - 1\) other variables simultaneously (df1 = p(K - 1)), not a single pairwise link. - Fair multivariate forecast evaluation must be strictly zero-leakage: forecast all system variables recursively rather than supplying actual future covariates to the test window.
- Avoid MAPE on stationary growth-rate series that cross near zero; compare RMSE and MAE instead.