Repository navigation
BUG: Use the null model's scale in GLMResults.llnull - #10669
Open
DresdenGman wants to merge 3 commits into
Open
DresdenGman wants to merge 3 commits into
DresdenGman wants to merge 3 commits into
Conversation
llnull evaluated the log-likelihood at the fitted values of the constant-only null model, but used the scale estimated for the full model. For families with an estimated scale, e.g. Gaussian and Gamma, this made llnull and the pseudo R-squared of the full model wrong. The scale of the null model is now estimated in the same way as the scale of the full model, using the fitted values and the residual degrees of freedom of the null model. Families with a fixed scale of one, e.g. Poisson and Binomial, are unchanged. The prsquared reference values for the Longley and Scotvote results were computed with the full model scale and have been updated. closes statsmodels#9025
4 of 5 tasks
Member
|
Please add the PR role to the release note, after the issue role: |
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.
NumPy's guide.
What this PR does
GLMResults.llnullevaluated the family log-likelihood at the fittedvalues of the constant-only null model, but passed the scale estimated
for the full model. For families with an estimated scale (e.g.
Gaussian, Gamma),
llnull— and with it the McFadden and Cox-Snellpseudo R-squared — was therefore wrong. Example (Gaussian, n = 40):
llnullwas -96.07, while the log-likelihood of the null model at itsown scale is -87.49.
The fix estimates the scale of the null model in exactly the same way
as the scale of the full model, i.e. through
GLM.estimate_scaleevaluated at the fitted values of the null model with the residual
degrees of freedom of the null model, honoring the
scaleargument ofthe original fit (fixed value,
"x2"or"dev"). The null-modelconstruction (constant-only design and adjusted init keywords) is
shared between
GLMResults.nullandllnullvia a small helper, sothe two cannot drift apart. Families with a fixed scale of 1
(Poisson, Binomial, NegativeBinomial by default) are unchanged, and
null_devianceis intentionally not touched: deviance is ascale-free quantity in statsmodels (as in R).
Tests
test_glm_llnull_own_scale: Gaussian againstthe closed-form null log-likelihood, Gamma against an explicitly
fitted constant-only model, plus fixed-scale and
"dev"-scale fits.It fails on main and passes with this change.
prsquaredreference values for the Longley and Scotvote resultclasses in
tests/results/results_glm.pywere updated. The oldvalues reproduce the pre-fix (full-model-scale) output to 3-4
significant digits; the corrected values are 0.28273/0.99549
(Longley) and 0.25568/0.83175 (Scotvote).
statsmodels/genmod/testsandstatsmodels/gam/testssuites:1148 passed on main, 1149 passed with this change (the +1 is the new
regression test), no new failures.
A release-notes entry was added to
version0.15.1.rst.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): Muse.
Used for: drafting the implementation and its regression test, and verifying the change against an explicitly fitted null model and the closed-form Gaussian null log-likelihood.
I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.