Hexa Scholar

Conjugate priors: updates that stay in the family

A wooden rod rests level on a gold triangular fulcrum, with a small gold weight hanging from one end and a large one from the other, the fulcrum closer to the large weight.
A rod balanced between a light weight and a heavy one.

The question

A prior puts the mean clinic wait near 50 minutes; nine days of data average 60. Where between 50 and 60 does the updated mean land?

Place it yourself; the page computes the answer.

  1. 1 SeePlace the updated mean between two means.
  2. 2 TryPredict what an update does to the spread.
  3. 3 ProveBuild the normal update, line by line.
  4. 4 ApplyFive problems with conjugate pairs.
Before you start · 3 quick checks on the SD of an average, a beta mean and a weighted average, about 3 min

Two ideas before you start

2 ideas

Precision is one over the variance

Figure: the density of one reading with SD 6, solid, and the density of the average of n readings, dashed, both centered at the true mean. It needs JavaScript.

Readings:

SD of the average = 6/√1 = 6

Precision n/σ² = 1/36 ≈ 0.0278

Each reading has SD 6. The average of n independent readings has SD 6/√n, so its precision, one over its variance, is n/36: four times the readings, four times the precision.

Exact definition

Precision. The precision of a normal distribution \(\operatorname{N}(m, v)\) with variance \(v \gt 0\) is \(1/v\). The second argument of \(\operatorname{N}\) is always a variance.

The two precisions of this page. An unknown mean \(\theta\) gets a normal prior \(\theta \sim \operatorname{N}(m_0, \tau^2)\) with \(\tau \gt 0\); its precision is \(\kappa_0 = 1/\tau^2\). Given \(\theta\), readings \(Y_1, \dots, Y_n\) are independent \(\operatorname{N}(\theta, \sigma^2)\) with \(\sigma \gt 0\) known, and their mean \(\bar{Y}\) is \(\operatorname{N}(\theta, \sigma^2/n)\); its precision is \(\kappa_d = n/\sigma^2\). The observed readings are \(y_1, \dots, y_n\), with mean \(\bar{y}\).

Conjugate: the posterior stays in the prior’s family

Figure: the prior density Beta(2, 2) for a heads probability, solid, and the posterior after the chosen tosses, dashed. It needs JavaScript.

Data:

No data, posterior = prior: Beta(2, 2)

Mean a/(a + b) = 2/4 = 0.5

With a beta prior for a coin’s heads probability, the posterior after any tosses is again a beta density: add the heads to the first parameter and the tails to the second.

Exact definition

Conjugate family. A family of prior densities is conjugate to a sampling model when, for every prior in the family and every possible data set, the posterior is again in the family. Updating then only changes the parameters.

Beta prior, coin tosses. Let \(p\) be the heads probability, \(0 \lt p \lt 1\), with prior Beta(\(a, b\)), \(a, b \gt 0\), whose density is proportional to \(p^{a-1}(1 - p)^{b-1}\). Given \(p\), tosses are independent with heads probability \(p\). A sequence with \(h\) heads and \(t\) tails has likelihood \(p^h(1 - p)^t\), so the posterior is proportional to \(p^{a+h-1}(1 - p)^{b+t-1}\): it is Beta(\(a + h, b + t\)). The lesson on posterior updates proves this with the normalizing constant.

Refresher: the models on this page

All examples are hypothetical. In the normal model, \(\theta\) is one fixed unknown number; the prior describes uncertainty about it before the readings are used, and it is chosen before seeing them. The posterior then describes the uncertainty about \(\theta\) that remains under that prior and that model; a different prior or model gives a different posterior. Given \(\theta\), the readings are independent, and the SD \(\sigma\) of a single reading is known. An unknown \(\sigma\) needs a different prior family, not treated here.

Reading a normal kernel. If a density in \(\theta\) is proportional to \(e^{-(\theta - m)^2/(2v)}\) for every real \(\theta\), with \(v \gt 0\), it is the \(\operatorname{N}(m, v)\) density: the factor in front is fixed by the total area 1. The lesson on the normal distribution has the density.

Multiplying a prior by a likelihood and normalizing is the subject of the lesson on posterior updates; Bayes’ rule for events is in the lesson on Bayes’ theorem and base rates, and intervals from a posterior are in the lesson on credible intervals.

1 See

Place the updated mean

How the game works

There are four rounds. Your guess moves in steps of 0.1, from 2.5 below the smaller of the two means to 2.5 above the larger. Check my guess locks it, draws the posterior density and says how far your guess is from the posterior mean; a guess within 1, a tenth of the distance between the two means, counts as close. After the fourth round a table compares your guesses with the posterior means. Start over clears everything.

