MarkovSwitchingAR.fit#

MarkovSwitchingAR.fit(*, max_iter=500, tol=1e-6, n_init=10, screen_iter=15, seed=None)[source]#

Estimate by EM with multi-start screening.

Unlike the other families, this fit takes arguments, because the likelihood is multimodal and the answer genuinely depends on where the search starts. The default is to screen n_init starts for screen_iter iterations each, then refine only the best; pass a seed when you need the fit to be reproducible. The first start is deterministic – intercepts at the within-regime quantiles of the series with a 0.9 diagonal – and the rest draw intercepts from the sample and a diagonal in (0.8, 0.95), so n_init=1 is the same fit for every seed.

Parameters:
  • max_iter (int) – Iteration cap for the refining run.

  • tol (float) – Convergence tolerance on the log-likelihood increment.

  • n_init (int) – Random starts to screen.

  • screen_iter (int) – Iterations used to score each screening start.

  • seed (int | Generator | None) – Seed or generator for the random starts.

Return type:

MarkovSwitchingARResult

Returns:

The fitted MarkovSwitchingARResult, regimes ordered by the convention MarkovSwitchingARResult.label_ordering names.

Raises:

NumericalError – If every start fails to produce a finite likelihood.

Example

Two seeds reach the same optimum on well-separated regimes:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> s = (np.arange(600) // 100) % 2
>>> y = np.where(s == 1, 2.0, -2.0) + 0.5 * rng.standard_normal(600)
>>> model = MarkovSwitchingAR(y, order=1)
>>> a, b = model.fit(seed=0, n_init=3), model.fit(seed=7, n_init=3)
>>> bool(abs(a.llf - b.llf) < 1e-4), a.converged and b.converged
(True, True)