Repository navigation
Conversation
4 of 5 tasks
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). |
4 of 5 tasks
bashtage
force-pushed
the
wip-mlemodel-unreachable
branch
from
November 24, 2026 16:16
ba0cdfd to
cedd370
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 24, 2026
The summary of state space results (MLEResults) warns that the covariance matrix is singular when the results' _rank is below the number of free parameters. With cov_type="robust_approx" (and "robust"/"robust_oim"), _rank was the rank of the outer product of gradients (OPG) matrix: the robust matrix, inv(H inv(OPG) H), computes the OPG matrix first, which sets the rank, so the robust matrix's own rank update could never run (statsmodels#11063 removes it as unreachable). The robust matrix has the rank of H, which can be lower. For white noise with a regressor, at the OLS coefficient and twice the mean squared residual as variance, the Hessian of the loglikelihood is diag(-sum(x**2) / s2, 0) (rank 1) and the OPG matrix has rank 2; the robust_approx matrix has rank 1, but the summary did not warn. This is the same change as statsmodels#11068 for the Markov switching models. Changes - _cov_params_robust_oim and _cov_params_robust_approx set _rank to the rank of the robust matrix when no rank is set yet, that is when it is the covariance matrix of the results, as the approx, oim and opg matrices do for theirs. Results with another cov_type keep the rank of their own matrix when a robust matrix is computed later. - versionchanged in the cov_params_robust_oim and cov_params_robust_approx docstrings. The summary of robust_approx results can now warn that the covariance matrix is singular (or stop warning, if the OPG rank was lower). For "robust" (Harvey's OIM matrix as H), the two ranks are equal in exact arithmetic: a direction in which the OIM matrix is singular has zero derivatives of the forecast errors and their variances, so every score is zero in it and the OPG matrix is singular there too; the numerical ranks can only differ through rounding. Not changed - The covariance matrices and standard errors. - The rank and warning of results with cov_type "approx", "oim", "opg", "none" and "custom". Tests - test_summary_singular_warning_follows_robust_cov_type: at the singular point above, robust_approx and approx results warn and the others do not, and the rank of cov_params() is the closed-form rank of each matrix (robust_approx fails on statsmodels#11063's branch and on main); after the other robust matrices are computed as well (rank 2 and 1), each result keeps the rank of its own matrix. At the MLE, all six cov types have rank 2 and none warns.
bashtage
force-pushed
the
wip-mlemodel-unreachable
branch
from
November 25, 2026 12:12
cedd370 to
e944939
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 25, 2026
The summary of state space results (MLEResults) warns that the covariance matrix is singular when the results' _rank is below the number of free parameters. With cov_type="robust_approx" (and "robust"/"robust_oim"), _rank was the rank of the outer product of gradients (OPG) matrix: the robust matrix, inv(H inv(OPG) H), computes the OPG matrix first, which sets the rank, so the robust matrix's own rank update could never run (statsmodels#11063 removes it as unreachable). The robust matrix has the rank of H, which can be lower. For white noise with a regressor, at the OLS coefficient and twice the mean squared residual as variance, the Hessian of the loglikelihood is diag(-sum(x**2) / s2, 0) (rank 1) and the OPG matrix has rank 2; the robust_approx matrix has rank 1, but the summary did not warn. This is the same change as statsmodels#11068 for the Markov switching models. Changes - _cov_params_robust_oim and _cov_params_robust_approx set _rank to the rank of the robust matrix when no rank is set yet, that is when it is the covariance matrix of the results, as the approx, oim and opg matrices do for theirs. Results with another cov_type keep the rank of their own matrix when a robust matrix is computed later. - versionchanged in the cov_params_robust_oim and cov_params_robust_approx docstrings. The summary of robust_approx results can now warn that the covariance matrix is singular (or stop warning, if the OPG rank was lower). For "robust" (Harvey's OIM matrix as H), the two ranks are equal in exact arithmetic: a direction in which the OIM matrix is singular has zero derivatives of the forecast errors and their variances, so every score is zero in it and the OPG matrix is singular there too; the numerical ranks can only differ through rounding. Not changed - The covariance matrices and standard errors. - The rank and warning of results with cov_type "approx", "oim", "opg", "none" and "custom". Tests - test_summary_singular_warning_follows_robust_cov_type: at the singular point above, robust_approx and approx results warn and the others do not, and the rank of cov_params() is the closed-form rank of each matrix (robust_approx fails on statsmodels#11063's branch and on main); after the other robust matrices are computed as well (rank 2 and 1), each result keeps the rank of its own matrix. At the MLE, all six cov types have rank 2 and none warns.
bashtage
force-pushed
the
wip-mlemodel-unreachable
branch
from
November 25, 2026 18:39
e944939 to
55853d3
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 25, 2026
The summary of state space results (MLEResults) warns that the covariance matrix is singular when the results' _rank is below the number of free parameters. With cov_type="robust_approx" (and "robust"/"robust_oim"), _rank was the rank of the outer product of gradients (OPG) matrix: the robust matrix, inv(H inv(OPG) H), computes the OPG matrix first, which sets the rank, so the robust matrix's own rank update could never run (statsmodels#11063 removes it as unreachable). The robust matrix has the rank of H, which can be lower. For white noise with a regressor, at the OLS coefficient and twice the mean squared residual as variance, the Hessian of the loglikelihood is diag(-sum(x**2) / s2, 0) (rank 1) and the OPG matrix has rank 2; the robust_approx matrix has rank 1, but the summary did not warn. This is the same change as statsmodels#11068 for the Markov switching models. Changes - _cov_params_robust_oim and _cov_params_robust_approx set _rank to the rank of the robust matrix when no rank is set yet, that is when it is the covariance matrix of the results, as the approx, oim and opg matrices do for theirs. Results with another cov_type keep the rank of their own matrix when a robust matrix is computed later. - versionchanged in the cov_params_robust_oim and cov_params_robust_approx docstrings. The summary of robust_approx results can now warn that the covariance matrix is singular (or stop warning, if the OPG rank was lower). For "robust" (Harvey's OIM matrix as H), the two ranks are equal in exact arithmetic: a direction in which the OIM matrix is singular has zero derivatives of the forecast errors and their variances, so every score is zero in it and the OPG matrix is singular there too; the numerical ranks can only differ through rounding. Not changed - The covariance matrices and standard errors. - The rank and warning of results with cov_type "approx", "oim", "opg", "none" and "custom". Tests - test_summary_singular_warning_follows_robust_cov_type: at the singular point above, robust_approx and approx results warn and the others do not, and the rank of cov_params() is the closed-form rank of each matrix (robust_approx fails on statsmodels#11063's branch and on main); after the other robust matrices are computed as well (rank 2 and 1), each result keeps the rank of its own matrix. At the MLE, all six cov types have rank 2 and none warns.
bashtage
force-pushed
the
wip-mlemodel-unreachable
branch
from
November 26, 2026 11:46
55853d3 to
0f57fa3
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 26, 2026
The summary of state space results (MLEResults) warns that the covariance matrix is singular when the results' _rank is below the number of free parameters. With cov_type="robust_approx" (and "robust"/"robust_oim"), _rank was the rank of the outer product of gradients (OPG) matrix: the robust matrix, inv(H inv(OPG) H), computes the OPG matrix first, which sets the rank, so the robust matrix's own rank update could never run (statsmodels#11063 removes it as unreachable). The robust matrix has the rank of H, which can be lower. For white noise with a regressor, at the OLS coefficient and twice the mean squared residual as variance, the Hessian of the loglikelihood is diag(-sum(x**2) / s2, 0) (rank 1) and the OPG matrix has rank 2; the robust_approx matrix has rank 1, but the summary did not warn. This is the same change as statsmodels#11068 for the Markov switching models. Changes - _cov_params_robust_oim and _cov_params_robust_approx set _rank to the rank of the robust matrix when no rank is set yet, that is when it is the covariance matrix of the results, as the approx, oim and opg matrices do for theirs. Results with another cov_type keep the rank of their own matrix when a robust matrix is computed later. - versionchanged in the cov_params_robust_oim and cov_params_robust_approx docstrings. The summary of robust_approx results can now warn that the covariance matrix is singular (or stop warning, if the OPG rank was lower). For "robust" (Harvey's OIM matrix as H), the two ranks are equal in exact arithmetic: a direction in which the OIM matrix is singular has zero derivatives of the forecast errors and their variances, so every score is zero in it and the OPG matrix is singular there too; the numerical ranks can only differ through rounding. Not changed - The covariance matrices and standard errors. - The rank and warning of results with cov_type "approx", "oim", "opg", "none" and "custom". Tests - test_summary_singular_warning_follows_robust_cov_type: at the singular point above, robust_approx and approx results warn and the others do not, and the rank of cov_params() is the closed-form rank of each matrix (robust_approx fails on statsmodels#11063's branch and on main); after the other robust matrices are computed as well (rank 2 and 1), each result keeps the rank of its own matrix. At the MLE, all six cov types have rank 2 and none warns.
bashtage
force-pushed
the
wip-mlemodel-unreachable
branch
from
November 27, 2026 00:31
0f57fa3 to
5ca33b4
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 27, 2026
The summary of state space results (MLEResults) warns that the covariance matrix is singular when the results' _rank is below the number of free parameters. With cov_type="robust_approx" (and "robust"/"robust_oim"), _rank was the rank of the outer product of gradients (OPG) matrix: the robust matrix, inv(H inv(OPG) H), computes the OPG matrix first, which sets the rank, so the robust matrix's own rank update could never run (statsmodels#11063 removes it as unreachable). The robust matrix has the rank of H, which can be lower. For white noise with a regressor, at the OLS coefficient and twice the mean squared residual as variance, the Hessian of the loglikelihood is diag(-sum(x**2) / s2, 0) (rank 1) and the OPG matrix has rank 2; the robust_approx matrix has rank 1, but the summary did not warn. This is the same change as statsmodels#11068 for the Markov switching models. Changes - _cov_params_robust_oim and _cov_params_robust_approx set _rank to the rank of the robust matrix when no rank is set yet, that is when it is the covariance matrix of the results, as the approx, oim and opg matrices do for theirs. Results with another cov_type keep the rank of their own matrix when a robust matrix is computed later. - versionchanged in the cov_params_robust_oim and cov_params_robust_approx docstrings. The summary of robust_approx results can now warn that the covariance matrix is singular (or stop warning, if the OPG rank was lower). For "robust" (Harvey's OIM matrix as H), the two ranks are equal in exact arithmetic: a direction in which the OIM matrix is singular has zero derivatives of the forecast errors and their variances, so every score is zero in it and the OPG matrix is singular there too; the numerical ranks can only differ through rounding. Not changed - The covariance matrices and standard errors. - The rank and warning of results with cov_type "approx", "oim", "opg", "none" and "custom". Tests - test_summary_singular_warning_follows_robust_cov_type: at the singular point above, robust_approx and approx results warn and the others do not, and the rank of cov_params() is the closed-form rank of each matrix (robust_approx fails on statsmodels#11063's branch and on main); after the other robust matrices are computed as well (rank 2 and 1), each result keeps the rank of its own matrix. At the MLE, all six cov types have rank 2 and none warns.
bashtage
force-pushed
the
wip-mlemodel-unreachable
branch
from
November 27, 2026 23:06
5ca33b4 to
4327bb4
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 27, 2026
The summary of state space results (MLEResults) warns that the covariance matrix is singular when the results' _rank is below the number of free parameters. With cov_type="robust_approx" (and "robust"/"robust_oim"), _rank was the rank of the outer product of gradients (OPG) matrix: the robust matrix, inv(H inv(OPG) H), computes the OPG matrix first, which sets the rank, so the robust matrix's own rank update could never run (statsmodels#11063 removes it as unreachable). The robust matrix has the rank of H, which can be lower. For white noise with a regressor, at the OLS coefficient and twice the mean squared residual as variance, the Hessian of the loglikelihood is diag(-sum(x**2) / s2, 0) (rank 1) and the OPG matrix has rank 2; the robust_approx matrix has rank 1, but the summary did not warn. This is the same change as statsmodels#11068 for the Markov switching models. Changes - _cov_params_robust_oim and _cov_params_robust_approx set _rank to the rank of the robust matrix when no rank is set yet, that is when it is the covariance matrix of the results, as the approx, oim and opg matrices do for theirs. Results with another cov_type keep the rank of their own matrix when a robust matrix is computed later. - versionchanged in the cov_params_robust_oim and cov_params_robust_approx docstrings. The summary of robust_approx results can now warn that the covariance matrix is singular (or stop warning, if the OPG rank was lower). For "robust" (Harvey's OIM matrix as H), the two ranks are equal in exact arithmetic: a direction in which the OIM matrix is singular has zero derivatives of the forecast errors and their variances, so every score is zero in it and the OPG matrix is singular there too; the numerical ranks can only differ through rounding. Not changed - The covariance matrices and standard errors. - The rank and warning of results with cov_type "approx", "oim", "opg", "none" and "custom". Tests - test_summary_singular_warning_follows_robust_cov_type: at the singular point above, robust_approx and approx results warn and the others do not, and the rank of cov_params() is the closed-form rank of each matrix (robust_approx fails on statsmodels#11063's branch and on main); after the other robust matrices are computed as well (rank 2 and 1), each result keeps the rank of its own matrix. At the MLE, all six cov types have rank 2 and none warns.
4 of 5 tasks
A coverage audit of statespace/mlemodel.py found private code that no public path can reach. It is removed; results do not change. Changes - _forecasts_error_partial_derivatives: its two callers (observed_information_matrix and the Harvey scores) always pass the filter output at the parameters and a resolved approx_complex_step, and check that complex-step derivatives are only used with transformed parameters (the Harvey scores always pass transformed parameters). The default for approx_complex_step, the check, and the filtering when `res` is None are removed; `res` is a required keyword argument. - MLEModel.simulate, MLEModel.impulse_responses and MLEResults.simulate: the location of the anchor from _get_index_loc is never negative (a negative integer is converted to a location from the end, and dates before the sample raise a KeyError), so the "if iloc < 0" branches are removed. - _cov_params_robust_oim and _cov_params_robust_approx: they compute the OPG matrix first, which sets the rank of the covariance matrix, so their own "if self._rank is None" updates never ran and are removed. - _get_robustcov_results: the statements after "raise NotImplementedError" are removed. Not changed - The _state_names hook, which mirrors _param_names. - The rank of the robust covariance matrices, which stays the rank of the OPG matrix. Tests - A negative integer anchor in MLEModel.simulate and MLEResults.simulate gives the same simulations as the equivalent location, with and without a date index, for a model with exog (so that the simulations depend on the anchor). The negative anchor of impulse_responses is already tested in test_impulse_responses.py. - The removed lines were not covered by the statespace tests on main; no line that was covered before is missing now.
bashtage
force-pushed
the
wip-mlemodel-unreachable
branch
from
November 28, 2026 21:36
4327bb4 to
7e8b168
Compare
bashtage
added a commit
to bashtage/statsmodels
that referenced
this pull request
Nov 28, 2026
The summary of state space results (MLEResults) warns that the covariance matrix is singular when the results' _rank is below the number of free parameters. With cov_type="robust_approx" (and "robust"/"robust_oim"), _rank was the rank of the outer product of gradients (OPG) matrix: the robust matrix, inv(H inv(OPG) H), computes the OPG matrix first, which sets the rank, so the robust matrix's own rank update could never run (statsmodels#11063 removes it as unreachable). The robust matrix has the rank of H, which can be lower. For white noise with a regressor, at the OLS coefficient and twice the mean squared residual as variance, the Hessian of the loglikelihood is diag(-sum(x**2) / s2, 0) (rank 1) and the OPG matrix has rank 2; the robust_approx matrix has rank 1, but the summary did not warn. This is the same change as statsmodels#11068 for the Markov switching models. Changes - _cov_params_robust_oim and _cov_params_robust_approx set _rank to the rank of the robust matrix when no rank is set yet, that is when it is the covariance matrix of the results, as the approx, oim and opg matrices do for theirs. Results with another cov_type keep the rank of their own matrix when a robust matrix is computed later. - versionchanged in the cov_params_robust_oim and cov_params_robust_approx docstrings. The summary of robust_approx results can now warn that the covariance matrix is singular (or stop warning, if the OPG rank was lower). For "robust" (Harvey's OIM matrix as H), the two ranks are equal in exact arithmetic: a direction in which the OIM matrix is singular has zero derivatives of the forecast errors and their variances, so every score is zero in it and the OPG matrix is singular there too; the numerical ranks can only differ through rounding. Not changed - The covariance matrices and standard errors. - The rank and warning of results with cov_type "approx", "oim", "opg", "none" and "custom". Tests - test_summary_singular_warning_follows_robust_cov_type: at the singular point above, robust_approx and approx results warn and the others do not, and the rank of cov_params() is the closed-form rank of each matrix (robust_approx fails on statsmodels#11063's branch and on main); after the other robust matrices are computed as well (rank 2 and 1), each result keeps the rank of its own matrix. At the MLE, all six cov types have rank 2 and none warns.
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.
#11029 (the C10 coverage chunk) appends tests to the same test file, so whichever merges second needs a rebase (keep both test blocks). The other C10F PRs and #11043 also append to
test_mlemodel.py: keep every appended block.A coverage audit of statespace/mlemodel.py found private code that no
public path can reach. It is removed; results do not change.
Changes
(observed_information_matrix and the Harvey scores) always pass the
filter output at the parameters and a resolved approx_complex_step, and
check that complex-step derivatives are only used with transformed
parameters (the Harvey scores always pass transformed parameters). The
default for approx_complex_step, the check, and the filtering when
resis None are removed;
resis a required keyword argument.the location of the anchor from _get_index_loc is never negative (a
negative integer is converted to a location from the end, and dates
before the sample raise a KeyError), so the "if iloc < 0" branches are
removed.
OPG matrix first, which sets the rank of the covariance matrix, so their
own "if self._rank is None" updates never ran and are removed.
NotImplementedError" are removed.
Not changed
OPG matrix.
Tests
A negative integer anchor in MLEModel.simulate and MLEResults.simulate
gives the same simulations as the equivalent location, with and without
a date index, for a model with exog (so that the simulations depend on
the anchor). The negative anchor of impulse_responses is already tested
in test_impulse_responses.py.
The removed lines were not covered by the statespace tests on main; no
line that was covered before is missing now.
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 unreachable code in a coverage audit, removing it, and checking that the results do not change.
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