Skip to content
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

cdf of InverseGaussian #1873

Closed
ldoyen opened this issue Jun 24, 2024 · 1 comment · Fixed by #1882
Closed

cdf of InverseGaussian #1873

ldoyen opened this issue Jun 24, 2024 · 1 comment · Fixed by #1882

Comments

@ldoyen
Copy link

ldoyen commented Jun 24, 2024

Hi,

I have noticed a problem with the cdf of InverseGaussian distribution which can potentially be equal to Inf. This is a problem since a cdf is probability and consequently must be between 0 and 1. For example,

d = InverseGaussian(1.65,590)
cdf(d, 2.)

returns Inf. In addition, if you plot the empirical histogram, you can see that 2.0 is not so extreme with respect to the simulated values.

histogram(rand(d, 10000),normalize=:pdf)

For comparison, in the same situation R provides the good value of the cdf which is equal to 1 in this case.

Best regards.

Laurent

@ldoyen
Copy link
Author

ldoyen commented Jun 28, 2024

Hello,
I found the solution thanks to a colleague: using the logdcf function.
d = InverseGaussian(1.65,590)
exp(logcdf(d, 2.))
gives the correct answer, that is to say 1 in this case

For most distributions, logcdf function simply takes the logarithm of cdf. But for some distributions that may have numerical problems for certain parameter values (such as the inverse Gaussian distribution), the logcdf function implements the calculation in a more subtle way and avoids numerical problems by scaling to log.
Best ragards
Laurent

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 a pull request may close this issue.

1 participant