The Beta-Binomial Model: A Ground-Up Reference
Building the Beta-Binomial model from coin flips, with intuition for priors, likelihood, and posterior distributions.
On this page
Bernoulli Trials and the Likelihood
Imagine that you have a coin that lands on heads with the probability . You flip it times and observe heads. The probability of seeing exactly heads given is the Binomial likelihood:
This is your data-generating process. If is known, you can compute how likely any outcome is. But in practice is unknown, and you want to infer it from data.
The maximum likelihood estimate is , which outputs a single number. However, the tradeoff here is that a point estimate like this doesn’t account for uncertainty. With Bayesian statistics, we keep the answer distribution based, allowing us to estimate the uncertainty involved with calculating the likeliness of an outcome.
The Beta Prior
Before seeing any data, you have beliefs about . If those beliefs are weak, you can choose a uniform (all events equally likely) prior or a very weak prior. This ensures that ultimately our decision is mostly informed by the data rather than shifted by our chosen prior.
The Beta distribution is a natural choice because it lives on and can encode many shapes with just two parameters:
The density is:
where is the Beta function (the normalizing constant here).
Alpha and beta are pseudocounts, basically imaginary prior observations. For example, behaves as if you have seen 2 heads and 5 tails before collecting real data.
| Prior shape | When to use |
|---|---|
| Uniform — no prior preference, all equally likely | |
| Belief that is high (coin biased toward heads) | |
| Belief that is low (coin biased toward tails) | |
| Strong prior certainty | |
| small | Weak prior — few pseudo-observations, so the data dominates quickly |
The mean of is , and the variance shrinks as the total pseudocount grows (intuitively this should make sense).
Conjugacy and the Posterior
The Beta distribution is conjugate to the Binomial likelihood. Conjugacy means the posterior is the same family as the prior. This is extremely useful because it means that multiplying our binomial likelihood by the prior Beta distribution just gives us another Beta distribution.
The update rule is strikingly simple:
Add the observed heads to , add the observed tails () to .
The posterior mean becomes:
which is a weighted average of the prior mean and the observed proportion . The weight is controlled by the total pseudocount . A larger prior sample size means the prior pulls harder against the data (exerting more influence on our results).
Using the Visualizer
Beta(2, 5) + 3 heads in 10 → Beta(5, 12)
posterior = Beta(α+k, β+n−k)
Read the full reference →The plot above (also on the homepage) lets you explore this update in real time.
and sliders (PRIOR curves). These set your prior Beta distribution. The dashed curve shows the prior density. Start with — a weak prior favoring tails. Increase both together to sharpen the prior. Increase alone to shift weight toward heads.
and sliders (POSTERIOR curves). These represent the data you observe. Set to the number of heads seen out of trials. The solid curve is the posterior — the prior updated by your data. When differs from the prior mean, the posterior shifts. When is small, the prior dominates. As grows, the posterior converges toward .
The formula caption below the sliders shows the exact posterior parameters:
Push to 30 with and a prior of — the posterior will sit between the prior mean () and the observed proportion (). With and , the prior pulls much harder.
The Extension
The Beta-Binomial is the simplest case of a pattern that repeats across Bayesian statistics:
- Choose a prior that captures what you know (or do not know) before seeing data
- Write down the likelihood of the data given the parameters
- Combine them via Bayes’ rule to get the posterior
The same recipe scales to linear regression (conjugate Normal-Inverse-Gamma priors), classification (Dirichlet-Multinomial), and Gaussian processes. It ultimately is the basic foundation of Bayesian inference. The ways in which we use Bayesian statistics are fundamentally just this loop repeated over and over in more domain specific contexts (drug discovery, clinical trials, personalized content recommendations, etc.).