ENH: add logs of upper and lower incomplete gamma functions from boost by dschmitz89 · Pull Request #25161 · scipy/scipy · GitHub adds two new special functions, `log_gammainc` and `log_gammaincc`, for the accurate computation of the logarithm of the lower and upper incomplete gamma functions. The functions are actually implemented in boost, we simply wrap them.
What are they useful for? The incomplete gamma functions arise in the CDF/SF of many distributions, so the new functions will enable very accurate logcdf and logsf computations for many distributions. This was for example requested for the Poisson distribution in ENH: stats.poisson: underflow/overflow + solution · Issue #8424 · scipy/scipy · GitHub .
We would like to gather some feedback and reviewer attention.
As a user, this is fantastic to see - thanks for this work! I’ve frequently ran into computation issues with various distributions where the log cdf doesn’t actually use something more precise under the hood, and that will solve this really nicely.
Glad to hear that this may be useful to others too and welcome to this forum! Out of curiosity: for which distributions did you run into precision issues?
I’ve wanted to use log cdfs quite often to calculate & compare very small p-values for a range of distributions. I guess this change will solve this for Gamma & Poisson distributions, which is great! I’ve also ran into issues with the binomial distribution, which also doesn’t have natively logarithmic cdf & sf functions. That would require a log incomplete beta function - which I don’t think is currently in boost, but I think could be added as it has a continued fraction expansion that could be calculated in log space.
Then you will be interested in Implement the log of the incomplete beta function by JacobHass8 · Pull Request #1359 · boostorg/math · GitHub which implements the log incomplete beta function :). If you leave a comment there to show that there are indeed real world users of that function it might help push that development further to the finish line.