The model in every round: the prior is \(\theta \sim \operatorname{N}(m_0, \tau^2)\), and given \(\theta\) the \(n\) readings are independent \(\operatorname{N}(\theta, \sigma^2)\) with \(\sigma\) known. The posterior mean is the mean of \(\theta\) given the readings.

2 Try

The spread after an update

Two predictions, each before its numbers. The explorer between them opens once the first one is answered.

A beta prior and one toss

3 Prove

Why a normal prior stays normal

Theorem

Assumptions. An unknown mean \(\theta\) has the prior \(\theta \sim \operatorname{N}(m_0, \tau^2)\) with \(\tau \gt 0\). Given \(\theta\), readings \(Y_1, \dots, Y_n\), with \(n \ge 1\), are independent \(\operatorname{N}(\theta, \sigma^2)\), with \(\sigma \gt 0\) known. The observed values are \(y_1, \dots, y_n\), with mean \(\bar{y}\); sums \(\sum_i\) run over \(i = 1, \dots, n\). Write \(\kappa_0 = 1/\tau^2\), \(\kappa_d = n/\sigma^2\), and \(\pi(\theta \mid y)\) for the posterior density of \(\theta\).

Conclusion. For every observed sample, \(\theta \mid y \sim \operatorname{N}(m_n, 1/\kappa_n)\), where

\[\begin{aligned} \kappa_n &= \kappa_0 + \kappa_d, \\ m_n &= \frac{\kappa_0 m_0 + \kappa_d \bar{y}}{\kappa_n}. \end{aligned}\]

So the posterior is again normal: the normal prior is conjugate to normal readings with known \(\sigma\).

Facts the proof uses.

  • the posterior density is proportional to the prior density times the likelihood, as in the lesson on posterior updates;
  • \(\ln(ab) = \ln a + \ln b\) for positive \(a, b\);
  • the deviations from the mean add up to 0: \(\sum_i (y_i - \bar{y}) = 0\);
  • a density proportional to \(e^{-(\theta - m)^2/(2v)}\) for every \(\theta\), with \(v \gt 0\), is the \(\operatorname{N}(m, v)\) density.

Each option is one step for the model of the theorem. Pick the one that is true for every prior, every observed sample the theorem covers and every \(\theta\). Here \(C_1\), \(C_2\) and \(C_3\) stand for numbers that do not depend on \(\theta\).

What else follows
  • Weights. With \(w = \kappa_d/\kappa_n\), the conclusion reads \(m_n = m_0 + w(\bar{y} - m_0)\), and \(0 \lt w \lt 1\) because both precisions are positive.
  • The prior as readings. With \(n_0 = \sigma^2/\tau^2\), \(\kappa_n = (n_0 + n)/\sigma^2\): the posterior has the precision of \(n_0 + n\) readings, and \(m_n = (n_0 m_0 + n\bar{y})/(n_0 + n)\).
  • One reading at a time. Each reading adds \(1/\sigma^2\) to the precision. Updating with the readings one by one, each posterior serving as the prior for the next reading, ends at the same \(\operatorname{N}(m_n, 1/\kappa_n)\).
  • Many readings. With \(\tau\) and \(\sigma\) fixed, \(w = n/(n_0 + n)\) tends to 1 as \(n\) grows, and the posterior SD \(\sigma/\sqrt{n_0 + n}\) gets close to \(\sigma/\sqrt{n}\): the prior’s influence fades.
  • Other conjugate pairs. A beta prior with coin tosses gives Beta(\(a + h, b + t\)). A gamma prior for a Poisson rate \(\lambda\), with density proportional to \(\lambda^{\alpha - 1}e^{-\beta\lambda}\), and independent Poisson counts \(x_1, \dots, x_n\) give a gamma posterior with shape \(\alpha + \sum_i x_i\) and rate \(\beta + n\). In each pair the prior’s parameters act like earlier data: \(a\) heads and \(b\) tails, or \(\alpha\) events in \(\beta\) time units.
  • A convenience, not a reason. Conjugacy makes the update exact and short. The prior should still describe what is believed before the data; a prior outside the family is updated the same way, prior times likelihood, but usually needs numerical integration.
4 Apply

Problems

Each problem states its model and has hints and a full solution.

Key point For a conjugate pair, write the prior’s kernel, multiply by the likelihood’s kernel and read off the new parameters. In the normal model add the precisions and weight the means by them; for a beta prior add the heads and the tails; for a gamma prior add the total count to \(\alpha\) and the number of intervals to \(\beta\).
Level Undergraduate Prerequisites posterior updates (the lesson on posterior updates), normal densities, the SD of an average and beta means (refreshed in Before you start) Time ~35 min

Further reading