The guide
When the success rate is itself uncertain, counts spread wider than a binomial allows
A beta-binomial count is a binomial whose success rate is drawn from a beta distribution. That one change inflates the variance by an exact factor and makes prediction a different job from estimation.
- 0.065934 chance of no success at n 10, 2 and 3; a binomial gives 0.006047
- 2.5 times the variance of that table against a binomial with the same mean
- Beta(9, 6) posterior after 7 successes in 10 from a Beta(2, 3) prior
- 0.366099 chance of 4 or more successes in the next 5 trials
- 256 orders the draw orders of an 8-draw urn, each one counted exactly
Read the full guide Fold the guide
One rate that is not known
Toss a coin ten times and count the heads. If the coin’s chance of heads is known, the count follows a binomial distribution and every familiar table applies.
Now suppose the chance is not known. Each batch of ten tosses comes from a different coin, a different machine or a different family, and the chance for that batch is itself a random draw. The beta-binomial distribution describes exactly this: a binomial count in which the success probability is drawn from a beta distribution. The beta distribution suits the job because it lives between 0 and 1 and is conjugate to the binomial, so the mixing can be done in closed form instead of by simulation. Wikipedia’s article on the beta-binomial distribution gives the formula the tool follows.
The chance of exactly k successes in n trials is C(n, k) times B(k + alpha, n - k + beta) divided by B(alpha, beta), where B is the beta function, a ratio of gamma functions. With n = 10, alpha = 2 and beta = 3 the table runs 0.065934, 0.109890, 0.134865, 0.143856, 0.139860, 0.125874, 0.104895, 0.079920, 0.053946, 0.029970, 0.010989. It adds to exactly 1.
The two shapes are not the mean. The mean success rate is alpha divided by alpha + beta, here 2/5. Mixing the two up changes every number in the table.
Why the variance grows by an exact factor
The variance of the count is n alpha beta (alpha + beta + n) divided by (alpha + beta) squared times (alpha + beta + 1). Wikipedia rewrites it as n p (1 - p) [1 + (n - 1) rho], with p = alpha / (alpha + beta) and rho = 1 / (alpha + beta + 1). The first part is the variance of a binomial with that mean. The bracket is the extra, and it equals the overdispersion factor (alpha + beta + n) / (alpha + beta + 1).
In the worked example the mean is 4, so p = 0.4 and a plain binomial has variance 10 times 0.4 times 0.6, which is 2.4. The beta-binomial variance is 6. That is 2.5 times larger, because rho = 1/6: trials that share one uncertain rate tend to succeed or fail together. The intraclass correlation article describes this as how strongly units in the same group resemble each other.
The tails show it best. A binomial with the same mean gives 0.006047 for no success at all. The beta-binomial gives 0.065934, almost eleven times as much. For ten successes the binomial gives 0.000105 and the beta-binomial 0.010989, about 105 times as much. A binomial forecast calls such runs freak events. The beta-binomial calls them ordinary.
With one trial the factor is exactly 1. A single yes-or-no count cannot show overdispersion, and the overdispersion article says the idea makes sense only for n above 1.
Shapes below 1 give a different picture. A beta distribution with both shapes below 1 is U-shaped, so the rate is usually near 0 or near 1 and the counts pile up at the ends. With alpha = beta = 0.5 and n = 10 the chance of 0 successes is 0.176197 and the chance of 5 is only 0.060562.
Real data show the effect at a modest size. The beta-binomial article lists the number of male children among the first 12 children in 6,115 families recorded in nineteenth century Saxony. From the table’s counts the mean is 6.2306 and the variance 3.4893, against 2.9956 for a binomial with that mean: a factor of 1.165, with rho about 0.0150. Matching those two numbers gives alpha near 34.135 and beta near 31.608.
A small rho still matters at the ends: a binomial expects 0.9 families with no boys and 2.3 with only boys, and the records hold 3 and 7.
One caution from that example. The page prints the moments as 6.23 and 42.31, and feeding those rounded figures into the same formulas gives alpha 33.59 and beta 31.11, not 34.135 and 31.608. When the variance sits only a little above the binomial value, the fit needs many digits of the sample variance.
The urn that builds the same table
Put alpha red and beta black balls in an urn. Draw one ball at random, return it, and add one more ball of the same colour. Repeat n times. Wikipedia’s article on the Polya urn model describes this rule, and its self-reinforcing character: a colour that is drawn early becomes more likely later. Drawing with simple replacement, with no extra ball, gives the binomial instead.
Take alpha = 2, beta = 3 and four draws. There are 16 orders of red and black. The order red, red, black, red has chance 2/5 times 3/6 times 3/7 times 4/8, which is 3/70. Every order with three reds has the same chance, and there are four such orders, so the total for three reds is 4 times 3/70, or 6/35. The beta-binomial formula for n = 4 gives 6/35 as well.
The Polya urn article states both facts: the orders that end with the same colour counts are equally likely, and the number of one colour drawn follows the beta-binomial. It writes the probability with rising factorials, the products x (x + 1) and so on that the article on falling and rising factorials defines. The tool uses the same form, so the whole table is whole-number arithmetic.
A pleasant special case: start with one ball of each colour and every count from 0 to n has chance 1/(n + 1). That is the beta-binomial with both shapes equal to 1, a discrete uniform distribution. The tool enumerates every order for up to 8 draws, 256 orders at most, and checks each total against the formula.
From a prior to a prediction
In Bayesian terms a Beta(alpha, beta) prior for the rate behaves like alpha and beta pseudo-observations, as the conjugate prior article puts it. After k successes in m trials the posterior is Beta(alpha + k, beta + m - k). A Beta(2, 3) prior and 7 successes in 10 trials give Beta(9, 6), with mean 3/5.
That posterior describes the rate. It answers what the rate probably is. It does not answer how many successes the next five trials will bring. For that you average the binomial over the posterior, and the result is a beta-binomial with the posterior’s shapes: BetaBin(5, 9, 6). Its table is 0.021672, 0.097523, 0.216718, 0.297988, 0.255418, 0.110681, and the chance of at least 4 successes in 5 is 473/1292, which is 0.366099.
The tempting shortcut is to take the posterior mean 3/5 and use a binomial with 5 trials. That gives 0.336960 for at least 4 successes, and a variance of 6/5 instead of 3/2. The article on the posterior predictive distribution warns that plugging in a single best estimate ignores the uncertainty about the parameter, so the predictive distribution comes out too narrow and extreme values get too little probability. Posterior for the rate, predictive for the count: two objects, two tables, and the tool keeps them apart.
Fitting the shapes, and what this cannot do
The method of moments sets the model’s mean and variance equal to the sample’s and solves. For counts out of n with sample mean mu and variance v, take p = mu / n, rho = (v / (n p (1 - p)) - 1) / (n - 1), alpha + beta = 1 / rho - 1 and alpha = p (alpha + beta). From mean 4 and variance 6 with n = 10 this returns rho = 1/6, alpha = 2 and beta = 3, the worked example again.
The beta-binomial article notes that the estimates can come out nonsensically negative when the data are not overdispersed, so the tool refuses with a plain message when the variance is not above the binomial value.
For very large shapes the rate is almost known and the binomial returns. With alpha = beta = 2000 and n = 10 the total variation distance from a binomial with probability one half is 0.00061.
The table is exact for every input the tool accepts: shapes written as whole numbers, decimals or fractions, up to 12 characters each, with n up to 1,000. Exact sums use BigInt, which holds integers of any size, and the heavy work runs in a web worker so the page stays responsive. Counts above 999 are written with separators by the browser’s own number formatter, Intl.NumberFormat. A second, independent method in ordinary doubles agreed with the exact table to within 3e-13 in every test, extreme shapes included. The density curves use the Lanczos approximation of the log gamma function, which matched Python’s math.lgamma to 1.4e-15.
What the tool cannot do is just as plain. It does not fit alpha and beta with unknown hyper-parameters, run a regression, or handle more than two outcomes: the Dirichlet-multinomial article calls the beta-binomial its one-dimensional version, and that larger case is not here. It does not test whether data are overdispersed. And a variance taken from a handful of batches is itself uncertain, so a fit is only as steady as the sample behind it. If the rate drifts through time, or the trials are not exchangeable, no table on this page repairs the forecast.
Sources
Every source consulted for this guide. Links checked November 11, 2026.
- Beta-binomial distribution Wikipedia
- Beta distribution Wikipedia
- Binomial distribution Wikipedia
- Conjugate prior Wikipedia
- Polya urn model Wikipedia
- Posterior predictive distribution Wikipedia
- Overdispersion Wikipedia
- Method of moments (statistics) Wikipedia
- Beta function Wikipedia
- Intraclass correlation Wikipedia
- Dirichlet-multinomial distribution Wikipedia
- Falling and rising factorials Wikipedia
- Lanczos approximation Wikipedia
- Web Workers API MDN Web Docs
- BigInt MDN Web Docs
- Intl.NumberFormat MDN Web Docs