Repository navigation
BUG: Pass p to the submodels in the truncated count score - #10736
Merged
bashtage merged 1 commit intoNov 15, 2026
Merged
Conversation
TruncatedLFGeneric.score_obs creates one untruncated model per truncated count to get the score of the truncation probability, but it did not pass p, so these models used the default p of the untruncated class. The score was wrong for TruncatedLFGeneralizedPoisson with its default p=2, for TruncatedLFNegativeBinomialP with p other than 2 and for HurdleCountModel with dist="negbin" and p other than 2, and fit stopped early with a ConvergenceWarning. Pass the p of model_main to these models. The score now agrees with the numerical derivative of loglike.
bhaskargurram-ai
marked this pull request as draft
November 11, 2026 15:28
bhaskargurram-ai
marked this pull request as ready for review
November 11, 2026 15:38
Member
|
Thanks. |
This was referenced Nov 15, 2026
bashtage
added a commit
that referenced
this pull request
Nov 16, 2026
The bullet for the truncated count score of #10736 was in the middle of the list of the discrete models, without the PR role, and did not say what users see. Move it to the end of the list, add the PR number, and state that params, bse and llf of the fitted models change for every p other than p=1 of the generalized Poisson and p=2 of the negative binomial model, with the example of the default generalized Poisson (alpha 0.099 -> 0.219, llf -3582.06 -> -3554.15 for 3000 simulated counts, measured on main before the PR and with the PR). The bullet stays in Bug Fixes like the sibling bullets of #10723 and #10737 for the Hessians of the discrete models. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage
added a commit
that referenced
this pull request
Nov 16, 2026
Follow-up to #10736. The default fit test of the truncated generalized Poisson only checked that the optimizer had stopped, which is true for any score. It now compares llf and params with the maximum of the same likelihood computed in R (own log-likelihood, numDeriv, optim), with the R call in a comment. The test of the hurdle model passed also if the model ignored p, because loglike and score were then both consistent with p=2, so it checks that the truncated model of the hurdle has p=1. The score test of the truncated models gets cases with an offset, which the models for the truncated counts have to receive, and a comment for the tolerance (finite difference error). Fix the blank lines before the helper. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
bashtage
added a commit
that referenced
this pull request
Nov 16, 2026
DOC: Follow up #10736 on the truncated count score, with tests
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]>
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.
TruncatedLFGeneric.score_obscreates one untruncated model for each truncated count to get the score of the truncation probability, but it does not passp. These models use the default of their class (p=1forGeneralizedPoisson,p=2forNegativeBinomialP), whileloglikeuses thepof the model. Soscoreis wrong forTruncatedLFGeneralizedPoissonwith its defaultp=2(and anypother than 1),TruncatedLFNegativeBinomialPwithpother than 2,HurdleCountModel(dist="negbin", p=...)withpother than 2.With 3000 simulated NB2 counts (zeros dropped),
TruncatedLFGeneralizedPoisson(endog, exog).fit()stops with aConvergenceWarningat llf -3582.06 and alpha 0.099. The maximum, found with Nelder-Mead and Powell onloglikeonly, is at llf -3554.15 with alpha 0.219. ForTruncatedLFNegativeBinomialP(p=1)it is -3566.23 instead of -3555.57. The relative error ofscoreagainst the numerical derivative ofloglikewas between 0.5 and 2.8 for the affected truncated models.The fix passes the
pofmodel_mainto these models. Afterwardsscoreagrees withapprox_fprimeoflogliketo 1.2e-7 or better for GP and NBP withp= 1, 1.5, 2, truncation 0 and 1, and for the hurdle model withp=1, and the default fits reach the same llf and params as the derivative-free optimization.Tests:
test_score_numerical_p(GP and NBP,p= 1, 1.5, 2, truncation 0 and 1),test_hurdle_negbin_p1_score_numericalandtest_truncated_genpoisson_default_fit. 8 of the 10 fail on main; GP withp=1and NBP withp=2pass on main, as expected.#10505 changes the
exposure=argument of the same constructor call. Whichever is merged second needs a one-line rebase there.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.