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

Rational param breaks Binomial CDF #98

Closed
ron-wolf opened this issue Jun 24, 2020 · 4 comments
Closed

Rational param breaks Binomial CDF #98

ron-wolf opened this issue Jun 24, 2020 · 4 comments

Comments

@ron-wolf
Copy link

StatsFuns.binomccdf() maps to the eponymous R function, as shown below.

import .RFunctions:
binompdf,
binomlogpdf,
binomcdf,
binomccdf,
binomlogcdf,
binomlogccdf,
binominvcdf,
binominvccdf,
binominvlogcdf,
binominvlogccdf

However, when called on a binomial distribution with 𝑝::Rational, an error occurs; currently, the only option is to convert the parameter using float(). Note that although the code below uses Distributions, I believe the error is on the part of StatsFuns: see this code in Distributions for the call to StatsFuns.

using Distributions; ccdf(Binomial(7, 1//5), 1)
ERROR: MethodError: no method matching binomccdf(::Int64, ::Rational{Int64}, ::Int64)
Closest candidates are:
  binomccdf(::Union{Float64, Int64}, ::Union{Float64, Int64}, ::Union{Float64, Int64}) at /Users/USER/.julia/packages/StatsFuns/CXyCV/src/rmath.jl:80
Stacktrace:
 [1] ccdf(::Binomial{Rational{Int64}}, ::Int64) at /Users/USER/.julia/packages/Distributions/RAeyY/src/univariates.jl:557
 [2] top-level scope at REPL[1]:1

Is this intended behavior? Such distributions work just fine with StatsPlots.plot().

using Distributions, StatsPlots; plot(Binomial(7, 1//5))

A plot of the binomial distribution with n=7 and p=⅕

@andreasnoack
Copy link
Member

The cdf of the Binomial distribution is based on the incomplete Beta function which is very complicated function to implement reliably. However, I guess we could have a naive fallback that sums up the probabilities.

@ron-wolf
Copy link
Author

Certainly! I’d be happy to get involved in implementing this. I’m relatively new to Julia though, as well as to statistics generally. I have a few questions:

  • Do you happen to know where I’d find R‘s implementation of the binomial CDF? It is my understanding that Julia uses it.
  • Do you suspect that when properly implemented, this fallback will involve numerical integration using, e.g., QuadGK?

@ron-wolf
Copy link
Author

Related: #33

@devmotion
Copy link
Member

The issue was fixed by #125. With StatsFuns 0.9.11:

julia> using Distributions; ccdf(Binomial(7, 1//5), 1)
0.4232832000000002

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

3 participants