Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CDF of a Negative Binomial with mu and alpha in python

I have some count data that somewhat resembles a poisson distribution but is overdispersed. I have fitted a negative binomial glm model in python using statsmodels with a chose value for alpha (i.e.dispersion parameter). I have then applied the model to a test set to make some predictions. I now want to calculate the cumulative distributiion function so that I can calculate the probability that a random variable X<=9 given my outputted prediction mu (i.e.7.8) and pre-determined value for alpha (i.e. 0.2).

The scipy documentation (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.nbinom.html) suggests that I can calculate this in python with nbinom.cdf(k, n, p) but how can i obtain the values of n and p, when all i have is mu and alpha?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

p and n are related to alpha and mu and the relation is given in the documentation you provide:

sigma_squared = mu + alpha * mu**2
p = mu / sigma_squared
n = mu**2 / (sigma_squared - mu)

which is equivalent to:

p = 1 / (1 + alpha * mu)
n = 1 / alpha
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading