MarkovSwitchingARResult.simulate_regimes#
- MarkovSwitchingARResult.simulate_regimes(n=200, *, seed=None, burn=_SIMULATION_BURN)[source]#
A fresh sample path together with the regimes that generated it.
- Parameters:
- Return type:
- Returns:
(y, regimes)of shapes(n,)and(n,), the regime labels0 .. K - 1in the order ofintercepts.- Raises:
SpecificationError – If the counts are not usable.
Example
The simulated chain spends time in each regime at its ergodic frequency:
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> p = np.array([[0.97, 0.03], [0.05, 0.95]]) >>> s = np.zeros(1500, dtype=int) >>> for t in range(1, 1500): ... s[t] = np.searchsorted(np.cumsum(p[s[t - 1]]), rng.random()) >>> y = np.array([-1.0, 1.5])[s] + 0.5 * rng.standard_normal(1500) >>> res = MarkovSwitchingAR(y, order=1, n_regimes=2).fit(seed=0) >>> path, regimes = res.simulate_regimes(5000, seed=1) >>> shares = np.bincount(regimes, minlength=2) / 5000 >>> bool(np.allclose(shares, res.ergodic_prob, atol=0.05)) True