Repository navigation
Conversation
With cov_type="cluster" and use_t=True, conf_int, t_test and pvalues use the t distribution with n_groups - 1 degrees of freedom, but get_prediction used df_resid, so the confidence and prediction intervals of the predicted mean were too narrow. This affected regression, GLM and discrete results.
Member
|
The release note the PR body and the new code comment say the confidence and prediction intervals "were too narrow". This is only true for the confidence interval of the mean. Please do one of the following:
Once you have taken a decision, rewrite the release note so it only claims what is true, and add the roles :issue: |
Reword the release note, add the issue and PR roles, and document in PredictionResults.conf_int that the prediction interval for a new observation uses df_resid_inference too, which is conservative.
Member
|
Thanks. LGTM. |
4 of 5 tasks
bashtage
added a commit
that referenced
this pull request
Nov 16, 2026
The release note of #10744 named only cov_type="cluster". Every covariance type that sets df_resid_inference changes: "cluster" (also two-way clustering), "hac-panel" and "hac-groupsum" for all models and "cluster-crv3" and "cluster-jk" for linear models, unless df_correction=False. With use_t=False nothing changes. Checked with seeded OLS, GLM, Logit and Poisson fits with 10 clusters on main before and after #10744. The entry stays in Bug Fixes with the neighbouring #10742, #10737 and #10736. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage
added a commit
that referenced
this pull request
Nov 16, 2026
#10744 made the intervals of get_prediction use df_resid_inference (n_groups - 1 with cluster-robust covariances) when the results have it, but only PredictionResults.conf_int of the regression results said so. Add one paragraph and a versionchanged directive to the get_prediction docstrings of the regression, GLM, discrete and generic likelihood results and to conf_int of the prediction result classes in base/_prediction_inference.py. The normal distribution is used with use_t=False, with average=True and for which other than "mean" and "linear"; checked by running each option. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage
added a commit
that referenced
this pull request
Nov 16, 2026
The test added in #10744 compared get_prediction with intervals computed from the same covariance, so it only checked consistency. Add a reference from R 4.6.1 (sandwich 3.1.3, lmtest 0.9.40: coefci with vcovCL HC1 and df = G - 1 or Inf) for the mean prediction of an OLS fit with literal data, a parametrized test of cluster-crv3, cluster-jk, hac-panel, hac-groupsum and two-way clustering, and a negative control: with df_correction=False the intervals use t(df_resid) and with use_t=False they are normal. Move the imports of scipy, GLM, Logit and the families to the module top, build the models in a helper and define the summary frame before the model branches. Reverting any one of the four getattr lines of #10744 fails tests. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage
added a commit
that referenced
this pull request
Nov 16, 2026
DOC: Follow up #10744 on get_prediction degrees of freedom, with R reference tests
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.
Fixes #10743
With
cov_type="cluster"anduse_t=True,conf_int,t_testandpvaluesuse the t distribution withn_groups - 1degrees of freedom (df_resid_inference), butget_predictionuseddf_resid. The confidence and prediction intervals of the predicted mean were too narrow, for example[1.012, 3.281]instead of[0.845, 3.448]for an OLS model with 10 clusters, wheret_testof the same linear combination gives the latter. In a simulation with 10 clusters the 95% interval covered 89.0% before and 93.4% after the change.The fix uses
getattr(self, "df_resid_inference", self.df_resid), the same asLikelihoodModelResults.conf_int, in the four places that build prediction results:regression/_prediction.get_predictionandget_prediction_glm,get_prediction_linear,get_prediction_monotonicinbase/_prediction_inference.py. Withoutdf_resid_inference(all other cov types) nothing changes.Test:
test_prediction_cluster_use_t_dfinregression/tests/test_predict.py, for OLS, WLS, Gaussian GLM, Poisson GLM and Logit. It compares the mean and observation intervals ofsummary_frame, andconf_intforwhich="linear"andwhich="mean", withx0 @ params ± t(0.975, G - 1) * seand witht_test(exog0).conf_int(). All 5 cases fail on main and pass with the fix. Release note added under regression bug fixes.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.Used for:
drafting the tests and this PR description.I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.