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

pdf(::Binomial, ::Int) should return rational number. #889

Open
newptcai opened this issue May 10, 2019 · 6 comments
Open

pdf(::Binomial, ::Int) should return rational number. #889

newptcai opened this issue May 10, 2019 · 6 comments

Comments

@newptcai
Copy link

If the parameters of binomial distribution are given in rational number, then perhaps the pdf function should also return rational number. But now it gives Float64, which can cause some unintended rounding problems.

julia> using Distributions

julia> dist = Binomial(2, 1//2)
Binomial{Rational{Int64}}(n=2, p=1//2)

julia> pdf(dist, 0)
0.24999999999999994

julia> pdf(dist, 1)
0.49999999999999994

julia> pdf(dist, 2)
0.24999999999999994
@simonbyrne
Copy link
Member

Would be cool to have, though may not be that practical.

@newptcai
Copy link
Author

I just need this for relatively small $n$. I can do write a bit script to do compute the probabilities, but it feels cleaner to extend the pdf function.

@matbesancon
Copy link
Member

I think the delegate_statsfuns is also an issue, we cannot enjoy generics with functions called from R. In the case of Binomial, it's a bit sad to have to call R, PR welcome

@matbesancon
Copy link
Member

@lukasbk
Copy link

lukasbk commented Aug 23, 2021

I'd be happy to work on this, but I'm mostly new contributing to open source. Why do you say delegate_statsfuns is "also" an issue? To me, it seems like it's the only place in binomial.jl where Rationals are unnecessarily converted into Floats. Wouldn't the solution be to implement the functionality of delegate_statsfuns for the binomial distribution directly in binomial.jl, indeed removing the dependence on R?

@devmotion
Copy link
Member

The solution to the R dependency is JuliaStats/StatsFuns.jl#113.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants