Negative Binomial Calculator

Model overdispersed count data.

Examples:

Enter parameters to calculate negative binomial probabilities

Use the negative binomial distribution when you're counting how many attempts it takes to achieve a certain number of successes, or when you have count data that's more variable than the Poisson distribution allows. It's commonly used in biology for modeling species abundance, in insurance for claim counts, and in quality control for defect analysis—anywhere counts show more variability than expected.

What Is the Negative Binomial Distribution?

The negative binomial distribution models the number of trials needed to achieve a specified number of successes, or equivalently, the number of failures before achieving r successes.

Also used for: Count data with overdispersion (variance > mean), which the Poisson cannot handle.

Two Parameterizations

Type 1: Trials Until r Successes

Question: "How many trials until I get r successes?"

P(X=k)=(k−1r−1)pr(1−p)k−rP(X = k) = \binom{k-1}{r-1} p^r (1-p)^{k-r}

Where:

  • X = number of trials (minimum r)
  • k = total trials
  • r = required successes
  • p = probability of success per trial

Type 2: Failures Before r Successes

Question: "How many failures before r successes?"

P(X=k)=(k+r−1k)pr(1−p)kP(X = k) = \binom{k+r-1}{k} p^r (1-p)^k

Where:

  • X = number of failures (minimum 0)
  • k = number of failures
  • r = required successes
  • p = probability of success per trial

Type 3: Mean-Dispersion Form (Overdispersed Counts)

P(X=k)=(k+r−1k)(rr+μ)r(μr+μ)kP(X = k) = \binom{k+r-1}{k} \left(\frac{r}{r+\mu}\right)^r \left(\frac{\mu}{r+\mu}\right)^k

Where:

  • μ = mean
  • r = dispersion parameter (smaller r = more overdispersion)

Example: Trials Until Success

Scenario: A basketball player has 70% free-throw success rate. What's the probability of needing exactly 5 shots to make 3 baskets?

Parameters:

  • r = 3 (need 3 successes)
  • p = 0.70
  • k = 5 (total shots)

P(X=5)=(42)(0.70)3(0.30)2P(X = 5) = \binom{4}{2}(0.70)^3(0.30)^2 =6×0.343×0.09=0.185= 6 \times 0.343 \times 0.09 = 0.185

Interpretation: 18.5% chance of needing exactly 5 shots.

Example: Overdispersed Counts

Scenario: Daily emergency room visits. Mean = 20, but variance = 45 (much greater than mean).

Poisson assumes variance = mean, so it's inappropriate.

Negative binomial with μ = 20 and r = 16 (estimated from data): Variance=μ+μ2r=20+40016=45\text{Variance} = \mu + \frac{\mu^2}{r} = 20 + \frac{400}{16} = 45 ✓

Mean and Variance

For "Failures Before r Successes" Version

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

Var(X)=r(1−p)p2\text{Var}(X) = \frac{r(1-p)}{p^2}

For "Overdispersed Counts" Version

E[X]=μE[X] = \mu

Var(X)=μ+μ2r\text{Var}(X) = \mu + \frac{\mu^2}{r}

Key insight: Variance always exceeds mean (overdispersion).

Relationship to Other Distributions

Special Case: Geometric Distribution

Negative binomial with r = 1 is the geometric distribution (trials until first success).

Limiting Case: Poisson Distribution

As r → ∞, negative binomial approaches Poisson with parameter μ.

Mixture Interpretation

Negative binomial can be viewed as a Poisson distribution where the rate parameter itself follows a gamma distribution (Poisson-gamma mixture).

Detecting Overdispersion

Visual Check

Compare histogram of counts to Poisson with same mean.

Variance-to-Mean Ratio

Dispersion=VarianceMean\text{Dispersion} = \frac{\text{Variance}}{\text{Mean}}

  • Ratio = 1: Poisson appropriate
  • Ratio > 1: Overdispersion → consider negative binomial
  • Ratio >> 1: Strong overdispersion

Statistical Test

In Poisson regression, test if dispersion parameter = 1.

