Repository navigation
BUG: GLM.information returned the Hessian, not the Fisher information - #10628
Merged
bashtage merged 4 commits intoOct 28, 2026
Merged
Conversation
The base-class contract documents information() as returning -1 * Hessian of the log-likelihood, but GLM returned the (negative definite) Hessian itself, unlike every other model that implements information() (e.g. ARModel). Negate so that GLM.information returns the positive-definite expected information matrix. Closes statsmodels#7826 The method has no internal callers, and the only test referencing it pinned the old, wrong identity; that assertion is flipped with the fix. Signed-off-by: simpleqt <[email protected]>
Parametrize the information test over Poisson/log, Gamma/log and Binomial/probit and compare with X'WX / scale. Add a Gamma/log test against the expected information of R's glm. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
closes #10498
Draft takeover of #10498 by simpleqt. The author's commit a146ffb is kept unchanged (author and message); it was rebased onto current
mainwithout conflict (no merge commit was dropped). It changesGLM.informationto return-self.hessian(params, scale=scale, observed=False), i.e. the positive definite expected (Fisher) informationX' W X / scaleas inLikelihoodModel.informationandARModel.information. Onmainit returned the negative of that. The code change is correct: the new tests check it against the formula and against R.What the PR adds
1c658eee5TST:test_information_is_expected_hessianis now parametrized over Poisson/log (canonical, observed and expected information coincide), Gamma/log and Binomial/probit (non-canonical, observed and expected differ). Besides the sign and positive definiteness, each case is compared with an independent formula(exog.T * w) @ exog / scalewithw = 1 / (link.deriv(mu)**2 * variance(mu)), and with-hessian(params)(observed) for the canonical link only. Newtest_information_gamma_log_r: Gamma family with a log link, 20 observations, compared with R 4.6.1glm:solve(summary(res)$cov.unscaled) / summary(res)$dispersion, which equalssolve(vcov(res))(the expected information, not the observed one: they differ by 14 percent in one entry). The R code and the values are in the test. R was run on Windows, not in WSL.58e0e78a0DOC: numpydocParametersandReturnsforGLM.information, saying that it is the expected information and differs from the default (observed)-hessian(params)unless the link is canonical.Callers: the only caller of any
.information()in the package isARModel.hessian;GLM.informationis not used inside statsmodels (cov_params, score tests and the hat matrices usehessian/hessian_factor), so nothing relied on the old sign.GLMGaminherits it throughPenalizedMixinand gets the same change.GEEinherits it too butGEE.information(params)already raised aTypeErrorbefore this change (GEE.estimate_scaletakes no argument); that is not touched here.Decision for the maintainer
#7826 is not closed: its title and body are about the sign of
GLM.hessian_factor, which is not changed here (the PR only fixes theinformationsign mentioned in the first comment of the issue; josef-pkt's comment there saysinformationcould instead be removed). The release note therefore cites:issue:7826 only as a reference, and the issue stays open. If you prefer to removeGLM.informationinstead of fixing its sign, this PR is not needed.Verification
Commands that were run and passed in WSL (Ubuntu-24.04, Python 3.13, NumPy 2.5, pandas 3.1, SciPy 1.18) on a copy of
mainwith the.pyfiles of this branch copied over it:With the pre-change
generalized_linear_model.pyofmainthe four new test cases fail:test_information_is_expected_hessian[poisson-log],[gamma-log],[binomial-probit]andtest_information_gamma_log_r(the result is the exact negative). The Sphinx docs were not built.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 Sonnet 5.5).
Used for: reviewing the original change, writing the tests and the docstring, running the R reference computation and the test runs.
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