-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numerical underflow in pgengamma #58
Comments
In this particular case, it's the very low value of the "q" argument to pgamma that's causing the issue as it's getting approximated to 0 and escaping via that route. When q is low (< 1), the "pgamma_smallx" evaluation path is used (referred to Abramowitz and Stegun 6.5.29 [right]; I'm afraid I haven't tracked down the equivalent in the DLMF yet). In this evaluation, for extremely small values the initial term is so small it lies within the episilon bound and the series is exited immediately. For alpha = 1 / (Q * Q) < 1, the result then reduces to:
It should be noted that the evaluation of pgengamma starts leaking precision before we hit the values you've given in your example, and we should switch over to the approximation at an earlier critical value. Below is an extremely naive implementation, but shows the sort of behaviour we should expect when allowing this escape hatch: `library(flexsurv) y <- log(q) Qwqq <- Q * w + log(qq) o <- numeric(length(q)) original <- Qwqq >= Qwqq_critical_low times <- seq(0,500,1) |
pgengamma
underflows for extreme values of Q:This behaviour is inherited from
pgamma
:Perhaps there's a workaround that uses logs in the intermediate calculations done in
https://github.com/chjackson/flexsurv-dev/blob/master/src/gengamma.h
The text was updated successfully, but these errors were encountered: