Skip to content
mlmentorship

Bayes' rule and the posterior

Normalize prior-weighted likelihoods over the right evidence population, then distinguish changed base rates from genuinely new evidence.

Published · 32 min read ·Core ·Foundation
Reading depth

Summary

Bayes’ rule conditions a declared probability model on observed evidence. For hypothesis or parameter , multiply its prior weight by its evidence likelihood, then normalize:

The evidence normalizer must be positive and finite. For discrete hypotheses, sum their weighted likelihoods; continuous parameters require an integral under the declared measure. Posterior probabilities, a posterior mode, and a chosen action are different outputs.

The classic example

Consider a hypothetical test with sensitivity and specificity . Assume prevalence and random sampling from that population; these are teaching assumptions, not measured clinical evidence. In people, expected branch counts are diseased and healthy. The branches contribute and positive results respectively, so the positive-result population has members.

Learning objective

Only 99 of 1,098 positive results come from the diseased group

A positive result is a new populationAmong all 1,098 positive tests, only 99 are true positives. Sensitivity is not the answer to this question.Before the test: 100000 peopleEach dot: 100 people100 diseased99900 healthySelect positive results99% pass thisfilter991% pass thisfilter999Now the positive group is the whole99 / 1098 = 9.016%
Derivation
Natural-frequency funnel for a rare disease test The population grid has 1,000 equal squares, each representing 100 people. Only the solid top-left square represents people with disease; the other 999 outlined squares represent healthy people. Start with 100,000 people. At 0.1 percent prevalence, 100 have the disease and 99,900 are healthy. With 99 percent sensitivity, the diseased branch contributes 99 true-positive results. With 99 percent specificity, one percent of the healthy branch contributes 999 false-positive results. A proportional positive-result strip contains a narrow 99-person true-positive segment and a 999-person false-positive segment. Both enter the denominator 1,098. The true-positive share is 99 divided by 1,098, about 9 percent. Before testing: 1 in 1,000 groups Each square represents 100 people. 1 group: disease 999 groups: healthy 100,000 people before testing 100 have disease prior: 0.1% 99,900 healthy prior: 99.9% 99% test positive 1% test positive 99 true positives 99% of 100 999 false positives 1% of 99,900 999 false positives 99 true all 1,098 positive results 99 / (99 + 999) = 9%
Read it this way: the narrow solid piece is 99 true positives. The much wider dashed piece is 999 false positives. Their widths use the same people-per-unit scale. The denominator is the entire strip, not just the diseased branch: 99 divided by 1,098, about 9%. These are expected counts under the hypothetical test assumptions.
Check: Why is a positive result only about 9% likely to indicate disease despite 99% sensitivity?
Read it this way: Among all 1,098 positive tests, only 99 are true positives. Sensitivity is not the answer to this question.
If disease prevalence rises, which input cohort changes before the test acts?

The healthy posterior is ; together the two posterior masses sum to one.

The four pieces

PieceNameRole
PriorWeight before this observation
LikelihoodEvidence model at a candidate parameter
PosteriorNormalized conditional distribution
EvidenceSum or integral of prior-weighted likelihoods

The evidence is constant across parameters within one model, so maximizing an unnormalized posterior can locate its mode. It cannot be discarded when reporting posterior probabilities or comparing model evidence. A constant prior density can preserve an MLE maximizer in that parameterization, when the posterior and maximizer exist. This is a prior assumption, not an absence of assumptions.

Change the Requirement

Change the Population

New task: Increase prevalence to one percent while keeping sensitivity and specificity unchanged.

Picture and change: Begin with diseased and healthy people.

Check: Both branches contribute positives; posterior disease probability becomes .

Use when: Screening and referral populations have different base rates and the transported test properties remain justified.

Observe Another Positive

New task: Add a second positive result, conditionally independent of the first given disease status.

Picture and change: Multiply each branch by its second-result likelihood.

Check: Original-population expected double-positive counts are and , giving .

Use when: The observation supplies genuinely new conditional evidence. Copying the same test report is perfectly dependent evidence and leaves the original posterior unchanged.

Conjugate priors

A conjugate prior produces a posterior in the same family, with parameters updated from the observations.

LikelihoodConjugate priorPosterior family
Bernoulli/binomialBetaBeta
Categorical/multinomialDirichletDirichlet
Gaussian (mean, known )GaussianGaussian
Gaussian precision, known meanGammaGamma
PoissonGammaGamma

Used in: Thompson sampling for bandits (Beta-Bernoulli), online recsys updates, conjugate Gibbs samplers.

Approximate inference (when conjugacy fails)

When closed-form conditioning is unavailable, distinguish the approximation from the desired posterior:

  • Laplace: approximate a suitable interior mode with a Gaussian using local curvature.
  • Variational inference: optimize within a chosen distribution family; the family and divergence affect the approximation.
  • MCMC: construct a target-invariant chain; convergence and Monte Carlo uncertainty still require diagnosis.
  • Stochastic-gradient samplers: introduce data subsampling and step-size/approximation considerations.

Common pitfalls

  • Reversed conditioning. A likelihood does not need to normalize over parameters.
  • Prior sensitivity. Weak evidence can leave substantial sensitivity to the prior; small sample size alone does not prove prior dominance.
  • Mode-only reporting. A mode omits uncertainty and can change under reparameterization.
  • Improper priors. An unnormalized prior can produce either a proper or improper posterior; check the integral.

Reconstruct

Why cannot two copies of one positive report be treated as independent tests?

Once the first report is known, its exact copy is certain under either disease status. The copy supplies likelihood ratio one, not another factor of ninety-nine.