Repository navigation
Conversation
4 of 5 tasks
bashtage
force-pushed
the
wip-msar-switching-variance
branch
from
November 24, 2026 16:15
7b87a24 to
ff40e26
Compare
With switching_variance=True and order >= 2, MarkovAutoregression used the error variance of the regime order - 1 periods earlier instead of that of the current regime: the variance was reshaped to (k_regimes, 1, 1), which broadcasts against the third axis from the end of the (k_regimes,) * (order + 1) + (nobs,) residuals. The log-likelihood, the estimates and the regime probabilities of such models were wrong, with no error or warning. Order 1, the default switching_variance=False and MarkovRegression were not affected. The variance is now reshaped to (k_regimes,) + (1,) * (order + 1), so it varies along the current-regime axis for every order. Results of models with switching_variance=True and order >= 2 change. Tests: the log-likelihood with switching variances of orders 1 to 3 against the Hamilton filter written out over the joint state, and an AR(2) with a zero second lag against the AR(1) on endog[1:] (log- likelihood contributions and smoothed probabilities), with and without a switching constant and switching variances.
bashtage
force-pushed
the
wip-msar-switching-variance
branch
from
November 28, 2026 21:36
ff40e26 to
9f1dcfd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With switching_variance=True and order >= 2, MarkovAutoregression used
the error variance of the regime order - 1 periods earlier instead of
that of the current regime: the variance was reshaped to
(k_regimes, 1, 1), which broadcasts against the third axis from the end
of the (k_regimes,) * (order + 1) + (nobs,) residuals. The
log-likelihood, the estimates and the regime probabilities of such
models were wrong, with no error or warning. Order 1, the default
switching_variance=False and MarkovRegression were not affected.
The variance is now reshaped to (k_regimes,) + (1,) * (order + 1), so
it varies along the current-regime axis for every order. Results of
models with switching_variance=True and order >= 2 change.
Tests: the log-likelihood with switching variances of orders 1 to 3
against the Hamilton filter written out over the joint state, and an
AR(2) with a zero second lag against the AR(1) on endog[1:] (log-
likelihood contributions and smoothed probabilities), with and without
a switching constant and switching variances.
NumPy's guide.
AI Disclosure
Contributions must comply with the statsmodels AI Policy.
Tick exactly one of the following. If AI tools were used, replace the
<...>placeholders in the second option with the tool name(s) and how the tool's output was
used.
Tool(s): Claude Code (Claude Opus 5.5).
Used for: finding the bug in a contract audit, writing the fix and its tests, and checking them (tests failing on main, mutation check).
I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.
🤖 Generated with Claude Code