ms_filter: Markov-Switching Volatility Filter (Kim 1994)

View source: R/markov-switching.R

ms_filterR Documentation

Markov-Switching Volatility Filter (Kim 1994)

Description

Evaluates the log-likelihood of a linear DSGE model whose structural shock volatilities switch between a small number of regimes governed by a first-order Markov chain, and returns filtered and smoothed regime probabilities.

Usage

ms_filter(
  y,
  G,
  H,
  M,
  D,
  regime_scale,
  P_trans,
  initial_probs = NULL,
  smooth = TRUE
)

Arguments

y

Matrix of observed data (T x n_obs).

G, H, M, D

Solution matrices from solve_dsge. At first order these are regime-invariant, so a single solve suffices.

regime_scale

Volatility multipliers applied to the shock loading M in each regime. Either a length-K numeric vector (the same multiplier for every shock) or a K \times n_{shocks} matrix (a separate multiplier per shock). Regime 1 is conventionally the low-volatility regime, but no ordering is imposed.

P_trans

K \times K Markov transition matrix, where P_trans[i, j] is the probability of moving from regime i to regime j. Rows must sum to one.

initial_probs

Optional length-K vector of initial regime probabilities. Defaults to the ergodic distribution implied by P_trans.

smooth

Logical. Also compute Kim-smoothed regime probabilities using the full sample. Default TRUE.

Details

Why the solution does not switch

A first-order perturbation solution is certainty-equivalent: the decision rules depend on the model's structural parameters but not on the variances of the shocks. Switching volatility therefore leaves G and H unchanged and rescales only the shock loading, which is what makes this specification exactly (rather than approximately) solvable. Switching structural parameters is a different and much harder problem, because agents' expectations must then account for the possibility of future regime changes.

Value

An object of class "dsge_ms_filter" with elements:

loglik

Log-likelihood of the data.

filtered_probs

(T x K) matrix of P(s_t = j \mid y_{1:t}).

predicted_probs

(T x K) matrix of P(s_t = j \mid y_{1:t-1}).

smoothed_probs

(T x K) matrix of P(s_t = j \mid y_{1:T}), or NULL when smooth = FALSE.

filtered_states

(T x n_states) regime-averaged filtered state means.

regime_scale, P_trans, ergodic

Inputs and the implied ergodic distribution.

See Also

kalman_filter_skewed for non-Gaussian shocks.

Examples

m <- dsge_model(
  obs(y ~ z),
  state(z ~ rho * z),
  fixed = list(rho = 0.7))
sol <- solve_dsge(m, params = c(rho = 0.7), shock_sd = c(z = 1))
set.seed(1)
dat <- matrix(rnorm(150), 150, 1, dimnames = list(NULL, "y"))
P <- matrix(c(0.95, 0.05, 0.10, 0.90), 2, 2, byrow = TRUE)
out <- ms_filter(dat, sol$G, sol$H, sol$M, sol$D,
                 regime_scale = c(1, 3), P_trans = P)
out$loglik
head(out$filtered_probs)


dsge documentation built on Sept. 25, 2026, 5:08 p.m.