Markov-switching VAR — R cross-check¶

Vector autoregressions, Part 11 (R)¶

Validates msvar_python.ipynb. MSwM (Sanchez-Espigares & Lopez-Moreno) fits a Markov-switching regression by EM. We fit a two-regime Markov-switching AR(2) to GDP growth with a switching intercept and variance, and check that the smoothed probability of its high-volatility regime reproduces the from-scratch Bayesian MS-VAR's chronology - concentrated before 1984.

Data: bvar_sv_data.csv - GDP growth, quarterly 1959-2019 (FRED-QD).

In [1]:
.libPaths('C:/Users/user/R/win-library/4.6'); suppressMessages(library(MSwM))
d <- read.csv('bvar_sv_data.csv'); dt <- as.Date(d$date); y <- d$gdp_growth
n <- length(y); df <- data.frame(y=y[3:n], y1=y[2:(n-1)], y2=y[1:(n-2)]); td <- dt[3:n]
set.seed(1)
ms <- msmFit(lm(y ~ y1 + y2, data=df), k=2, sw=c(TRUE, FALSE, FALSE, TRUE), p=0)   # switch intercept + variance
sig <- ms@std; turb <- which.max(sig)                                              # high-volatility regime
pturb <- ms@Fit@smoProb[, turb]; if (length(pturb) == nrow(df) + 1) pturb <- pturb[-1]
cat(sprintf('MSwM regime std devs: %.1f (calm) / %.1f (turbulent)\n', min(sig), max(sig)))
cat(sprintf('P(turbulent) pre-1984 %.2f  post-1984 %.2f\n',
            mean(pturb[td <  as.Date('1984-01-01')]), mean(pturb[td >= as.Date('1984-01-01')])))
cat('cross-check -> Python MS-VAR: pre-1984 0.40, post-1984 0.03  (same chronology; the single-series EM concentrates the regime more strongly than the joint MS-VAR)\n')
options(repr.plot.width=13, repr.plot.height=4)
plot(td, pturb, type='h', col='firebrick', xlab='', ylab='P(turbulent | data)',
     main='MSwM: smoothed probability of the high-volatility regime (GDP growth)')
abline(v=as.Date('1984-01-01'), col='navy', lty=2)
MSwM regime std devs: 1.8 (calm) / 4.1 (turbulent)
P(turbulent) pre-1984 0.99  post-1984 0.06
cross-check -> Python MS-VAR: pre-1984 0.40, post-1984 0.03  (same chronology; the single-series EM concentrates the regime more strongly than the joint MS-VAR)
No description has been provided for this image

Same regime chronology¶

  • MSwM agrees. A Markov-switching AR on GDP growth alone puts its high-volatility regime overwhelmingly before 1984 - the same Great-Moderation break the multivariate Bayesian MS-VAR discovered, reached here by EM on a single series.
  • The regime-inference machinery (Hamilton filter + smoothing) reproduces across a from-scratch Bayesian sampler and a maximum-likelihood package.

References¶

  • Hamilton, J. D. (1989). Econometrica 57, 357-384.
  • Sanchez-Espigares, J. A. & Lopez-Moreno, A. (2021). MSwM: fitting Markov switching models. R package.