MarkovSwitchingARResult.state_space#
- property MarkovSwitchingARResult.state_space: _MarkovSwitchingStateSpace[source]#
The fitted system, re-applicable to data it was not estimated on.
Filtering a new series through this reports what the estimated regimes say about observations the fit never saw – the natural out-of-sample check for a regime model, and one the fitted arrays alone cannot give.
Example
The fitted chain dates a fresh draw from the same process:
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> p = np.array([[0.97, 0.03], [0.05, 0.95]]) >>> def draw(n): ... s = np.zeros(n, dtype=int) ... for t in range(1, n): ... s[t] = np.searchsorted(np.cumsum(p[s[t - 1]]), rng.random()) ... return s, np.array([-1.0, 1.5])[s] + 0.5 * rng.standard_normal(n) >>> _, y = draw(1500) >>> res = MarkovSwitchingAR(y, order=1, n_regimes=2).fit(seed=0) >>> abs(res.state_space.loglikelihood(y) - res.llf) < 1e-8 True >>> s_new, y_new = draw(300) >>> dated = res.state_space.filter(y_new).filtered_prob.argmax(axis=1) >>> bool(np.mean(dated == s_new[1:]) > 0.95) True