The idea
Someone hands you a coin that might be biased. Before flipping, you have a belief about its probability of heads, . That belief is a whole distribution, not a single number: the prior.
Each flip is evidence. Heads makes high values of more plausible, tails makes low values more plausible. Multiply the prior by the likelihood of what you saw, renormalise, and you get the posterior. Keep going and the posterior narrows around the truth.
Why the Beta distribution
If the prior is and you see heads and tails, the posterior is exactly . The Beta is the conjugate prior for coin flips: updating is just adding counts. You can read and as imaginary heads and tails you saw before the experiment started.
Bayesian vs frequentist
The frequentist estimate is simply . With lots of data both approaches agree. With little data the prior matters: after one head, the frequency says , while a sensible prior says 'probably above a half, but who knows'. The credible interval states directly where probably lies, given the data and the prior.
Try this
- Flip 10 times with the flat prior Beta(1, 1). Then flip 100 more and watch the credible interval shrink roughly like .
- Set a stubborn prior, , and a hidden bias of 0.8. The posterior starts near 0.5 and has to be dragged towards the truth by the data.
- Reset and flip once. Compare the posterior mean with the frequency estimate , which jumps to 0 or 1 straight away.
- Try . This prior expects the coin to be extreme (always heads or always tails) and reacts strongly to the first few flips.
The maths
Bayes for parameters
Likelihood of h heads in n flips
Conjugate update
Posterior mean
Maximum likelihood