Repository navigation
BUG: Use the log_wright_bessel of SciPy 1.15 or later only in Tweedie - #11320
Merged
Merged
Conversation
Tweedie.loglike_obs, and so the llf of a GLM with the Tweedie family, used scipy.special.log_wright_bessel with SciPy 1.14 and later. In SciPy 1.14.0 and 1.14.1 it is wrong for some arguments: log_wright_bessel(1, 0, 2) is 4.7897, while log(wright_bessel(1, 0, 2)) and SciPy 1.15.0 give 1.5665. With SciPy 1.14 the density of the Tweedie family did not integrate to 1 (1.25, 2.09 and 1.01 for var_power 1.9, 1.5 and 1.1 in test_tweedie_loglike_obs), and the llf in TestGlmTweedieAwNr was -8504.98 instead of the reference value from R, -8669.18. With SciPy < 1.15 loglike_obs uses wright_bessel, as it did with SciPy < 1.14, and test_tweedie_log_wright_bessel, which checks the values of the log path, is skipped. No CI job uses SciPy 1.14, so the tests only fail on main with SciPy 1.14 installed: with SciPy 1.14.0, test_tweedie_loglike_obs (3 cases) and TestGlmTweedieAwNr::test_basic fail without this change and pass with it.
bashtage
force-pushed
the
wip-tweedie-scipy114
branch
from
November 28, 2026 20:10
5e53ea8 to
2d18112
Compare
This was referenced Nov 28, 2026
|
Thanks for the pull request! Neither box in the AI Disclosure section is ticked. Please tick the one that applies. Per the AI Policy, every pull request must state whether AI tools were used. Please edit the PR description so it includes the section below, tick exactly one box, and, if AI tools were used, replace the placeholders with the tool name(s) and how they were used. #### AI Disclosure
Contributions must comply with the statsmodels [AI Policy](https://www.statsmodels.org/devel/dev/ai-policy.html).
- [ ] No AI tools were used to develop this pull request.
- [ ] AI tools were used.
Tool(s): `<name(s), e.g. Copilot, Claude, ChatGPT>`.
Used for: `<e.g. drafting an implementation, writing tests, debugging, editing docstrings>`.
I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.This check re-runs automatically when the description is edited. |
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.
Tweedie.loglike_obs, and so the llf of a GLM with the Tweedie family,
used scipy.special.log_wright_bessel with SciPy 1.14 and later. In SciPy
1.14.0 and 1.14.1 it is wrong for some arguments: log_wright_bessel(1, 0,
2) is 4.7897, while log(wright_bessel(1, 0, 2)) and SciPy 1.15.0 give
1.5665. With SciPy 1.14 the density of the Tweedie family did not
integrate to 1 (1.25, 2.09 and 1.01 for var_power 1.9, 1.5 and 1.1 in
test_tweedie_loglike_obs), and the llf in TestGlmTweedieAwNr was
-8504.98 instead of the reference value from R, -8669.18.
With SciPy < 1.15 loglike_obs uses wright_bessel, as it did with SciPy
< 1.14, and test_tweedie_log_wright_bessel, which checks the values of
the log path, is skipped.
No CI job uses SciPy 1.14, so the tests only fail on main with SciPy 1.14
installed: with SciPy 1.14.0, test_tweedie_loglike_obs (3 cases) and
TestGlmTweedieAwNr::test_basic fail without this change and pass with
it.
Verification
With SciPy 1.14.0 (NumPy 2.0.0, Python 3.11, Ubuntu 24.04),
test_family.py,test_glm_weights.pyandtest_glm.py: 4 failed and 3warnings on main, 1030 passed and no warnings with this change. Probing
SciPy directly,
log_wright_bessel(1, 0, 2)is 4.7897 in SciPy 1.14.0 and1.14.1 and 1.5665 in SciPy 1.15.0, which equals
log(wright_bessel(1, 0, 2))in all three. With SciPy 1.15 and later the code is unchanged.
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: finding the bug when the CI job with the minimum versions ran SciPy 1.14.0, locating the wrong SciPy releases and checking the fix against them.
I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.