Repository navigation
Conversation
4 of 5 tasks
bashtage
force-pushed
the
wip-ms-predict-nobs-one
branch
2 times, most recently
from
November 25, 2026 12:14
41ac6ab to
e09b574
Compare
4 of 5 tasks
bashtage
force-pushed
the
wip-ms-predict-nobs-one
branch
3 times, most recently
from
November 27, 2026 23:06
b78aa2f to
0f6f0df
Compare
…dict
MarkovSwitching.predict (and MarkovSwitchingResults.predict) with
conditional=True or an int and with start or end applied the
[start:end + 1] selection to the first axis of the conditional
predictions, which indexes the regime. The result had every period and
the wrong regimes, or no regimes at all when start was at least
k_regimes, with no error. For example, predict(params, start=10,
end=20, conditional=True) of a two-regime MarkovRegression returned an
array of shape (0, nobs).
The selection now applies to the last axis, the periods. Unconditional
predictions, which are one-dimensional, and conditional predictions of
the full sample do not change; conditional predictions with start or
end change.
Tests: conditional predictions of MarkovRegression against the regime
means, and of an AR(1) MarkovAutoregression given the current and last
regime against mu_i + phi_i (y_{t-1} - mu_j), for several start/end
pairs and for date keys; unconditional and current-regime predictions
with start/end against the same periods of the full-sample predictions.
…rvation MarkovSwitching.predict squeezed the predictions conditional on the regimes, shaped (k_regimes,) * n + (nobs,), to drop the length-one axis of the previous regime that MarkovRegression predictions carry. With a single observation (nobs 1) np.squeeze also dropped the time axis, so the last regime axis was taken for the time axis: the check whether to average over the regimes compared one axis too few, and the selection of the periods kept the first regime of that axis only. For MarkovRegression, predict() (also with conditional False), fittedvalues and resid were the prediction of the first regime instead of the weighted average; conditional=True returned one value instead of one per regime. For MarkovAutoregression, conditional=order returned the predictions given the first regime in the earliest period instead of their average over that regime, and larger conditional values lost that regime axis. Only the regime axes of length one are dropped now, never the time axis. Stacked on the PR that selects periods along the time axis of conditional predictions (wip-ms-predict-conditional-slice): without it, the period selection applies to the regime axis and the conditional predictions with one observation are still wrong. Changes - MarkovSwitching.predict and MarkovSwitchingResults.predict (and so fittedvalues and resid) with nobs 1 give the results of the same computation as with more observations. - A paragraph in the versionchanged notes under conditional in both predict docstrings. Not changed - Models with more than one observation: the time axis was never squeezed. - MarkovAutoregression with conditional False, which averaged over every regime axis already. Tests - MarkovRegression with one observation: the unconditional prediction, fittedvalues and resid equal the regime means averaged with the smoothed probabilities written out by hand (ergodic probabilities times the normal densities), and conditional True, 1 and 2 give one prediction per regime, the regime means, through the model and the results. - MarkovAutoregression of order 1 with one observation: conditional 2 and 3 give mu_i + phi_i (y_0 - mu_j) for each pair of regimes, and the unconditional prediction (a control that passes before) their average with the joint probabilities written out by hand. - The new tests fail on the base (6 of 7; the control passes), and every changed line is guarded (5 mutants, all killed).
bashtage
force-pushed
the
wip-ms-predict-nobs-one
branch
from
November 28, 2026 21:36
0f6f0df to
f8e0e13
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.
Stacked on #10995, merge that first (this PR adds one commit): without it the period selection applies to the regime axis, so conditional predictions with one observation stay wrong. The stack was rebuilt on 2026-11-25 so that it merges without conflicts in this order; notes about conflicts with PRs of the same stack no longer apply. #11012 conflicts with this PR only in the two
versionchangedblocks underconditional(as it does with #10995): keep one directive with all three paragraphs. With #11012 merged too, theMarkovAutoregressionpredictions withconditional1 toorderand one observation are the expected values given those regimes (checked on a trial merge). Other open PRs append tests at the end of the same test file: keep both appended blocks.BUG: Select periods, not regimes, in conditional Markov switching predict
MarkovSwitching.predict (and MarkovSwitchingResults.predict) with
conditional=True or an int and with start or end applied the
[start:end + 1] selection to the first axis of the conditional
predictions, which indexes the regime. The result had every period and
the wrong regimes, or no regimes at all when start was at least
k_regimes, with no error. For example, predict(params, start=10,
end=20, conditional=True) of a two-regime MarkovRegression returned an
array of shape (0, nobs).
The selection now applies to the last axis, the periods. Unconditional
predictions, which are one-dimensional, and conditional predictions of
the full sample do not change; conditional predictions with start or
end change.
Tests: conditional predictions of MarkovRegression against the regime
means, and of an AR(1) MarkovAutoregression given the current and last
regime against mu_i + phi_i (y_{t-1} - mu_j), for several start/end
pairs and for date keys; unconditional and current-regime predictions
with start/end against the same periods of the full-sample predictions.
BUG: Keep the time axis of Markov switching predictions with one observation
MarkovSwitching.predict squeezed the predictions conditional on the
regimes, shaped (k_regimes,) * n + (nobs,), to drop the length-one axis of
the previous regime that MarkovRegression predictions carry. With a single
observation (nobs 1) np.squeeze also dropped the time axis, so the last
regime axis was taken for the time axis: the check whether to average over
the regimes compared one axis too few, and the selection of the periods
kept the first regime of that axis only. For MarkovRegression, predict()
(also with conditional False), fittedvalues and resid were the prediction
of the first regime instead of the weighted average; conditional=True
returned one value instead of one per regime. For MarkovAutoregression,
conditional=order returned the predictions given the first regime in the
earliest period instead of their average over that regime, and larger
conditional values lost that regime axis.
Only the regime axes of length one are dropped now, never the time axis.
Stacked on the PR that selects periods along the time axis of conditional
predictions (wip-ms-predict-conditional-slice): without it, the period
selection applies to the regime axis and the conditional predictions with
one observation are still wrong.
Changes
fittedvalues and resid) with nobs 1 give the results of the same
computation as with more observations.
predict docstrings.
Not changed
squeezed.
regime axis already.
Tests
MarkovRegression with one observation: the unconditional prediction,
fittedvalues and resid equal the regime means averaged with the
smoothed probabilities written out by hand (ergodic probabilities times
the normal densities), and conditional True, 1 and 2 give one prediction
per regime, the regime means, through the model and the results.
MarkovAutoregression of order 1 with one observation: conditional 2 and
3 give mu_i + phi_i (y_0 - mu_j) for each pair of regimes, and the
unconditional prediction (a control that passes before) their average
with the joint probabilities written out by hand.
The new tests fail on the base (6 of 7; the control passes), and every
changed line is guarded (5 mutants, all killed).
tests added / passed.
code/documentation is well formatted.
properly formatted commit message. See
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 coverage audit of statsmodels.tsa, writing the fix and its tests, and checking them (tests failing on the base, 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