Search

Search papers and lessons

Posterior Predictive Distribution

Level 3 · 12 min read

The posterior predictive distribution forecasts new data by asking each possible parameter value for its prediction and averaging those predictions, weighted by how believable each value is now.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Inference
  • Sign in to see your progress

TL;DR

Once you have a posterior for an unknown parameter, the next question is usually about data you have not seen yet. The posterior predictive distribution answers it. It is a forecast for a new observation, built by asking every possible parameter value what it would predict and averaging those predictions, each weighted by how believable that value is after seeing the data.

Where you'll see it: in forecasting a coin's next flip, in checking whether a fitted model could have produced the data it was trained on, and in leave-one-out model comparison, where each held-out point is scored by its predictive probability.

Intuition

Start from the next flip

You flip a coin once and it lands heads. Is the next flip more likely to be heads? Probably yes, but how much more? Two questions are hiding in there. The first is "how biased is this coin?", which the posterior answers with a spread of beliefs. The second is "what will the next flip be?", which is usually what you actually want. The posterior predictive distribution answers the second question without picking one value for the bias and pretending it is certain.

Average the forecasts, weighted by belief

Imagine a panel of experts, one for each possible bias. Each expert says exactly what the next flip will look like under their assumed bias. A fair-coin expert says heads with probability 0.5, and a loaded-coin expert says 0.8. You trust no single expert. You give each a vote equal to your posterior belief in them and combine the votes. The combined forecast is the posterior predictive. If most of your belief sits on the loaded coin, the forecast leans toward heads. If your belief is split, the forecast sits between the two.

flowchart LR
  A[Data seen so far] --> B[Posterior: belief about each parameter value]
  B --> C[Each parameter value predicts the new data]
  C --> D[Weight each prediction by its posterior belief]
  D --> E[Sum or integrate: posterior predictive]

This is the key difference from a plug-in forecast. A plug-in forecast takes the single most likely parameter value and predicts with it alone, ignoring how uncertain you still are. The posterior predictive keeps that uncertainty, so its spread is wider when the data are few. That width is information, not noise.

Why not just use the best parameter?

Suppose that after three flips the best estimate of the bias is 2/3. Predicting the next flip with exactly 2/3 claims more confidence than three flips can buy. The posterior predictive blends in the other plausible biases, pulling the forecast toward 1/2 when the evidence is thin. As the data grow, the posterior narrows, the blend tightens, and the forecast approaches the best value. No extra rule is needed; the averaging does the adjusting.

The math

Definition

Definition: Posterior predictive distribution

Let θ\theta be the unknown parameter, xx the observed data and x~\tilde{x} a new, unseen observation. The posterior predictive distribution of x~\tilde{x} given xx is

p(x~∣x)=∫p(x~∣θ) p(θ∣x) dθp(\tilde{x} \mid x) = \int p(\tilde{x} \mid \theta)\, p(\theta \mid x)\, d\theta

when θ\theta is continuous, and

p(x~∣x)=∑θp(x~∣θ) p(θ∣x)p(\tilde{x} \mid x) = \sum_{\theta} p(\tilde{x} \mid \theta)\, p(\theta \mid x)

when θ\theta takes finitely many values.

Read the integral in words. For each candidate value θ\theta, take the probability of the new data under that value, p(x~∣θ)p(\tilde{x} \mid \theta), and multiply it by the posterior weight p(θ∣x)p(\theta \mid x) of that value. Then add (or integrate) over all candidates. The symbol ∣\mid means "given". The factor p(x~∣θ)p(\tilde{x} \mid \theta) is the likelihood of the new point, and p(θ∣x)p(\theta \mid x) is the posterior.

Where the formula comes from

Start from the joint distribution of the parameter and the new data, given the old data. By the definition of conditional probability,

p(x~,θ∣x)=p(x~∣θ,x) p(θ∣x).p(\tilde{x}, \theta \mid x) = p(\tilde{x} \mid \theta, x)\, p(\theta \mid x).

Now make the modelling assumption that the new observation is independent of the old data once θ\theta is known. Then p(x~∣θ,x)=p(x~∣θ)p(\tilde{x} \mid \theta, x) = p(\tilde{x} \mid \theta). The old data affect the new point only through the parameter. Last, sum or integrate out θ\theta, which is the law of total probability applied with xx held fixed:

p(x~∣x)=∑θp(x~,θ∣x)=∑θp(x~∣θ) p(θ∣x).p(\tilde{x} \mid x) = \sum_{\theta} p(\tilde{x}, \theta \mid x) = \sum_{\theta} p(\tilde{x} \mid \theta)\, p(\theta \mid x).

The independence assumption is the step to remember. If the new point is related to the old data in some way that the parameter does not capture, the formula is wrong for that problem, and the model needs a richer parameter.

Compare with the evidence in Bayes' rule

The denominator of Bayes' rule is p(x)=∑θp(x∣θ) p(θ)p(x) = \sum_\theta p(x \mid \theta)\, p(\theta). It is the forecast for the data before any data are seen, the prior predictive (the same sum, weighted by the prior). The posterior predictive is the same kind of sum with the posterior replacing the prior. The data have moved the weights, and the forecast has moved with them.

