Skip to content

fix: use log_wright_bessel to fix overflow - #9320

Closed
bzheng06 wants to merge 2 commits into
statsmodels:mainfrom
StateFarmIns:use_log_wright_bessel
Closed

bzheng06 wants to merge 2 commits into
statsmodels:mainfrom
StateFarmIns:use_log_wright_bessel

Conversation

@bzheng06

Copy link
Copy Markdown
Contributor
Details Tweedie's loglike_obs function currently overflows in some cases with the scipy wright_bessel function. As of scipy version 1.14.0, log_wright_bessel has been released which fixes the overflow issues. Added a test case for the new loglike_obs function with a case where wright_bessel caused overflow to verify that the new function solves the issue. (link: https://github.com//issues/9234)

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in main and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/main -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

@pep8speaks

Copy link
Copy Markdown

Hello @bzheng06! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 126:1: W293 blank line contains whitespace
Line 130:1: W391 blank line at end of file

@bzheng06

Copy link
Copy Markdown
Contributor Author

@josef-pkt @lorentzenchr

I was testing out the change mentioned in this comment: #9234 (comment)

It seemed to fix our issue with 'inf' appearing in our loglikelihood results but also caused the test 'test_tweedie_loglike_obs' in test_family.py to fail. From examining the outputs of the current version of the code vs the new version (the change I made in this PR), the outputs of pdf() are the same, as well as tweedie.loglike_obs(). However, the results from integrate.quad(pdf, 0, 1e2)[0] are different, causing the test cases to fail. Could you provide some insight as to why that is?

@lorentzenchr

Copy link
Copy Markdown
Contributor

Which test is failing?

@josef-pkt

Copy link
Copy Markdown
Member

AFAICS, this needs a scipy version check or try ... except ... for older scipy versions

@josef-pkt

Copy link
Copy Markdown
Member

log_write_bessel has Added in version 1.14.0.
I'm still on older scipy versions.

@bashtage bashtage mentioned this pull request Aug 24, 2026
6 of 7 tasks
bashtage added a commit to bashtage/statsmodels that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants