Discrete distribution · also called Pólya urn distribution
Beta-binomial distribution
The number of successes in trials when the success probability is not fixed but varies from group to group as a Beta() variable: defects per batch when batches differ in quality, hits per player over a season, responders per clinic. It has the binomial's range but a wider spread (over-dispersion), and it is the posterior predictive distribution of a binomial count under a beta prior.
Beta-binomial probability calculator
P(X ≤ 4) = 0.594406
At the parameters set by the sliders. The shaded region on the plot is the probability; the dots on the CDF mark F at its ends. For a discrete distribution, < and ≤ differ.
PMF
CDF
mean 4 · variance 6 · sd 2.449
Formulas
| Parameters |
|
|---|---|
| Support | |
| PMF | |
| CDF | |
| Mean | |
| Variance |
With the variance is times , the over-dispersion factor; it tends to 1 (the binomial) as . is the beta function. With every count from 0 to is equally likely.
Worked example
The defect rate varies between production batches as Beta(2, 18), so it averages 10%. Ten parts are tested from one batch. What is the probability that none is defective?
A binomial with the average rate would give : when quality varies, clean batches and bad batches are both more common than a fixed rate suggests. answer checked by code
How it relates to others
- Mixture← Beta: A Binomial() count whose is itself Beta() is Beta-binomial(). It is also the posterior predictive of a binomial count under a beta prior. checked by code
- Limit→ Binomial: If with fixed, Beta-binomial() tends to Binomial(): the success rate stops varying. checked by code
- Special case→ Discrete uniform: Beta-binomial() is the discrete uniform on . checked by code
- Special case→ Bernoulli: Beta-binomial() is Bernoulli(): with one trial, a varying rate is indistinguishable from its average. checked by code
All the relationships, as a diagram →
In Python
from scipy import stats
import numpy as np
X = stats.betabinom(n=10, a=2, b=3)
X.pmf(2) # P(X = 2) = 0.1349
X.cdf(2) # P(X ≤ 2) = 0.3107
X.mean(), X.var() # 4, 6
X.ppf(0.95) # 95th percentile
X.rvs(size=10, random_state=0)
rng = np.random.default_rng(0)
rng.binomial(n=10, p=rng.beta(a=2, b=3, size=10))NumPy has no beta-binomial sampler: draw p from the beta, then a binomial with that p.
Choosing between this and its neighbours? Which distribution for count data? · Which distribution for proportions and probabilities? · Which prior distribution should I use?