1.6. Switching VARs with known regimes

A regime-switching reduced-form VAR whose transition probabilities are exactly 0 or 1, given the data and the calibrated parameters, has a known regime at every scored date. A threshold VAR with a calibrated cutoff is the typical case. Under a conjugate VAR prior (minnesota, inw, niw, generate_sims_zha_prior) estimate then finds the posterior mode without a numerical search. Under niw, or Sims-Zha with its prior on the covariance, it also reports the exact log marginal data density given the regimes, in posterior_maximization.log_marginal_data_density_closed_form (see Closed-form marginal data density of VARs).

There is no new option: estim_var_closed_form (true by default) covers this case, and false asks for the numerical search.

1.6.1. Writing the chain

The regime of a quarter is known when the transition probabilities are an indicator of observed variables and calibrated parameters. With inflation pinfobs and a cutoff thr:

chain = struct('name', 'sc', 'number_of_states', 2, ...
    'controlled_parameters', {{'b', 'c', 'covar'}}, ...
    'endogenous_probabilities', {{'sc_tp_1_2=hard_threshold(pinfobs,thr,0)', ...
                                  'sc_tp_2_1=1-hard_threshold(pinfobs,thr,0)'}}, ...
    'probability_parameters', {{'thr'}});

m = rfvar_model({'pinfobs','robs'}, lag_length = 1, constant_term = true, ...
                markov_chains = chain);

m = set(m, 'parameters', struct('thr', 1));
  • The third argument of hard_threshold is its floor. The default, \(10^{-10}\), keeps both regimes possible at every date: the regimes are then a mixture, the model is filtered and its mode is searched numerically. threshold_chains writes that default form. Write the chain by hand, with a zero floor, for the closed form.

  • The transition matrix built at \(t\) governs the regime at \(t+1\): here the regime of a quarter is 2 when the inflation of the quarter before is above thr, and 1 when it is at or below it.

  • thr has no prior: it is calibrated, not estimated.

1.6.2. When the regimes are known

RISE reads the compiled transition probabilities and qualifies the model when

  • they read no estimated parameter, and no steady-state or derived constant;

  • propagating every possible initial regime through them leaves one possible regime at each scored date. No probability is rounded: a floor, a smooth transition (logistic) or an estimated cutoff leaves the path uncertain;

  • the conditions of the constant-parameter route hold (a conjugate template, no prior in estim_priors, no endogenous prior, complete data, and the others listed under How the mode is found in Reduced-form VAR Modeling).

Otherwise estimate searches numerically and prints the reason, for example:

Posterior mode by numerical search (no closed form: the regime path is uncertain from the observed transition history).

and transition probabilities depend on estimated parameters for a cutoff that is estimated. A latent chain (constant transition probabilities, estimated) goes to the search without a message.

1.6.3. The posterior mode

The coefficients and the covariances of the regimes take their exact conditional modes in turn, normal given the covariances and inverse-Wishart given the coefficients, with the prior counting each value once (see Priors under regime switching in Reduced-form VAR Modeling). The passes stop at a stationary point of the posterior, a scaled score of at most \(10^{-6}\). estimate prints, for example:

Posterior mode in closed form (4 passes, 1.42 seconds): log posterior 5.4148

Shared parameters and linear restrictions keep their free coordinates. A regime without observations keeps the mode of its prior when the prior is proper. The mode is searched numerically instead, with the reason, when

  • the covariance switches in part, or has restrictions (partial covariance switching or covariance restrictions have no inverse-Wishart conditional);

  • under niw or Sims-Zha, coefficients are shared by regimes whose covariances differ (the conditional of coefficients is not an exact normal or inverse-Wishart);

  • the posterior kernel rejects a conditional mode, for example a VAR that is not stable under solve_check_stability (the kernel rejects a conditional mode (return code 25)).

This route has no analytic Hessian. With estim_hessian_type = 'fd', the default, estimate computes it by finite differences (14.8 seconds in the run behind this page, for the 18 parameters of the example below, against 1.42 seconds for the mode), and hessian(mdlest) does the same afterwards. 'none' skips it and keeps the closed-form marginal data density; only the Laplace approximation needs the Hessian. The same conditionals give sample_posterior its exact blocks.

