Bayesian updating

The engine behind every model in this course: posterior ∝ prior × likelihood. The posterior is a compromise between what you believed beforehand (the prior) and what the data say (the likelihood). More data lets the likelihood win; a stronger prior pulls harder. These figures let you feel that tug-of-war.

Bayes' theorem

Turning "what we believe" plus "what we saw" into "what we now believe"

We want the probability of unknown parameters θ given the data — but our model tells us the reverse, the probability of the data given the parameters. Bayes' theorem inverts it:

p(θ | data) = p(data | θ) · p(θ)p(data)   // posterior = (likelihood × prior) / evidence

The denominator p(data) does not depend on θ — it is just a constant that makes the posterior integrate to 1. So the shape of the answer comes entirely from the numerator, which is why the whole of Bayesian inference fits in one proportionality:

p(θ | data) ∝ p(data | θ) × p(θ)   // posterior ∝ likelihood × prior

Why bother with a prior?

A prior is not cheating — it is the explicit, auditable statement of what you assumed. With lots of data it barely matters; with little data it is doing the honest work of stopping the model from believing nonsense.

In this course we sample the posterior

For the toy examples on this page the posterior has a tidy closed form. Real epidemic models have hundreds of parameters and no such formula, so the normalising integral p(data) is intractable. Instead of solving it we draw samples from the posterior using MCMC (in Stan). Each sample is one plausible parameter set — one possible version of the epidemic — and the cloud of samples is the posterior. Everything below is the conjugate, exactly-solvable shadow of that sampling machinery.

Updating a probability Beta–Binomial

Estimating a reporting / ascertainment probability θ from "k of n" data

Suppose θ is a probability we want to learn — the chance a true case is reported, say, or a test comes back positive. We hold a prior belief about θ, then observe data: k successes in n trials. The likelihood of that data is Binomial, ∝ θk(1−θ)n−k. A Beta(a, b) prior, ∝ θa−1(1−θ)b−1, is the natural partner — multiply the two and the exponents simply add:

prior Beta(a, b)  ×  data (k of n)  →  posterior Beta(a + k,  b + n − k)

So updating is just bookkeeping: add the successes to a and the failures to b. The figure evaluates each Beta density on a fine grid of θ ∈ [0, 1] and normalises it numerically (the trapezoid rule) — no special functions needed. Watch how the posterior sits between prior and likelihood, and how it slides toward the data as n grows.

prior Beta(a, b) likelihood (scaled) posterior Beta(a+k, b+n−k)
prior mean = data k/n = posterior mean = 95% CrI =

Watch the data take over, one draw at a time

Press play to stream Bernoulli draws (each a "success" with true probability 0.7) and feed them in sequentially. The prior is fixed at whatever a, b you set above. Early on, the posterior barely moves from the prior; as the trials pile up the likelihood dominates and the posterior tightens around the true 0.7 — the data swamp the prior.

streamed n = 0, k = 0

The "play" stream overrides the n and k sliders and uses the live prior a, b. Press reset stream to return to the manual sliders.

A continuous mean Normal–Normal

The posterior mean is a precision-weighted average of prior and data

Now θ is a continuous quantity — a mean we want to estimate (an average delay, a log-incidence level). We hold a prior N(μ0, σ0²) and observe n data points with sample mean x̄ and known observation noise σ. With a Normal prior and Normal likelihood the posterior is again Normal, and its mean is the two sources blended by their precisions (precision = 1/variance):

μpost = μ00² + n·x̄/σ²1/σ0² + n/σ²     1σpost² = 1σ0² + nσ²

Read it as a weighted tug-of-war: whichever side is more precise (less variance, or — for the data — more observations) pulls the posterior toward itself. A confident prior (small σ0) holds firm; lots of data (large n) overwhelms it. And the posterior is always sharper than either input — precisions add, so it can only narrow.

prior N(μ0, σ0²) likelihood (from data) posterior
prior mean = data mean = posterior mean = posterior sd =
Set n = 0 and the posterior is the prior exactly — no data, no update. Crank n up and the posterior slides onto the data mean and shrinks, almost ignoring the prior. That is the same convergence MCMC shows: with enough data the choice of (reasonable) prior stops mattering.

Takeaways