Closed forms and conjugate pairs

When the prior and the likelihood form a matching pair (a Conjugate Prior), the posterior and the predictive have closed forms, and no integral has to be computed. A standard case: the observations are Gaussian with known variance σ2\sigma^2, and the prior on the mean is also Gaussian. Then the posterior predictive of a new point is again Gaussian. Its mean is the posterior mean of θ\theta, and its variance is σ2\sigma^2 plus the posterior variance of the mean. The extra term is uncertainty about the mean, which is why the forecast is wider than the noise alone.

Computing when there is no shortcut

Most models have no closed form. Then the sum or integral is approximated by sampling. Draw parameter values from the posterior, simulate one new observation from each draw, and treat the simulated values as samples from the predictive. Averages and quantiles of those samples approximate the exact answer. This is the Monte Carlo approach, and it is how most posterior predictive calculations are done in practice.

Worked examples

Example
Example 1: the next flip after one head (tiny)

The setup is the one from Posterior Distribution: a fair coin (heads probability 0.5) or a loaded coin (heads probability 0.8), each with prior probability 1/2. One flip gave heads, so the posterior is fair 5/13 and loaded 8/13.

  1. Write the forecast as a weighted sum over the two candidates: p(H∣data)=p(H∣fair) p(fair∣data)+p(H∣loaded) p(loaded∣data)p(H \mid \text{data}) = p(H \mid \text{fair})\, p(\text{fair} \mid \text{data}) + p(H \mid \text{loaded})\, p(\text{loaded} \mid \text{data}).
  2. Fair term: 0.5×5/13=2.5/130.5 \times 5/13 = 2.5/13.
  3. Loaded term: 0.8×8/13=6.4/130.8 \times 8/13 = 6.4/13.
  4. Add: (2.5+6.4)/13=8.9/13≈0.685(2.5 + 6.4)/13 = 8.9/13 \approx 0.685.
  5. Compare with the forecast before any flip: 0.5×0.5+0.8×0.5=0.650.5 \times 0.5 + 0.8 \times 0.5 = 0.65.

Interpretation: after one head, the forecast for the next flip rises from 65% to about 68%. The shift is small because one flip is weak evidence. The forecast is neither 0.5 nor 0.8. It is a blend of the two coins, in proportion to how believable each now is.

Example
Example 2: three candidate biases (the standard case)

The heads probability is θ∈{0.2,0.5,0.8}\theta \in \{0.2, 0.5, 0.8\} with a uniform prior. Five flips give four heads and one tail. The posterior lesson gives posterior weights of about 0.01120.0112, 0.27300.2730 and 0.71580.7158 for the three values. Use them to forecast the next flip.

  1. A flip lands heads with probability θ\theta, so the forecast is p(H∣x)=∑θθ p(θ∣x)p(H \mid x) = \sum_\theta \theta\, p(\theta \mid x).
  2. Term for θ=0.2\theta = 0.2: 0.2×0.0112=0.002240.2 \times 0.0112 = 0.00224.
  3. Term for θ=0.5\theta = 0.5: 0.5×0.2730=0.136500.5 \times 0.2730 = 0.13650.
  4. Term for θ=0.8\theta = 0.8: 0.8×0.7158=0.572640.8 \times 0.7158 = 0.57264.
  5. Add the three terms: 0.00224+0.13650+0.57264=0.71138≈0.7110.00224 + 0.13650 + 0.57264 = 0.71138 \approx 0.711.
  6. Check against the unrounded weights. They were 0.001280.00128, 0.031250.03125 and 0.081920.08192, with total 0.114450.11445. The weighted numerator is 0.2×0.00128+0.5×0.03125+0.8×0.08192=0.0814170.2 \times 0.00128 + 0.5 \times 0.03125 + 0.8 \times 0.08192 = 0.081417, and 0.081417/0.11445≈0.7110.081417 / 0.11445 \approx 0.711. The rounding did not change the answer.

Interpretation: the forecast for heads is about 71%. It sits below the best single bias of 0.8, because the posterior still gives about 27% to the fair-ish coin at 0.5 and a little to 0.2. The forecast is an honest blend, not the most likely coin's prediction.

Example
Example 3: will the next email contain the word free? (realistic)

A mail filter, as in Posterior Distribution, starts with a 40% prior on spam. The word "free" appears in 30% of spam and 2% of ordinary mail. One email containing "free" has arrived, and the posterior is spam 10/11 and ordinary mail 1/11. Forecast whether the next email contains "free". Assume that, once its class is known, the next email is independent of the first.

  1. The forecast is (rate of "free" in spam) times (posterior probability of spam) plus (rate in ordinary mail) times (posterior probability of ordinary mail).
  2. Spam term: 0.30×10/11=3.00/110.30 \times 10/11 = 3.00/11.
  3. Ordinary term: 0.02×1/11=0.02/110.02 \times 1/11 = 0.02/11.
  4. Add: (3.00+0.02)/11=3.02/11≈0.275(3.00 + 0.02)/11 = 3.02/11 \approx 0.275.
  5. Compare with the forecast before any email: 0.40×0.30+0.60×0.02=0.1320.40 \times 0.30 + 0.60 \times 0.02 = 0.132. The forecast rose from about 13% to about 27%.

