Home > Backend Development > Python Tutorial > CDF of negative binomial with mu and alpha in python

CDF of negative binomial with mu and alpha in python

WBOY
Release: 2024-02-08 22:09:15
forward
886 people have browsed it

python 中带有 mu 和 alpha 的负二项式的 CDF

Question content

I have some count data, somewhat similar to a Poisson distribution, but too spread out. I fitted a negative binomial glm model in python using statsmodels and selected the alpha value (i.e. the dispersion parameter). I then apply the model to the test set to make some predictions. I now want to compute the cumulative distribution function that calculates the probability of a random variable X<=9 given the output prediction mu (i.e. 7.8) and a predetermined alpha value (i.e. 0.2).

scipy documentation (https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.nbinom.html) suggests that I can use nbinom.cdf(k, n, p) but when I only How do I get the values ​​of n and p when mu and alpha are given?


Correct answer


p and n are related to alpha and mu, the relationship is given in the document you provided:

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

This is equivalent to:

p = 1 / (1 + alpha * mu)
n = 1 / alpha
Copy after login

The above is the detailed content of CDF of negative binomial with mu and alpha in python. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template