Solved – How to draw random samples from a negative binomial distribution in R?

Let $X$ have the Negative Binomial distribution with parameters $r$ and $p$. The Negative Binomial distribution is a mixture distribution or compound distribution. That is $X$ is $text{Poisson}(lambda)$ where $lambda$ is randomly chosen from a $text{Gamma}(r, p/(1-p))$. Use this relation to write an R function for randomly drawing $n$ Negative Binomial random samples. Hint: Use the R functions rpois and rgamma.

If this is not a homework question, you're probably better off with the rnbinom function from stats. If you're lucky (I haven't checked) you can check it's source to see how the implementers did it.

Similar Posts:

Rate this post

Leave a Comment