1.6.4. The marginal data density given the regimes

The regimes that share a covariance form one regression, on their dates. When the coefficients switch among them, the regressors are interacted with the regime, and the coefficients of each regime take the prior of the template; a coefficient that does not switch enters once, and the switching ones by their density conditional on it. The log marginal data density is the sum, over the distinct covariances, of the closed form of their regression. A regime without observations adds 0.

With the mode in closed form, the value is reported when all these conditions hold, and is NaN with the reason of the first that fails otherwise:

Condition

Reason when it fails

a Kronecker coefficient prior (niw, Sims-Zha)

no closed-form marginal likelihood: a proper matrix-normal/IW integral is required; the coefficient prior is independent of the covariance

an inverse-Wishart prior on the covariance

no marginal likelihood: the prior has no proper density on the covariance

no linear restriction that fixes a coefficient or a covariance entry

no closed-form marginal likelihood: linear restrictions or fixed values among the coefficients or the covariance

no linear restriction that ties different elements (a restriction that equates the same element in two regimes only shares it, and is allowed)

no closed-form marginal likelihood: linear restrictions tie different coefficients or covariance entries

the covariance switches whole or not at all

no closed-form marginal likelihood: the covariance switches in part

a regressor switches in all the equations or in none

no closed-form marginal likelihood: a regressor switches in some equations only

no coefficient shared by regimes whose covariances differ

no closed-form marginal likelihood: coefficients are shared by regimes whose covariances differ

The mode is checked first: a covariance that switches in part and, under niw and Sims-Zha, coefficients shared by regimes whose covariances differ already send the mode to the numerical search (see above), and the field is then empty. The closed-form marginals of the VAR prior, which normalize a combined prior (see Combined priors in Reduced-form VAR Modeling), are a property of the prior alone: they do not make this integral available.

The value is \(\log p(Y \mid \text{regimes})\): it conditions on the regime path, so for a threshold VAR on the cutoff. It neither integrates the cutoff nor counts a prior on it; VAR threshold profiles scores many cutoffs at once. Under the stability check or finite parameter bounds the value carries the label described in Closed-form marginal data density of VARs.

1.6.5. An example

The chain above on the VAR(1) in quarterly inflation and the federal funds rate (Smets and Wouters (2007) data in RISE’s examples/VariousModels/SmetsWouters, both in percent per quarter), estimated from 1966Q1 to 2004Q4 under niw with its default hyperparameters, thr = 1 (about 4 percent a year), solve_check_stability = false and estim_prior_trunc = 0. Of the 155 scored quarters (1966Q2-2004Q4), 90 are in regime 1 and 65 in regime 2. estimate takes 2 function evaluations.

Quantity (nats)

Value

closed form, everything switching ({'b','c','covar'})

-46.066061

Laplace approximation, same model

-46.742553

regression on the 90 quarters of regime 1

30.307075

regression on the 65 quarters of regime 2

-76.373137

constant-parameter VAR(1), same quarters

-71.334613

closed form, coefficients switching, covariance common ({'b','c'})

-81.969969

The two regressions add up to the switching model’s value, and the log Bayes factor of the threshold VAR at thr = 1 against the constant VAR is 25.2686. With a common covariance the value equals that of one regression on the regressors interacted with the regime. The standard deviation of the inflation residual at the mode is 0.235 percent per quarter in regime 1 and 0.344 in regime 2. Under inw the mode is still found in 2 function evaluations, and the marginal data density is NaN with the first reason in the table.

The tutorial Estimation/var_known_regimes/howto.m runs this example.

1.6.6. The routines

rise.engine.var.vartools.bvar_conjugate_problem hands a model with more than one regime to rise.engine.var.vartools.bvar_known_regime_problem. Its P.mode() alternates the conditional modes, P.log_marginal_likelihood() returns [lml, why], and P.at(calibration) is the same problem at other calibrated values, the model evaluated once and the path read again, which VAR threshold profiles uses. rise.engine.var.vartools.bvar_posterior_mode returns the mode with the path in known_regimes.