Bayesian inference treats the coin's bias θ as a random variable, not a fixed unknown. Bayes' theorem turns a prior belief about θ into a posterior belief once data (coin flips) is observed.
Bayes' theorem: P(θ|data) ∝ P(data|θ) · P(θ)
posterior ∝ likelihood · prior
Beta-Binomial conjugacy (this sim):
prior: π(θ) = Beta(α₀, β₀)
likelihood: x heads in n flips ~ Binomial(n, θ)
posterior: π(θ|data) = Beta(α₀ + x, β₀ + n − x) — closed form, no MCMC needed
E[θ|data] = (α₀+x) / (α₀+β₀+n) posterior mean
Var[θ|data] shrinks as n grows more data ⇒ narrower credible interval
- α₀ / β₀ — the prior's pseudo-counts of heads/tails "seen" before any real data; α₀=β₀=1 is a flat (uniform) prior, larger values encode stronger prior belief.
- True P(heads) — the hidden bias used only to generate simulated flips; the model never sees this value directly, only the flip outcomes.
- Flip / Auto-run — each flip updates x and n, and the green posterior bars are recomputed analytically from the conjugate formula above.
For non-conjugate models, the posterior has no closed form and is instead approximated numerically — e.g. with Markov Chain Monte Carlo methods (Gibbs sampling, Metropolis–Hastings) that draw samples from π(θ|data) without ever computing it exactly.