The answer is a distribution
Classical estimation hands you a number and, separately, a statement about how that number would behave under hypothetical repetition. Bayesian inference hands you a distribution describing how plausible each possible value is, given the data you actually have.
What each approach treats as random
- frequentist
- The parameter is a fixed unknown constant. The data is random, and so is any estimate computed from it. Probability describes long-run frequencies.
- bayesian
- The data is what it is — you observed it. The parameter is uncertain, so it gets a distribution. Probability describes degrees of belief.
Neither is a mistake. They answer different questions, and the Bayesian one is usually closer to what a person actually wanted to ask.
What you get out
- A full posterior, not a point. You can read off any summary you like from it — mean, mode, median, intervals, tail probabilities.
- Direct probability statements. "There's an 89% chance the effect is positive" is a sentence a posterior licenses and a p-value does not.
- Coherent updating. New data slots in without redoing anything from scratch.
- Assumptions written down. The prior forces you to state what you brought to the problem, where other methods leave it implicit.
- Uncertainty that propagates. Predictions inherit parameter uncertainty automatically. Section 09.
Prior, likelihood, posterior, evidence
Prior · p(θ)
What you believed about the parameter before this data. A distribution over every value it could take. Can encode real knowledge, deliberate ignorance, or a regularizing preference for simplicity.
Likelihood · p(D|θ)
How well each candidate value explains what you saw. Not a distribution over θ — it doesn't integrate to 1 in θ. It's a function scoring each hypothesis against fixed data.
Posterior · p(θ|D)
The updated belief. Always a compromise between prior and likelihood, weighted by how sharp each one is. This is the output.
Evidence · p(D)
How likely the data was overall, averaged across every value of θ. A normalizing constant that makes the posterior integrate to 1 — and the source of nearly all computational pain.
Why the proportional form is what people actually use
The evidence doesn't depend on θ, so it changes the height of the posterior but never its shape. Drop it, work with the unnormalized product, and normalize at the end — which is exactly what MCMC does, and why MCMC never needs to compute the hard integral at all.
Point summaries, if you need one
- posterior mean
- The expected value. Minimizes squared error. The usual default.
- posterior median
- Minimizes absolute error. More robust for skewed posteriors.
- MAP
- The mode — the single most probable value. Cheap, and the bridge to regularized optimization.
Today's posterior is tomorrow's prior
Evidence accumulates. Process a batch, get a posterior, then treat that posterior as your prior when the next batch arrives — the result is identical to having processed everything at once. Order doesn't matter either. That consistency is a genuine structural property, not a convenience.
The cleanest way to see accumulation is the odds form. Divide Bayes' rule for one hypothesis by the same rule for its complement, and the evidence term cancels completely:
That fraction is the likelihood ratio — the only thing evidence contributes. Take logs and multiplication becomes addition, so each independent observation adds a fixed number of bits to your belief. Toggle the items below.
When the maths closes cleanly
For some prior-likelihood pairings the posterior stays in the same family as the prior, and updating reduces to arithmetic on the parameters. No integrals, no sampling. The hero above runs on exactly this.
| Likelihood | Conjugate prior | Posterior | Models |
|---|---|---|---|
| Bernoulli / Binomial | Beta(α, β) | Beta(α + heads, β + tails) | Conversion rates, click-through, defect rates |
| Poisson | Gamma(α, β) | Gamma(α + Σx, β + n) | Event counts, arrivals, failures per hour |
| Exponential | Gamma(α, β) | Gamma(α + n, β + Σx) | Waiting times, time between failures |
| Normal (known σ) | Normal(μ₀, σ₀²) | Normal, precision-weighted mean | Measurement with known noise |
| Normal (both unknown) | Normal-Inverse-Gamma | Normal-Inverse-Gamma | The general one-dimensional case |
| Categorical / Multinomial | Dirichlet(α) | Dirichlet(α + counts) | Topic models, word distributions, multi-class rates |
Pseudo-counts: the intuition that makes it stick
A Beta(α, β) prior behaves exactly like having already seen α−1 heads and β−1 tails. Beta(1,1) is flat — no imaginary data at all. Beta(30,30) is 58 imaginary fair flips, which is why it takes real effort to shift.
This makes prior strength something you can state in units a colleague understands: "my prior is worth about ten observations." Try the stubbornly-fair preset in the hero and then click flip 100 — you can watch the data outvote it.
Why the denominator ruins everything
An integral over the entire parameter space. In one dimension you could evaluate it on a grid. In two or three, still fine. At fifty parameters a grid with ten points per axis needs 10⁵⁰ evaluations, which is more operations than there are atoms available to perform them.
| Approach | Idea | Cost / accuracy |
|---|---|---|
| Conjugacy | Pick a prior that makes the integral analytic | Exact and instant, but only for special pairings |
| Grid approximation | Evaluate on a lattice and normalize numerically | Exact enough in 1–3 dimensions; hopeless beyond |
| Laplace approximation | Fit a Gaussian at the mode using the Hessian | Very fast; wrong whenever the posterior is skewed or multimodal |
| MCMC | Draw correlated samples from the posterior | Asymptotically exact, slow, needs diagnostics |
| Variational inference | Optimize the closest member of a simple family | Fast and scalable; systematically underestimates uncertainty |
| ABC | Simulate data, keep parameters producing close matches | For models you can simulate but cannot write a likelihood for |
Sampling instead of solving
Build a random walk whose long-run visiting frequency is the posterior. Run it, keep the positions, and treat them as draws. Any quantity you wanted from the posterior becomes an average over samples.
Metropolis–Hastings, in five lines
- Start anywhere.
- Propose a nearby point.
- Compute the ratio of unnormalized posterior densities. The evidence cancels here.
- If the ratio exceeds 1, move. Otherwise move with probability equal to the ratio.
- Record the position and repeat.
Downhill moves are sometimes accepted, which is what stops it collapsing onto the mode and lets it map the whole distribution.
R-hat
Run several chains from different starts and compare between-chain to within-chain variance. Values above about 1.01 mean they haven't converged on the same answer yet.
Effective sample size
Samples are correlated, so 10,000 draws may carry the information of 200 independent ones. ESS tells you how many you really have. Aim for several hundred per quantity of interest.
Divergences
HMC-specific, and the most useful warning in applied Bayes. They signal geometry the sampler cannot navigate — usually a model that needs reparameterizing. Never ignore them.
Optimization instead of sampling
Give up on the exact posterior. Choose a family of tractable distributions, and find the member closest to the truth. Inference becomes an optimization problem, which means gradient descent, mini-batches and GPUs all apply.
Maximizing the evidence lower bound is equivalent to minimizing KL(q ‖ p), and the gap between the ELBO and the true log evidence is exactly that divergence. The first term rewards explaining the data; the second rewards staying spread out.
Use it when the dataset is large, you need speed, and approximate uncertainty is acceptable. Avoid it when the uncertainty estimate is the deliverable — for a safety threshold or a clinical decision, run MCMC.
The posterior predictive
To predict a new observation, don't pick the best parameter and use it. Predict under every parameter value and average, weighted by how plausible each one is. Parameter uncertainty flows straight into the prediction.
In practice it's a sum, not an integral: you already have posterior samples, so draw a prediction from each one and collect the results. Twenty lines of code, and the spread you get back is honest rather than assumed.
Notice where the fan widens. A single fitted line is equally confident everywhere; the posterior predictive automatically becomes less certain away from the data, which is exactly the behaviour you want from anything making decisions.
Credible is not confidence
Credible interval
"Given this model and this data, there is a 95% probability the parameter lies in [a, b]."
A statement about the parameter, conditional on what you observed. It is the sentence people want to say, and the Bayesian framework is what licenses saying it.
Confidence interval
"If I repeated this experiment many times and built an interval each time by this procedure, 95% of those intervals would contain the true value."
A statement about the procedure, not about the particular interval in front of you. Your specific interval either contains the value or doesn't; the 95% belongs to the method.
Equal-tailed interval
Chop 2.5% off each end. Simple, and invariant under monotone transformations. Can exclude the mode on a strongly skewed posterior, which looks odd.
Highest density interval (HDI)
The narrowest interval containing 95% of the mass. Always includes the mode, and can be disjoint on a multimodal posterior — which is informative rather than a bug.
The part everyone argues about
The standard objection is that priors are subjective. The standard answer is that every method embeds assumptions, and the Bayesian ones are at least written down where a reviewer can attack them.
| Kind | What it does | When |
|---|---|---|
| Informative | Encodes real domain knowledge or previous studies | You genuinely know something. Say where it came from |
| Weakly informative | Rules out the absurd, stays agnostic within the plausible | The sensible default for most applied work |
| Flat / uniform | Equal density everywhere | Feels neutral; often isn't. Not flat after a reparameterization |
| Improper | Doesn't integrate to 1 at all | Sometimes yields a proper posterior. Breaks Bayes factors entirely |
| Jeffreys | Invariant under reparameterization | When "objectivity" matters and the model is simple |
| Hierarchical | Priors whose parameters are themselves estimated | Grouped data. Produces partial pooling, which is often the whole reason to go Bayesian |
| Regularizing | Deliberately shrinks toward zero | Many parameters, limited data. This is what ridge and lasso are |
Choosing between models
Bayes factors
The ratio of evidences — how much better one model predicted the data than the other. It penalizes complexity automatically, because a model that can explain anything spreads its predictive mass thin and therefore assigns less to what actually happened.
Predictive criteria
- WAIC
- Estimates out-of-sample predictive accuracy from the posterior, with a complexity correction.
- PSIS-LOO
- Approximate leave-one-out cross-validation from the samples you already have. Generally preferred, and it flags its own unreliability.
- K-fold CV
- Refit the model on each fold. Expensive and hard to argue with.
These ask which model predicts better rather than which is more probable — usually the more useful question, and far less prior-sensitive.
Where it actually shows up
| Method | What's Bayesian about it | Why it's used |
|---|---|---|
| Ridge / Lasso | MAP with a Gaussian / Laplace prior | Nearly everyone doing this has no idea. The penalty is a prior |
| Bayesian linear regression | Posterior over coefficients, not point estimates | Honest coefficient uncertainty and predictive intervals |
| Gaussian processes | A prior over functions, updated by data | Non-parametric regression with calibrated uncertainty built in |
| Bayesian optimization | GP posterior plus an acquisition function | Hyperparameter tuning when each evaluation is expensive |
| Thompson sampling | Sample a parameter from the posterior, act greedily on it | Bandits and A/B testing. Elegant exploration with no tuning knob |
| Variational autoencoders | Variational inference over a latent code | The V in VAE is exactly the ELBO from section 07 |
| Bayesian neural networks | Distributions over weights | Principled, and still expensive enough to be rare in production |
| MC dropout | Dropout at inference, read as approximate VI | Cheap uncertainty from a network you already trained |
| Deep ensembles | Not formally Bayesian, but a similar posterior-averaging effect | The strong practical baseline for uncertainty in deep learning |
| Naive Bayes | Bayes' rule plus a conditional independence assumption | Fast, and surprisingly hard to beat on small text problems |
| Kalman filters | Sequential Bayesian updating for linear Gaussian states | Robotics, tracking, sensor fusion — running this loop at 100 Hz |
| Hierarchical models | Partial pooling across groups | The killer application. Borrows strength across small groups |
# the modern workflow, in PyMC — the model reads like the maths import pymc as pm with pm.Model() as model: # priors — weakly informative, stated explicitly intercept = pm.Normal("intercept", mu=0, sigma=10) slope = pm.Normal("slope", mu=0, sigma=5) noise = pm.HalfNormal("noise", sigma=1) # likelihood mu = intercept + slope * x pm.Normal("y", mu=mu, sigma=noise, observed=y) # check the priors BEFORE looking at the data prior = pm.sample_prior_predictive() # NUTS, four chains, automatic tuning idata = pm.sample(2000, tune=1000, chains=4, target_accept=0.9) idata.extend(pm.sample_posterior_predictive(idata)) import arviz as az az.summary(idata) # means, HDIs, r_hat, ess — read r_hat first az.plot_trace(idata) # fuzzy caterpillars = healthy az.loo(idata) # predictive comparison against another model
Worth the cost, and when it isn't
Reach for it when
- The uncertainty is the deliverable. Risk estimates, safety margins, anything feeding a decision with asymmetric costs.
- Data is scarce or expensive. Priors do real work here, and this is where Bayesian methods most outperform.
- You have genuine prior knowledge. Physical constraints, previous studies, expert calibration — throwing that away is a choice.
- The structure is hierarchical. Many small groups, partial pooling. Frequentist alternatives exist and are clumsier.
- Evidence arrives over time. Sequential updating is native, with no multiple-comparisons penalty for looking.
- You need to explain the model. A generative model plus explicit priors is far easier to defend to a regulator than a tuned pipeline.
Skip it when
- You have enormous data and only want a point prediction. The posterior collapses to the MLE; you paid for nothing.
- Prediction accuracy is the sole metric. Gradient boosting will usually win on tabular data and take minutes.
- The model is very high-dimensional. Sampling a deep network's weights is still largely impractical — deep ensembles are the pragmatic answer.
- You need results this afternoon. MCMC takes real wall-clock time, and models need diagnosis.
- Nobody on the team can maintain it. A model no one can debug at 2am is a liability regardless of its elegance.
Drills that build the intuition
| # | Do this | You'll know it when |
|---|---|---|
| 1 | Do the Beta-Binomial update by hand on paper for ten flips, then check it against the hero above | Pseudo-counts stop being an analogy |
| 2 | Fit the same data with a flat prior and a strong wrong prior; plot both posteriors as n grows | You can say how much data is needed to overturn a given prior |
| 3 | Implement grid approximation in 1D, then try it in 5D and watch it die | The curse of dimensionality is felt, not recited |
| 4 | Write Metropolis–Hastings from scratch in thirty lines | You understand why the normalizing constant never appears |
| 5 | Deliberately mis-tune the step size and inspect the trace plots | You can diagnose a bad chain from its picture alone |
| 6 | Fit the same model in PyMC or NumPyro; read r_hat, ESS and divergences | You check diagnostics before you look at results |
| 7 | Run a prior predictive check and find a prior that generates absurd data | You do this before every fit, automatically |
| 8 | Build a hierarchical model over groups; compare against no pooling and complete pooling | Partial pooling clicks, and you see why it's the main event |
| 9 | Derive ridge regression as MAP with a Gaussian prior | Regularization and priors are one idea in your head |
| 10 | Take a decision you actually face and write down your prior odds and the likelihood ratios | The framework leaves the notebook |
The one-paragraph summary
Bayesian inference treats unknown parameters as uncertain and therefore as having distributions, and updates those distributions with data through Bayes' rule: the posterior is proportional to the likelihood times the prior. The output is a full distribution rather than a point, so uncertainty is a first-class result and probability statements about parameters become licensed. Updating is sequential and order-independent, and in odds form each independent piece of evidence contributes a fixed additive shift in log-odds. The normalizing constant is an integral over the whole parameter space and is intractable beyond a few dimensions, which is why practical Bayes is a story about computation: conjugate families when the maths closes, MCMC when you want asymptotic exactness, and variational inference when you want speed and can accept systematically narrow uncertainty. Predictions come from the posterior predictive, which averages over parameter uncertainty instead of conditioning on one estimate. Priors are the standard objection and the standard answer is a sensitivity analysis. It is worth the cost when uncertainty drives a decision, when data is scarce, or when the structure is hierarchical — and rarely worth it when you have abundant data and only want a point prediction.