View source: R/markov-switching.R
| ms_filter | R Documentation |
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.
ms_filter(
y,
G,
H,
M,
D,
regime_scale,
P_trans,
initial_probs = NULL,
smooth = TRUE
)
y |
Matrix of observed data (T x n_obs). |
G, H, M, D |
Solution matrices from |
regime_scale |
Volatility multipliers applied to the shock
loading |
P_trans |
|
initial_probs |
Optional length- |
smooth |
Logical. Also compute Kim-smoothed regime
probabilities using the full sample. Default |
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.
An object of class "dsge_ms_filter" with elements:
loglikLog-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, ergodicInputs and the implied ergodic distribution.
kalman_filter_skewed for non-Gaussian shocks.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.