NegativeBinomial: Create a negative binomial distribution

View source: R/NegativeBinomial.R

NegativeBinomialR Documentation

Create a negative binomial distribution


A generalization of the geometric distribution. It is the number of failures in a sequence of i.i.d. Bernoulli trials before a specified target number (r) of successes occurs.


NegativeBinomial(size, p = 0.5, mu = size)



The target number of successes (greater than 0) until the experiment is stopped. Denoted r below.


The success probability for a given trial. p can be any value in [0, 1], and defaults to 0.5.


Alternative parameterization via the non-negative mean of the distribution (instead of the probability p), defaults to size.


We recommend reading this documentation on, where the math will render with additional detail and much greater clarity.

In the following, let X be a negative binomial random variable with success probability p = p.

Support: \{0, 1, 2, 3, ...\}

Mean: \frac{(1 - p) r}{p} = μ

Variance: \frac{(1 - p) r}{p^2}

Probability mass function (p.m.f.):

f(k) = (k+r-1)!/(k!(r-1)!) p^r (1-p)^k

Cumulative distribution function (c.d.f.):

Omitted for now.

Moment generating function (m.g.f.):

\frac{p^r}{(1 - (1-p) e^t)^r}, t < -\log (1-p)

Alternative parameterization: Sometimes, especially when used in regression models, the negative binomial distribution is parameterized by its mean μ (as listed above) plus the size parameter r. This implies a success probability of p = r/(r + μ). This can also be seen as a generalization of the Poisson distribution where the assumption of equidispersion (i.e., variance equal to mean) is relaxed. The negative binomial distribution is overdispersed (i.e., variance greater than mean) and its variance can also be written as μ + 1/r μ^2. The Poisson distribution is then obtained as r goes to infinity. Note that in this view it is natural to also allow for non-integer r parameters. The factorials in the equations above are then expressed in terms of the gamma function.


A NegativeBinomial object.

See Also

Other discrete distributions: Bernoulli(), Binomial(), Categorical(), Geometric(), HurdleNegativeBinomial(), HurdlePoisson(), HyperGeometric(), Multinomial(), Poisson(), ZINegativeBinomial(), ZIPoisson(), ZTNegativeBinomial(), ZTPoisson()



X <- NegativeBinomial(size = 5, p = 0.1)

random(X, 10)

pdf(X, 50)
log_pdf(X, 50)

cdf(X, 50)
quantile(X, 0.7)

## alternative parameterization of X
Y <- NegativeBinomial(mu = 45, size = 5)
cdf(Y, 50)
quantile(Y, 0.7)

distributions3 documentation built on Sept. 7, 2022, 5:07 p.m.