logo

Negative Binomial Distribution 📂Probability Distribution

Negative Binomial Distribution

Definition 1

pmf10 pmf20

Given rNr \in \mathbb{N} and p(0,1]p \in (0,1], a discrete probability distribution NB(r,p)\text{NB}(r,p) with the following probability mass function is called the Negative Binomial Distribution. p(x)=(r+x1x1)pr(1p)x,x=0,1,2, p(x) = \binom{r+x-1}{x-1} p^{r}(1-p)^{x} \qquad, x = 0,1,2,\cdots

Basic Properties

Moment Generating Function

  • [1]: m(t)=[p1(1p)et]r,t<log(1P)m(t) = \left[ {{ p } \over { 1 - (1-p) e^{t} }} \right]^{r} \qquad , t < -\log (1-P)

Mean and Variance

  • [2]: If XNB(r,p)X \sim \text{NB}(r, p), then E(X)=r(1p)pVar(X)=r(1p)p2 \begin{align*} E(X) =& {{ r (1-p) } \over { p }} \\ \Var(X) =& {{ r (1-p) } \over { p^{2} }}\end{align*}

Description

The negative binomial distribution is concerned with the number of trials needed for an event with a probability pp to occur rr times. For example, consider how many times one must flip a coin until it lands on heads twice. Given that the probability of landing on heads is 5050%, it would take about two flips to get heads once, and needing that to happen one more time gives us an expected value of 44.

Intuitively, the negative binomial distribution can be seen as a generalization of the geometric distribution with the number of successes rr generalized. In fact, when the number of successes is one, i.e., r=1r = 1, it exactly becomes the geometric distribution.

Naming

The reason for calling it a negative binomial distribution is because the shape of its probability mass function is related to the negative binomial coefficient.

Theorem

Generalization of Geometric Distribution

  • [b]: If Y=X1++XrY = X_{1} + \cdots + X_{r} and XiiidGeo(p)X_{i} \overset{\text{iid}}{\sim} \text{Geo}(p), then YNB(r,p)Y \sim \text{NB}(r,p)

Proof

[1]

Negative Binomial Coefficient: (1)k(rk)=(r+k1k) (-1)^{k} \binom{-r}{k} = \binom{r + k - 1}{ k }

m(t)=x=0etxp(x)=x=0etx(r+x1x)pr(1p)x=prx=0(rx)(1)x[(1p)et]x=prx=0(rx)[(1p)et]x \begin{align*} m(t) =& \sum_{x=0}^{\infty} e^{tx} p(x) \\ =& \sum_{x=0}^{\infty} e^{tx} \binom{r+x-1}{x} p^{r} (1-p)^{x} \\ =& p^{r}\sum_{x=0}^{\infty} \binom{-r}{x} (-1)^{x} \left[ (1-p) e^{t} \right]^{x} \\ =& p^{r}\sum_{x=0}^{\infty} \binom{-r}{x} \left[ - (1-p) e^{t} \right]^{x} \end{align*}

Binomial Series: If x<1|x| < 1, then for αC\alpha \in \mathbb{C}, (1+x)α=k=0(αk)xk\displaystyle (1 + x )^{\alpha} = \sum_{k=0}^{\infty} \binom{\alpha}{k} x^{k}

Based on the binomial series, since x=0(rx)[(1p)et]x=[1(1p)et]r\displaystyle \sum_{x=0}^{\infty} \binom{-r}{x} \left[ - (1-p) e^{t} \right]^{x} = \left[ 1 - (1-p) e^{t} \right]^{-r}, m(t)=[p1(1p)et]r,t<log(1P) m(t) = \left[ {{ p } \over { 1 - (1-p) e^{t} }} \right]^{r} \qquad , t < -\log (1-P)

[2]

Using the concept of Generalization of Geometric Distributions.

[b]

When the probability mass function of a geometric distribution is defined as p(x)=p(1p)x,x=0,1,2,p(x) = p (1-p)^{x} \qquad,x=0,1,2,\cdots, its moment generating function is as follows: m(t)=p(1(1p)et)1 m(t) = p \left( 1 - (1-p) e^{t} \right)^{-1} Since the random variables X1,X2,,XrX_1, X_2, \cdots , X_r, which are mutually independent, follow Geo(p)\text{Geo} (p), the moment generating function for YY is MY(t)=E(eYt)=E(e(X1+X2++Xr)t)=E(eX1t)E(eX2t)E(eXrt)=i=1rp(1(1p)et)1=pr{(1(1p)et)}r \begin{align*} M_Y(t) =& E(e^{Yt}) \\ =& E(e^{(X_1+X_2+\cdots+X_r)t}) \\ =& E(e^{X_1 t}) E(e^{X_2 t}) \cdots E(e^{X_r t}) \\ =& \prod_{i=1}^r p { (1 - (1-p) e^t ) }^{-1} \\ =& p^r \left\{ (1 - (1-p) e^t ) \right\}^{-r} \end{align*} This is identical to the moment generating function for the negative binomial distribution NB(r,p)\text{NB}(r,p), therefore YNB(r,p)Y \sim \text{NB}(r,p)

Code

Below is a Julia code to show the probability mass function of the negative binomial distribution as a gif.

@time using LaTeXStrings
@time using Distributions
@time using Plots

cd(@__DIR__)

x = 0:20
P = collect(0.2:0.01:0.8); append!(P, reverse(P))

animation = @animate for p ∈ P
    scatter(x, pdf.(NegativeBinomial(5, p), x),
     color = :black, markerstrokecolor = :black,
     label = "r = 5, p = $(rpad(p, 4, '0'))", size = (400,300))
    xlims!(0,20); ylims!(0,0.5); title!(L"\mathrm{pmf\,of\,NB}(5, p)")
end
gif(animation, "pmf5.gif")

animation = @animate for p ∈ P
    scatter(x, pdf.(NegativeBinomial(10, p), x),
     color = :black, markerstrokecolor = :black,
     label = "r = 10, p = $(rpad(p, 4, '0'))", size = (400,300))
    xlims!(0,20); ylims!(0,0.5); title!(L"\mathrm{pmf\,of\,NB}(10, p)")
end
gif(animation, "pmf10.gif")

  1. Hogg et al. (2013). Introduction to Mathematical Statistcs(7th Edition): p145. ↩︎