MarkovSwitchingVARResult._from_fit#
- classmethod MarkovSwitchingVARResult._from_fit(fit, model)[source]#
Assemble the public result, building one stable view per regime.
Each regime view carries the regime’s own conditional-mean residuals rescaled by the square root of its smoothed weight (normalized to the sample size), so that the view’s
resid.T @ resid / nobsis the regime’s probability-weighted residual covariance.- Parameters:
fit (
_VectorMarkovSwitchingFit) – The EM output: transition matrix, per-regime coefficient blocks and covariances, the three posteriors, the mixture fitted values and residuals.model (
_MarkovSwitchingVectorAutoRegressionModel[MarkovSwitchingVARResult]) – The model that produced it, read for the sample, the specification and the ordering convention.
- Return type:
- Returns:
A populated result whose
regimesare identity-stable.
Example
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> s = np.repeat([0, 1, 0, 1], 100) >>> y = np.array([[-1.0, -0.5], [1.5, 1.0]])[s] + 0.4 * rng.standard_normal((400, 2)) >>> model = MarkovSwitchingVAR(y, order=1, n_regimes=2) >>> fit = model._fit_markov(max_iter=500, tol=1e-6, n_init=10, screen_iter=15, seed=0) >>> res = MarkovSwitchingVARResult._from_fit(fit, model) >>> view = res.regimes[0] >>> weighted = view.resid.T @ view.resid / res.nobs >>> round(view.nobs), bool(np.allclose(weighted, view.sigma_u, atol=1e-6)) (199, True)