Skip to content
Back to Logs
Logs

The Beta-Binomial Model: A Ground-Up Reference

Building the Beta-Binomial model from coin flips, with intuition for priors, likelihood, and posterior distributions.

June 27, 20264 min readStatisticsbayesianprobability
On this page

Bernoulli Trials and the Likelihood

Imagine that you have a coin that lands on heads with the probability θ\theta. You flip it nn times and observe kk heads. The probability of seeing exactly kk heads given θ\theta is the Binomial likelihood:

P(kθ,n)=(nk)θk(1θ)nkP(k \mid \theta, n) = \binom{n}{k} \theta^k (1 - \theta)^{n - k}

This is your data-generating process. If θ\theta is known, you can compute how likely any outcome is. But in practice θ\theta is unknown, and you want to infer it from data.

The maximum likelihood estimate is θ^=k/n\hat{\theta} = k / n, 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 θ\theta. 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 [0,1][0, 1] and can encode many shapes with just two parameters:

θBeta(α,β)\theta \sim \text{Beta}(\alpha, \beta)

The density is:

f(θ;α,β)=θα1(1θ)β1B(α,β)f(\theta; \alpha, \beta) = \frac{\theta^{\alpha - 1} (1 - \theta)^{\beta - 1}}{B(\alpha, \beta)}

where BB is the Beta function (the normalizing constant here).

Alpha and beta are pseudocounts, basically imaginary prior observations. For example, Beta(2,5)\text{Beta}(2, 5) behaves as if you have seen 2 heads and 5 tails before collecting real data.

Prior shapeWhen to use
α=β=1\alpha = \beta = 1Uniform — no prior preference, all θ\theta equally likely
α>β\alpha > \betaBelief that θ\theta is high (coin biased toward heads)
α<β\alpha < \betaBelief that θ\theta is low (coin biased toward tails)
α,β1\alpha, \beta \gg 1Strong prior certainty
α+β\alpha + \beta smallWeak prior — few pseudo-observations, so the data dominates quickly

The mean of Beta(α,β)\text{Beta}(\alpha, \beta) is α/(α+β)\alpha / (\alpha + \beta), 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:

Beta(α,β)+(k heads in n trials)Beta(α+k,β+nk)\text{Beta}(\alpha, \beta) + (k \text{ heads in } n \text{ trials}) \longrightarrow \text{Beta}(\alpha + k, \beta + n - k)

Add the observed heads to α\alpha, add the observed tails (nkn - k) to β\beta.

The posterior mean becomes:

α+kα+β+n\frac{\alpha + k}{\alpha + \beta + n}

which is a weighted average of the prior mean α/(α+β)\alpha / (\alpha + \beta) and the observed proportion k/nk / n. The weight is controlled by the total pseudocount α+β\alpha + \beta. A larger prior sample size means the prior pulls harder against the data (exerting more influence on our results).

Using the Visualizer

Prior: what you believe
2
5
Data: k heads in n flips
3
10

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.

α\alpha and β\beta sliders (PRIOR curves). These set your prior Beta distribution. The dashed curve shows the prior density. Start with α=2,β=5\alpha = 2, \beta = 5 — a weak prior favoring tails. Increase both together to sharpen the prior. Increase α\alpha alone to shift weight toward heads.

kk and nn sliders (POSTERIOR curves). These represent the data you observe. Set kk to the number of heads seen out of nn trials. The solid curve is the posterior — the prior updated by your data. When k/nk / n differs from the prior mean, the posterior shifts. When nn is small, the prior dominates. As nn grows, the posterior converges toward k/nk / n.

The formula caption below the sliders shows the exact posterior parameters:

Beta(α+k,β+nk)\text{Beta}(\alpha + k, \beta + n - k)

Push nn to 30 with k=15k = 15 and a prior of Beta(2,5)\text{Beta}(2, 5) — the posterior will sit between the prior mean (2/70.292/7 \approx 0.29) and the observed proportion (0.500.50). With n=3n = 3 and k=2k = 2, the prior pulls much harder.

The Extension

The Beta-Binomial is the simplest case of a pattern that repeats across Bayesian statistics:

  1. Choose a prior that captures what you know (or do not know) before seeing data
  2. Write down the likelihood of the data given the parameters
  3. 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.).