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?
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)
This is equivalent to:
p = 1 / (1 + alpha * mu) n = 1 / alpha
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!