# Generate pseudo-random overdispersed Poisson numbers

I have multiple sets of data which conform to overdispersed Poisson distributions which I can model with the alternative parameterization of a negative binomial distribution ($\mu$ and $D$ instead of $p$ and $r$).

I am interested in being able to generate pseudo-random numbers from these distributions but cannot find the ICDF to do so. I also tried to look for how R did it but it's buried in the Cpp deep enough that I get lost (not a C++ programmer).

How can I convert a psuedo-random uniform number into a pseudo-random negative binomial number with parameters $\mu$=mean and $D$=dispersion?

clarification and thanks

Thank you for the answer and comments pointing me to rnbinom in R. That in combination with fitdistr from the MASS package do exactly what I want. However my interest is in generating these random numbers in SQL Server without leveraging a .NET language.

That being said, I found the stata code interesting, but it's parameterized for $p$ and $r$ and perhaps I'm just very dense, but I'm not sure how to convert my $\mu$ and $D$ back to $p$ and $r$.

All that being said, I have found a JSTOR article that about negative binomial distributions with the specific application as an overdispersed Poisson. I'll see if I can conjure a CDF from there.

• Can you either write or give a link to the exact for of the negative binomial you are using? I am unfamiliar with it when parameterized with $\mu$ and $D$. – Dan Sep 4 '14 at 16:38
• Also, not sure if this fact helps but "Negative Binomial Random Variable as a sum of independent Geometric Random Variables" – Dan Sep 4 '14 at 16:44
• Is there a reason you can't use ?rnbinom? – gung - Reinstate Monica Sep 4 '14 at 16:49
• @gung, how do you specify the overdispersion parameter using rnbinom() in R – Dan Sep 4 '14 at 17:09
• Also, if you are able to read or interpret STATA code here is a solution: ats.ucla.edu/stat/stata/code/discrete_rv_v2.htm – Dan Sep 4 '14 at 17:16

 # Negative Binomials with means fitted(fm) and theta = 4.5

• Thank you for this. Base R also has the rnbinom function which relates very well to the output from MASS's fitdistr which was invaluable for me in estimating the dispersion parameter. – Mark Sep 5 '14 at 0:46