When to Use Negative Binomial

Counting Processes

  • Number of failures before success
  • Trials until quota reached
  • Waiting for rare events

Overdispersed Count Data

  • Disease counts with clustering
  • Accident data
  • Insurance claims
  • Ecological counts (species abundance)
  • Website hits with viral effects

Whenever Poisson Doesn't Fit

If Poisson model shows overdispersion, try negative binomial.

Negative Binomial Regression

Model count data with covariates:

log⁡(μi)=β0+β1x1i+β2x2i+⋯\log(\mu_i) = \beta_0 + \beta_1 x_{1i} + \beta_2 x_{2i} + \cdots

With negative binomial variance:

Var(Yi)=μi+μi2r\text{Var}(Y_i) = \mu_i + \frac{\mu_i^2}{r}

Use when: Poisson regression shows overdispersion (deviance >> df).

Cumulative Probabilities

P(X≤k)=∑i=0kP(X=i)P(X \leq k) = \sum_{i=0}^{k} P(X = i)

For practical calculations, use software or statistical tables.

Applications

Quality Control

Number of inspections until finding r defective items.

Clinical Trials

Number of patients screened until finding r eligible subjects.

Epidemiology

Disease counts when clustering or heterogeneity exists.

Ecology

Species abundance data (often highly overdispersed).

Insurance

Claim counts per policyholder.

Software Engineering

Bug counts in code modules.

Example: Hospital Readmissions

Data: 30-day readmission counts for 500 patients

ReadmissionsObservedPoisson ExpectedNegBin Expected
0350303348
1100152102
2303831
3+20719

Negative binomial fits much better due to overdispersion from unobserved patient heterogeneity.

Estimating Parameters

Method of Moments

p^=XˉVar(X)\hat{p} = \frac{\bar{X}}{\text{Var}(X)} r^=Xˉ2Var(X)−Xˉ\hat{r} = \frac{\bar{X}^2}{\text{Var}(X) - \bar{X}}

Maximum Likelihood

More accurate; requires iterative computation.

Confidence Intervals

For estimated probabilities, use exact methods for small samples or normal approximation for large samples.

Reporting Results

For regression:

"Negative binomial regression was used due to significant overdispersion in the Poisson model (dispersion = 2.8). Hospital readmission counts were significantly associated with age (IRR = 1.03 per year, 95% CI: 1.01-1.05, p = .003) and prior admissions (IRR = 1.45, 95% CI: 1.22-1.72, p < .001)."

For probability calculation:

"Under a negative binomial model with r = 3 successes and p = 0.70, the probability of needing exactly 5 trials is 18.5%."

Common Mistakes

Using Poisson When Overdispersed

Check variance-to-mean ratio. If > 1.5, consider negative binomial.

Confusing Parameterizations

Be clear whether counting trials, failures, or using mean-dispersion form.

Ignoring Zero-Inflation

If there are excess zeros beyond what negative binomial predicts, consider zero-inflated models.

Wrong Variance Formula

Variance formula differs by parameterization—use the one matching your formulation.

Comparison with Poisson

AspectPoissonNegative Binomial
Variance= Mean> Mean
Parameters1 (λ)2 (μ, r)
FlexibilityLessMore
Use caseHomogeneous countsOverdispersed counts
InterpretationRandom eventsClustering/heterogeneity

Historical Context

The negative binomial distribution was studied by Pascal in the 17th century in the context of waiting for successes in repeated trials.

Its application to overdispersed count data developed in the 20th century, particularly through the work of Greenwood and Yule (1920) in epidemiology and Fisher in genetics.

Related Calculations

Summary

The negative binomial distribution models either the number of trials until r successes or overdispersed count data where variance exceeds mean. It's more flexible than Poisson, accommodating clustering and heterogeneity in count data. Key applications include quality control (waiting for r defects), epidemiology (disease clustering), and any count data failing the Poisson variance assumption. The dispersion parameter r controls the degree of overdispersion—smaller r means more overdispersion. Use negative binomial regression when Poisson regression shows overdispersion.