-
Notifications
You must be signed in to change notification settings - Fork 40
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
Wrong quantiles for the binomial distribution #170
Comments
Thanks for reporting this. The issue is actually in julia> binominvcdf(5000.0, 0.998575, 0.0005)
5000.0 However, for the quantile function, we actually rely on Rmath so it is a bit surprising and might be an issue with the version of Rmath that we use. |
Looked a bit into this and it appears that it is actually a bug in R that was fixed relatively recently, see https://bugs.r-project.org/show_bug.cgi?id=18711. So we should upgrade |
Once JuliaPackaging/Yggdrasil#9413 has been merged, this issue should be resolved. It would be good to add a test case, though. @Martin-exp-z2 would you be able to prepare a PR with a test? |
I can confirm that this now works (StatsFuns) pkg> up
Updating registry at `~/.julia/registries/General.toml`
Installed Rmath ───── v0.8.0
Installed Rmath_jll ─ v0.5.1+0
Downloaded artifact: Rmath
Updating `~/.julia/dev/StatsFuns/Project.toml`
[79098fc4] ↑ Rmath v0.7.1 ⇒ v0.8.0
Updating `~/.julia/dev/StatsFuns/Manifest.toml`
[79098fc4] ↑ Rmath v0.7.1 ⇒ v0.8.0
[f50d1b31] ↑ Rmath_jll v0.4.3+0 ⇒ v0.5.1+0
Precompiling project...
3 dependencies successfully precompiled in 4 seconds. 12 already precompiled.
julia> using StatsFuns
julia> binominvcdf(5000.0, 0.998575, 0.0005)
4983.0 |
@andreasnoack , thank you very much indeed for fixing the issue! I was not aware that the computation of quantiles in Julia actually relies on R routines. In future, it might be a good idea to write all the computation in Julia itself: I presume that this would make it even more efficient. However, I am aware that this requires considerable effort, which might be better spent elsewhere. I am ready to prepare a program which would test the correctness of the computation of quantiles of instances of the binomial distribution suitably chosen at random (both parameters as well as quantile levels). Would that be OK? However, I am quite busy in general. Should the program not be ready in a few days, please remind me. |
We are working towards that, see #37, but indeed it takes time to implement these functions. We try to compose these out if functions from StatsFuns.jl/src/distrs/binom.jl Lines 4 to 14 in 5d0bf33
Regarding the testing then we mostly rely on testing against values from R since R is generally considered battle tested and we test a relatively small number of combinations. See e.g. Lines 219 to 231 in 5d0bf33
|
@andreasnoack , could you please help me update to the newest version of
Many thanks! |
I just realized that a new version of StatsFuns is needed here because of the minor version bump of Rmath. Once JuliaRegistries/General#115053 is available, you should be able to upgrade. |
@andreasnoack , great! Now it works on my computer, too! Please find a testing program below (I was unable to attach it as a file, but maybe it is meant to be this way). After testing 2M randomly selected instances of the binomial distribution, no error so far.
|
Hello everyone,
I have noticed that the call
quantile(Binomial(5000, 0.998575), 0.0005)
returns5000
, which is wrong. Consider:which return correct values (virtually the same as the corresponding calls of
scipy.stats.binom.cdf
in Python). Thus, the above-mentioned call ofquantile()
should return4983
.In addition, in my opinion, it would be more natural and useful if the function
cquantile()
returned the upper quantile. In particular, this would allow the user to get the middle median by calling(quantile(dist, 0.5) + cquantile(dist, 0.5))/2
.I am using Distributions v0.25.111 in Julia v1.10.5.
Thank you very much in advance for considering the issue!
The text was updated successfully, but these errors were encountered: