Moses Stamboulian
Moses Stamboulian

Reputation: 11

the equivalent of R VGAM::pbetabinom() function in python3

Im looking for the equivalent of the VGAM::pbetabinom() R package in Python3, I tried using the scipy betabinomial distribution package however it did not give the same results. For example, in R if I run this command:

VGAM::pbetabinom(q = 884.0, size = 2425, prob = 0.374491636284026, rho = 9.192015e-05)
I get the following probability result:

0.1849791

But when I use the scipy package

from scipy.stats import betabinom
betabinom.cdf(884.0, 2425, 0.374491636284026, 9.192015e-05)
then i get the following result:

0.00018973589125312118

does anyone have any idea if I can find a package in Python that would yeild concordant results? Thanks a lot for your time.

Upvotes: 1

Views: 227

Answers (1)

Stéphane Laurent
Stéphane Laurent

Reputation: 84649

That's because the two implementations use a different parametrization.

The Beta-binomial distribution is usually parametrized by the two shape parameters a and b of the Beta distribution. But VGAM uses prob=a/(a+b) and rho=1/(1+a+b).

Then here is how to get the same result:

from scipy.stats import betabinom

prob = 0.374491636284026
rho = 9.192015e-05

a = prob * (1/rho - 1)
b = 1/rho - 1 - a

betabinom.cdf(884.0, 2425, a, b)

EDIT

VGAM also provides the Beta-binomial distribution parameterized with a and b:

size <- 10
a <- 2; b <- 4

library(VGAM)
pbetabinom.ab(5, size, a, b)
# 0.8181818

You can also use the SuppDists package as follows:

library(SuppDists)
pghyper(5, -a, size, -a-b)
# 0.8181818

Upvotes: 1

Related Questions