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

beta_inc_inv sometimes not sufficiently accurate #375

Closed
andreasnoack opened this issue Jan 31, 2022 · 4 comments · Fixed by #376
Closed

beta_inc_inv sometimes not sufficiently accurate #375

andreasnoack opened this issue Jan 31, 2022 · 4 comments · Fixed by #376

Comments

@andreasnoack
Copy link
Member

E.g.

julia> x
0.2142857142857142

julia> y = StatsFuns.beta_inc(1.5, 5.0, x)[1];

julia> (StatsFuns.beta_inc_inv(1.5, 5.0, y)[1] - x)/eps(x)
-140.0

I noticed this because R currently computes this more accurately.

I tried to look a bit into this and I noticed

iex = max(-5.0/a^2 - 1.0/p^0.2 - 13.0, -30.0)
. The expression in the first argument is not present in the publication that the algorithm is based and it's not in Applied Statistics Algorithms by Griffiths, P. and Hill, I.D but I do see the expression in http://lib.stat.cmu.edu/apstat/109 but without a comment about where it might come from. If I just set iex=-30 following the publications then I get

julia> (StatsFuns.beta_inc_inv(1.5, 5.0, y)[1] - x)/eps(x)
0.0

@simonbyrne Do you have any guess to where the extra expression that reduces iex come from?

@simonbyrne
Copy link
Member

Ah, that's interesting, I hadn't notice the discrepancy from the paper. I have no idea!

@simonbyrne
Copy link
Member

This seems to be the most recent work in the area https://doi.org/10.1007/s11075-016-0139-2 / https://arxiv.org/abs/1605.03503v1

@simonbyrne
Copy link
Member

A relatively recent algorithm was given in [5].

[5] is from 1992.

@andreasnoack
Copy link
Member Author

andreasnoack commented Jan 31, 2022

Thanks for the link. It looks like something that would interesting to try out instead of the current implementation. The paper also solved the mystery here since it cites the remark that introduces the adjustment of ACU. It's https://rss.onlinelibrary.wiley.com/doi/epdf/10.2307/2347779. However, they provide no motivation for the coefficients. The original implementations from Applied Statistics are all single precision so maybe the formula requires some adjustment for double precision but that it's impossible to tell from the comment.

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.

2 participants