Skip to content

BUG: Select periods, not regimes, in conditional Markov switching predict - #10995

Draft
bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-ms-predict-conditional-slice
Draft

bashtage wants to merge 2 commits into
statsmodels:mainfrom
bashtage:wip-ms-predict-conditional-slice

Conversation

@bashtage

Copy link
Copy Markdown
Member

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.

  • 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.

  • No AI tools were used to develop this pull request.
  • AI tools were 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

@bashtage

bashtage commented Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

Merge order. These open PRs build on this one (their branches contain its commits), so please merge this PR first:

Indented PRs build on the PR above them, so merge them after it.

Once this PR is merged, their diffs shrink to their own changes. Each of them also says "Stacked on #..." at the top of its description.

Merge-order note generated with Claude Code (updated 2026-11-25).

@bashtage
bashtage force-pushed the wip-ms-predict-conditional-slice branch 2 times, most recently from 620ecb9 to f66b772 Compare November 25, 2026 12:11
@bashtage
bashtage force-pushed the wip-ms-predict-conditional-slice branch 3 times, most recently from b8bf401 to 8d3bc95 Compare November 27, 2026 23:06
…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.
@bashtage
bashtage force-pushed the wip-ms-predict-conditional-slice branch from 8d3bc95 to b0e1e62 Compare November 28, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant