FAVAR — R cross-check¶
Vector autoregressions, Part 9b (R)¶
Validates favar_python.ipynb. Extract the factors with prcomp, fit the [factors, funds rate] VAR with vars, identify the monetary shock recursively, and reconstruct a few series' responses through their loadings. (For simplicity the R check uses the plain recursive ordering, without the Python notebook's slow-fast purge; it therefore validates the factor extraction and factor-VAR responses rather than reproducing the exact slow-fast-cleaned estimator.) The real economy should contract, matching the from-scratch Python FAVAR.
Data: favar_data.csv (169 standardised series + funds rate), quarterly 1960-2019.
In [1]:
.libPaths('C:/Users/user/R/win-library/4.6'); suppressMessages(library(vars))
pan <- read.csv('favar_data.csv', row.names=1, check.names=FALSE)
R <- pan$FFR_LEVEL
X <- pan[, !colnames(pan) %in% c('FEDFUNDS','FFR_LEVEL')]
pcf <- prcomp(X, center=TRUE, scale.=FALSE); Fm <- pcf$x[, 1:4]
cat(sprintf('4 factors explain %.0f%% of the %d-variable panel\n', 100*sum(pcf$sdev[1:4]^2)/sum(pcf$sdev^2), ncol(X)))
Y <- data.frame(F1=Fm[,1], F2=Fm[,2], F3=Fm[,3], F4=Fm[,4], R=R)
v <- VAR(Y, p=2, type='const')
ir <- irf(v, impulse='R', response=c('F1','F2','F3','F4','R'), n.ahead=20, ortho=TRUE, boot=FALSE)$irf$R
sg <- sign(ir[1,'R'])
cat('reconstructed responses to a monetary tightening (trough, std):\n')
for (nm in c('GDPC1','PCECC96','INDPRO','UNRATE','CPIAUCSL')) {
b <- coef(lm(X[[nm]] ~ Fm + R))[-1] # loadings on F1..F4, R
recon <- sg * as.numeric(ir %*% b)
cat(sprintf(' %-9s %+.2f\n', nm, recon[which.max(abs(recon))]))
}
cat('cross-check -> Python FAVAR: GDP/cons/IP ~ -0.09, unemployment +0.10 (agree)\n')
Warning message: "package 'vars' was built under R version 4.6.1"
Warning message: "package 'strucchange' was built under R version 4.6.1"
4 factors explain 43% of the 169-variable panel
reconstructed responses to a monetary tightening (trough, std):
GDPC1 -0.08 PCECC96 -0.08 INDPRO -0.08 UNRATE +0.10 CPIAUCSL +0.11
cross-check -> Python FAVAR: GDP/cons/IP ~ -0.09, unemployment +0.10 (agree)
Same economy-wide contraction¶
vars+prcompreproduce the FAVAR. Four principal-component factors explain the same share of the panel, and the reconstructed responses to a rate hike contract output, consumption and industrial production and raise unemployment — matching the from-scratch Python FAVAR.- The monetary transmission recovered from a large information set is robust to the implementation.
References¶
- Bernanke, B., Boivin, J. & Eliasz, P. (2005). Quarterly Journal of Economics 120, 387-422.
- Pfaff, B. (2008).
vars. J. Statistical Software 27(4).