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`

.

**Contents**hide

#### Best Answer

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:

- Solved – How to draw random samples from a negative binomial distribution in R?
- Solved – How to draw random samples from a negative binomial distribution in R?
- Solved – Generate random variables with negative binomial distribution in R
- Solved – How would you find the mean of the zero truncated Poisson distribution?
- Solved – Finding a pdf of an exponential distribution