Skip to content

BUG: GLM.information returned the Hessian, not the Fisher information - #10628

Merged
bashtage merged 4 commits into
statsmodels:mainfrom
bashtage:wip-pr10498-glm-information-sign
Oct 28, 2026
Merged

bashtage merged 4 commits into
statsmodels:mainfrom
bashtage:wip-pr10498-glm-information-sign

Conversation

@bashtage

Copy link
Copy Markdown
Member

closes #10498

  • tests added / passed.
  • code/documentation is well formatted.
  • properly formatted commit message.

Draft takeover of #10498 by simpleqt. The author's commit a146ffb is kept unchanged (author and message); it was rebased onto current main without conflict (no merge commit was dropped). It changes GLM.information to return -self.hessian(params, scale=scale, observed=False), i.e. the positive definite expected (Fisher) information X' W X / scale as in LikelihoodModel.information and ARModel.information. On main it 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

  • 1c658eee5 TST: test_information_is_expected_hessian is 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 / scale with w = 1 / (link.deriv(mu)**2 * variance(mu)), and with -hessian(params) (observed) for the canonical link only. New test_information_gamma_log_r: Gamma family with a log link, 20 observations, compared with R 4.6.1 glm: solve(summary(res)$cov.unscaled) / summary(res)$dispersion, which equals solve(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.
  • 58e0e78a0 DOC: numpydoc Parameters and Returns for GLM.information, saying that it is the expected information and differs from the default (observed) -hessian(params) unless the link is canonical.
  • Release note (last commit): a bullet under Breaking Changes and Deprecations, Behavior changes.

Callers: the only caller of any .information() in the package is ARModel.hessian; GLM.information is not used inside statsmodels (cov_params, score tests and the hat matrices use hessian/hessian_factor), so nothing relied on the old sign. GLMGam inherits it through PenalizedMixin and gets the same change. GEE inherits it too but GEE.information(params) already raised a TypeError before this change (GEE.estimate_scale takes 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 the information sign mentioned in the first comment of the issue; josef-pkt's comment there says information could instead be removed). The release note therefore cites :issue: 7826 only as a reference, and the issue stays open. If you prefer to remove GLM.information instead 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 main with the .py files of this branch copied over it:

pytest statsmodels/genmod/tests/test_glm.py statsmodels/gam/tests statsmodels/tsa/tests/test_ar.py -q   # 5241 passed, 1 skipped
ruff check statsmodels/genmod/generalized_linear_model.py statsmodels/genmod/tests/test_glm.py          # All checks passed
git diff --check

With the pre-change generalized_linear_model.py of main the four new test cases fail: test_information_is_expected_hessian[poisson-log], [gamma-log], [binomial-probit] and test_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.

  • No AI tools were used to develop this pull request.
  • AI tools were 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

simpleqt and others added 4 commits October 28, 2026 10:24
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]>
@bashtage
bashtage marked this pull request as ready for review October 28, 2026 15:01
@bashtage
bashtage merged commit 7e1ec36 into statsmodels:main Oct 28, 2026
13 checks passed
@bashtage
bashtage deleted the wip-pr10498-glm-information-sign branch October 28, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants