Bayesian Updating
A parameter θ is drawn from the prior, n observations are generated from the likelihood at that θ, and the posterior is updated one observation at a time.
Likelihood
Prior
θ is drawn from
the posterior is computed with
Data
Prior and posterior
posteriorposterior after k after k − 1 prior true θ prior θ was drawn from mean and 95% interval
- Posterior mean
- MAP estimate
- 95% credible interval
- Posterior standard deviation
Posterior mean as data accumulate
posterior mean 95% interval true θ
- True θ (drawn at Simulate)
- Posterior mean − θ
The model
Each observation updates the distribution over θ by Bayes' rule, with the previous posterior as the prior:
The observations are independent given θ, so after k steps the result is the posterior given all k observations at once, in whatever order they arrived:
Each observation is the number of heads in m flips, xi ~ Binomial(m, θ), and θ ~ Beta(α, β). After k observations with h heads and t tails in total, the posterior is Beta(α + h, β + t): the heads add to α and the tails to β, so the prior acts as α heads and β tails counted before the data.
Each observation is the number of heads in m flips, xi ~ Binomial(m, θ), and θ ~ ½ Beta(α, β) + ½ Beta(β, α): a coin believed to be biased, in a direction not known in advance. Each component updates as a Beta prior does, and its weight is multiplied by how well it predicted the data. With h heads and t tails, the posterior is w Beta(α + h, β + t) + (1 − w) Beta(β + h, α + t), where w is B(α + h, β + t) divided by B(α + h, β + t) + B(β + h, α + t) and B is the beta function.
Each observation is a count xi ~ Poisson(θ), and θ ~ Gamma(α, β) with shape α and rate β. After k observations with total count s, the posterior is Gamma(α + s, β + k): the counts add to α and the number of observations to β.
Each observation is xi ~ N(θ, σ2) with σ known, and θ ~ N(μ0, τ2). After k observations with sample mean x̄, the posterior is N(m, v) with 1/v = 1/τ2 + k/σ2 and m = v (μ0/τ2 + kx̄/σ2): the precisions add, and the posterior mean is the precision-weighted average of the prior mean and the sample mean.
Each observation is a waiting time xi ~ Exponential(θ) with rate θ, and θ ~ Gamma(α, β) with shape α and rate β. After k observations with total time s, the posterior is Gamma(α + k, β + s): the number of events adds to α and the elapsed time to β.
With the wrong-prior option, θ is drawn from one prior and the posterior is computed with another, so the analysis starts from beliefs that do not match how the data arose. The posterior still concentrates near θ as observations accumulate, provided the prior it starts from gives θ some density; a prior that rules θ out can never recover it.
The curves and statistics on this page are computed on a grid of θ values rather than from these closed forms, so the prior need not be conjugate; the closed form is printed above the plot for comparison.