St · Statistics & Probability

How to Find the MLEs of a Negative Binomial Distribution

Updated 13 October 2026

At a glance

  1. 1. Choose a convention

    Here, X counts failures before r successes, and p is the probability of success on each trial.

  2. 2. Fix the size

    If r is known, estimate p using the sample mean: p-hat equals r divided by r plus the sample mean.

  3. 3. Estimate both parameters

    If r is unknown, substitute the estimate of p into the likelihood and solve the size score equation numerically.

  4. 4. Check the limit

    A very large estimated size approaches a Poisson model; check the profile likelihood if the data are not overdispersed.

The maximum-likelihood estimates depend on which negative-binomial convention you use and whether the size parameter is known. This article uses the convention that each observation counts failures before the rrth success. It gives the closed-form estimate when rr is fixed and the equation to solve when both parameters are unknown.

Model and likelihood

Let X1,…,XnX_1,\ldots,X_n be independent observations, where each XiX_i is the number of failures before rr successes. Write pp for the success probability. The probability mass function is

P(X=x)=(x+r−1x)pr(1−p)x,x=0,1,2,…P(X=x)=\binom{x+r-1}{x}p^r(1-p)^x,\qquad x=0,1,2,\ldots

For positive integer rr, the binomial coefficient has its usual meaning. In estimation, it is also common to allow a positive real-valued size parameter rr, using the gamma-function extension. Under this parameterization,

E[X]=r(1−p)p.\mathbb{E}[X]=\frac{r(1-p)}{p}.

For observations x1,…,xnx_1,\ldots,x_n, let S=∑i=1nxiS=\sum_{i=1}^n x_i and let xˉ=S/n\bar{x}=S/n. The likelihood is

L(r,p)=∏i=1n(xi+r−1xi)pnr(1−p)S.L(r,p)=\prod_{i=1}^n \binom{x_i+r-1}{x_i}p^{nr}(1-p)^S.

The combinatorial factors do not depend on pp, which makes its estimate straightforward when rr is fixed.

MLE of pp when rr is known

The part of the log-likelihood involving pp is

ℓ(p)=nrlog⁡p+Slog⁡(1−p)+constant.\ell(p)=nr\log p+S\log(1-p)+\text{constant}.

Differentiate and set the result to zero:

dℓdp=nrp−S1−p=0.\frac{d\ell}{dp}=\frac{nr}{p}-\frac{S}{1-p}=0.

Solving gives

p^=nrnr+S=rr+xˉ.\hat{p}=\frac{nr}{nr+S}=\frac{r}{r+\bar{x}}.

Thus, for known rr, the MLE of the success probability is the size divided by the size plus the sample mean. The fitted mean is r(1−p^)/p^=xˉr(1-\hat{p})/\hat{p}=\bar{x}. If S=0S=0, this formula gives the boundary estimate p^=1\hat{p}=1. If the parameter space is restricted to 0<p<10<p<1, the likelihood instead has a supremum as pp approaches 1, but no interior MLE.

MLE when both rr and pp are unknown

If S=0S=0, all observations are zero. The likelihood is maximized at the boundary p=1p=1 if that value is allowed, and every positive rr gives the same likelihood, so rr is not identified. If 0<p<10<p<1 is required, the likelihood supremum is approached as pp tends to 1.

For S>0S>0, for each proposed value of rr, the maximizing value of pp is still r/(r+xˉ)r/(r+\bar{x}). Substitute this into the log-likelihood, then solve the score equation for rr:

∑i=1n[ψ(xi+r)−ψ(r)]+nlog⁡(rr+xˉ)=0,\sum_{i=1}^n\left[\psi(x_i+r)-\psi(r)\right] +n\log\left(\frac{r}{r+\bar{x}}\right)=0,

where ψ\psi is the digamma function, the derivative of log⁡Γ\log\Gamma. This equation generally has no closed-form solution, so use a numerical root finder or maximize the profile log-likelihood directly. A finite root need not exist: compare the profile likelihood with its limit as rr tends to infinity, which corresponds to a Poisson model with mean xˉ\bar{x}. If that limit is favored, there is no finite-rr MLE under the negative-binomial model alone. After finding a finite r^\hat{r}, calculate

p^=r^r^+xˉ.\hat{p}=\frac{\hat{r}}{\hat{r}+\bar{x}}.

When the observations are nonnegative integers, the digamma differences can be written as finite sums:

ψ(xi+r)−ψ(r)=∑j=0xi−11r+j.\psi(x_i+r)-\psi(r)=\sum_{j=0}^{x_i-1}\frac{1}{r+j}.

For an observation equal to zero, this sum is empty and contributes zero. This form can make numerical evaluation easier.

Worked example

Suppose the observed failure counts are 0,0,2,60,0,2,6, and both parameters are to be estimated. There are n=4n=4 observations and xˉ=2\bar{x}=2. The score equation becomes

2r+2r+1+1r+2+1r+3+1r+4+1r+5+4log⁡(rr+2)=0.\frac{2}{r}+\frac{2}{r+1}+\frac{1}{r+2}+\frac{1}{r+3}+\frac{1}{r+4}+\frac{1}{r+5} +4\log\left(\frac{r}{r+2}\right)=0.

Numerically, its solution is approximately r^=0.495\hat{r}=0.495. Substituting this into the formula for pp gives

p^=0.4950.495+2≈0.198.\hat{p}=\frac{0.495}{0.495+2}\approx 0.198.

The fitted mean is approximately 0.495(1−0.198)/0.198=20.495(1-0.198)/0.198=2, matching the sample mean, as expected. In practice, a software optimizer should also be checked for convergence and for whether it found a maximum rather than another stationary point.

If your convention is different

Some sources define a negative-binomial variable as the number of successes before a fixed number of failures, or write the model in terms of its mean μ\mu and size rr. Under the mean-size form,

P(X=x)=Γ(x+r)Γ(r)x!(rr+μ)r(μr+μ)x.P(X=x)=\frac{\Gamma(x+r)}{\Gamma(r)x!} \left(\frac{r}{r+\mu}\right)^r \left(\frac{\mu}{r+\mu}\right)^x.

For fixed rr, the MLE of μ\mu is xˉ\bar{x}. This is the same result expressed in different parameters: μ=r(1−p)/p\mu=r(1-p)/p. Always check what the variable counts and which probability is called pp before applying a formula.

Common mistakes

  • Swapping pp and 1−p1-p. In the convention used here, pp is the probability of success, while the observed count is failures.
  • Treating the size estimate as closed form. The estimate of pp is explicit for fixed rr, but estimating both parameters usually requires numerical optimization.
  • Using the wrong mean. The sample mean estimates r(1−p)/pr(1-p)/p, not pp itself.
  • Ignoring the Poisson limit. As rr grows without bound while the mean stays fixed, the negative binomial approaches a Poisson distribution. If the profile likelihood is maximized at this limit, there is no finite-size MLE under the negative-binomial model alone. Inspect the profile likelihood instead of forcing a finite estimate.

References

  1. Discrete Distributions, 3rd edition — Norman L. Johnson, Adrienne W. Kemp, and Samuel Kotz
  2. Statistical Inference, 2nd edition — George Casella and Roger L. Berger

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.