### 20.4.4 Negative binomial distribution

##### The probability density function for the negative binomial distribution.

If you repeatedly perform an experiment with probability of success p, then, given an integer n, the probability of k failures that occur before you have n successes is given by the negative binomial distribution, which can be computed by

⎛ ⎜ ⎝ |
n+k−1
k
| ⎞ ⎟ ⎠
| pn(1−p)k. (2)

The negbinomial command finds the density function for the negative binomial distribution.

- negbinomial takes three arguments:
  - n and k, integers.
  - p, a probability (a real number between 0 and 1).
- negbinomial(n,k,p) returns the value of the negative binomial distribution, given in (2).

#### Example

negbinomial(4,2,0.5)

0.15625 |  |  |  |  |  |  |  |  |  |

Note that

⎛ ⎜ ⎝ |
n
k
| ⎞ ⎟ ⎠
| = |
n!
k! (n−k)!
| = |
n (n−1) … (n−k+1)
k!
| .

The second formula makes sense even if n is negative, and you can write

negbinomial(n,k,p)= |
⎛ ⎜ ⎝ |
−n
k
| ⎞ ⎟ ⎠
| pn (p−1)k,

from which the name negative binomial distribution comes from. This also makes it simple to determine the mean (n(1−p)/p) and variance (n(1−p)/p2). The negative binomial is also called the Pascal distribution (after Blaise Pascal) or the Pólya distribution (after George Pólya).

##### The cumulative distribution function for the negative binomial distribution.

The negbinomial_cdf command finds the cumulative distribution function for the negative binomial distribution.

- negbinomial_cdf takes three mandatory arguments and two optional arguments:
  - n, an integer.
  - p, a probability (between 0 and 1).
  - x, a number.
  - Optionally, y, a number.
- negbinomial_cdf(n,p,x) returns

  Prob(X ≤ x)=negbinomial(n,0,p)+⋯+negbinomial(n,⌊ x⌋,p).

- negbinomial_cdf(n,p,x,y) returns

  Prob(x ≤ X ≤ y)=negbinomial(n,⌈ x⌉,p)+⋯ + negbinomial(n,⌊ y⌋,p)

#### Examples

negbinomial_cdf(4,0.5,2)

0.34375 |  |  |  |  |  |  |  |  |  |

negbinomial_cdf(4,0.5,2,5)

0.40234375 |  |  |  |  |  |  |  |  |  |

##### The inverse distribution function for the negative binomial distribution.

The negbinomial_icdf command gives the inverse distribution function for the negative binomial distribution.

- negbinomial_icdf takes three arguments:
  - n, a positive integer.
  - p, a probability (a real number between 0 and 1).
  - h, a real number between 0 and 1.
- negbinomial_icdf(n,p,h) returns the value of the inverse distribution for the negative binomial distribution with n and probability p; namely, the smallest value of x for which Prob(X ≤ x) ≥ h.

#### Example

negbinomial_icdf(4,0.5,0.9)

8 |  |  |  |  |  |  |  |  |  |