Bayesian Monte Carlo and MCMCLesson 76 of 76 · 10 min
Predict new observations
Propagate posterior parameter uncertainty into a future outcome distribution.
Posterior predictive sampling first draws a parameter from its posterior, then draws new observations conditional on that parameter. The resulting distribution accounts for parameter uncertainty and future outcome variability under the model. It is distinct from the posterior distribution of the parameter alone.
For the beta-binomial example, draw p from beta(20,14), then generate a future count among 20 observations with that p. Plugging the posterior mean directly into a binomial omits uncertainty in p. Both have the same expected count here, but the predictive mixture has greater variance.
The beta-binomial distribution gives an exact predictive mean and variance to check the simulation. Predictive checks compare features of replicated and observed data to reveal mismatch. A tail comparison under the fitted predictive model can be useful criticism, but does not by itself validate the prior or observation model. Keep numerical accuracy separate from model adequacy.
- Draw an uncertain parameter
- Draw a future group
- Keep the targets distinct
Can the plug-in and full predictive distributions share a mean but have different spreads?
Write a prediction (optional)
Seeded teaching simulation
Select Run Python below with the code unchanged.
A saved draft is open. To run the published example, open Tools and select Restore example. Recover draft brings your code back.
Execution error
Technical error details
Your result
Published example output
This result comes from the original Python. Your runs appear above. Build environment ↗
Full predictive mean / variance: 11.762 7.519 Exact beta-binomial mean / variance: (np.float64(11.764705882352942), np.float64(7.474048442906574)) Plug-in mean / variance: 11.753 4.742 Full predictive count quantiles: [ 7. 12. 16.] Posterior p quantiles: [0.446 0.591 0.722]
Read the first result
Count quantiles describe future group outcomes; p quantiles describe a parameter. Neither is the numerical error bar on an estimated mean.
Try an edit
Replace a, b, future_n, draws = 20, 14, 20, 20000 with a, b, future_n, draws = 20, 14, 100, 20000. Select Run Python again. Compare the second numbers in Full predictive mean / variance and Plug-in mean / variance. What happens to the variance gap when more outcomes share the same uncertain probability?
Scope. The model assumes future observations share the same p and sampling mechanism as the invented evidence. Changing conditions and model uncertainty require further analysis.
Try a fresh case
Which simulation represents the full posterior predictive count?
Need a hint?
Hint 1
Write the units of p and of the count.
Hint 2
First sample the uncertain parameter, then the conditional observation.