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

dinvgaussian function is incorrect #33

Open
samsemegne opened this issue Dec 1, 2022 · 1 comment
Open

dinvgaussian function is incorrect #33

samsemegne opened this issue Dec 1, 2022 · 1 comment

Comments

@samsemegne
Copy link

samsemegne commented Dec 1, 2022

The dinvgaussian function, the pdf of the inverse-Gaussian distribution, produces incorrect results.

It doesn't integrate to 1 like a proper pdf, but to 1.732051. Its moments also mismatch what they should algebraically be, e.g. its expected value should equal the mu parameter, but it isn't.

afbeelding

I discovered the issue. Discord user Clarinetist#7695 identified the problem to be in this piece of code:

dens <- log(lambda/(2 * pi * x^3)^0.5) - ((lambda * (x - mu)^2)/(2 * mu^2 * x)) if (log == FALSE) dens <- exp(dens)

Stating: "Taking the log of this, it should be"
"$$\log f(x) = \dfrac{1}{2}\log\left(\dfrac{\lambda}{2\pi x^3} \right) - \dfrac{\lambda (x-\mu)^2}{2\mu^2 x}$$"

@singmann
Copy link
Contributor

singmann commented Dec 1, 2022

Can you submit a pull request please that fixes this?

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

No branches or pull requests

2 participants