Interpretation: one "free" email roughly doubles the chance that the next email has the word. The filter's belief moved toward spam, and the forecast moved with it. The independence assumption is what lets the forecast depend on the class alone. If emails arrived in bursts from one sender, that assumption would fail and the forecast would be too low.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
Few data, so the posterior is wideThe forecast is vague and close to the prior predictiveAccept it, since it is honest; collect more data if the forecast must be sharp
The model is wrongThe forecast is confidently wrong about the kind of data it was fitted onPosterior predictive checks: simulate replicated data and compare it with the real data
Observations depend on each other beyond the parameterIndependence is violated, so the forecast is too narrow or biasedAdd the dependence to the model, for example a hierarchical or time-series structure
The integral has no closed formThe exact sum or integral cannot be written downMonte Carlo: sample parameters from the posterior and average the simulated predictions

A subtler trap: if you fit the model on the data and then score the predictive on the same data, the score is too optimistic, because the model has already adapted to those points. Fitted-model scores and the posterior predictive both suffer from this. Leave-one-out cross-validation handles it by scoring each point with a predictive density computed without that point. WAIC (the widely applicable information criterion) approximates the same idea from a single fit.

History

The predictive idea is as old as Bayesian inference. In the 1770s Pierre-Simon Laplace worked out what is now called the rule of succession: after ss successes in nn trials, with a uniform prior on the success chance, the probability that the next trial succeeds is (s+1)/(n+2)(s+1)/(n+2). That is exactly a posterior predictive forecast under a uniform prior.

The use of the predictive as a tool for checking models was developed later. In 1984 Donald Rubin argued that a model should be judged by whether data it generates look like the data actually observed. Andrew Gelman and colleagues turned this into routine practice through posterior predictive checks, which are described in Bayesian Data Analysis. Leave-one-out scoring of predictive densities became a standard model-comparison tool later, with the 2017 work of Vehtari, Gelman and Gabry on cross-validation and WAIC. It caught on because a single distribution over new data answers both "what happens next?" and "is my model any good?".

Recap

The chain runs like this. A prior and the data give a posterior over the parameter. Each parameter value makes its own prediction for a new observation. Weighting those predictions by the posterior and summing gives the posterior predictive. Its closed form exists for conjugate pairs, and sampling handles the rest. The same weighted-sum shape reappears in Bayesian Model Averaging, where the weights are over models instead of parameter values. It also drives leave-one-out and WAIC model comparison, which scores each held-out point by its predictive density.

Check yourself

QuestionRecall: in one sentence, what does the posterior predictive distribution forecast, and what two ingredients are averaged to produce it?Show answer

It forecasts a new, unseen observation given the data already seen. It averages, over every candidate parameter value, the probability of the new observation under that value (the likelihood), weighted by the posterior belief in that value.

QuestionComputation: a coin is fair (heads probability 0.5) or biased toward heads (heads probability 0.9), each with prior 1/2. You flip twice and get two heads. What is the posterior predictive probability that the third flip is heads?Show answer

The likelihood of two heads is 0.250.25 for the fair coin and 0.810.81 for the biased coin. Multiplied by the prior, these give 0.1250.125 and 0.4050.405. The evidence is 0.125+0.405=0.5300.125 + 0.405 = 0.530, so the posterior is 0.125/0.530≈0.2360.125 / 0.530 \approx 0.236 for fair and 0.405/0.530≈0.7640.405 / 0.530 \approx 0.764 for biased. The forecast is 0.5×0.236+0.9×0.764=0.118+0.688=0.8060.5 \times 0.236 + 0.9 \times 0.764 = 0.118 + 0.688 = 0.806. Equivalently, (0.5×0.125+0.9×0.405)/0.530=0.427/0.530≈0.806(0.5 \times 0.125 + 0.9 \times 0.405) / 0.530 = 0.427 / 0.530 \approx 0.806.

QuestionWhy: why is the posterior predictive wider than the plug-in forecast that uses only the most likely parameter value, especially when data are few?Show answer

The plug-in forecast assumes the best parameter value is exactly right, so its spread comes only from the noise in one new observation. The posterior predictive also averages over the parameter values that are still plausible. When data are few, many values remain plausible, and their predictions disagree, which widens the forecast. As data accumulate the posterior narrows and the two forecasts converge.

QuestionApplied: a model fitted to 200 sensor readings is meant to describe the sensor. Describe how you would use the posterior predictive to check whether the model could have produced readings like yours.Show answer

Draw parameter values from the posterior. For each draw, simulate a replicated data set of 200 readings from the model. Compute a summary that matters for your use, such as the largest reading, the variance or the fraction of readings above a threshold. Compare the summary of the real readings with the distribution of that summary over the replicated sets. If the real value sits far in the tail, the model fails to capture something about the data, and you should revise it.

Sources