Created
January 27, 2021 16:06
-
-
Save omarfsosa/12d2e0f25577b25668cdc14c89713824 to your computer and use it in GitHub Desktop.
Sample from a negative binomial in terms of mean and precision parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def neg_binomial_2_rng(mu, phi, size=None): | |
""" | |
RNG for the negative binomial parametrised in terms | |
of the mean and the precision. | |
mean = mu | |
variance = mu + (mu**2)/phi | |
""" | |
tau = np.random.gamma(phi, mu/phi, size=size) | |
return np.random.poisson(tau) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment