4 Model checking and comparison: Evaluating and picking out the best Bayesian model
Bayesian modeling is not finished once the posterior looks mathematically consistent; a good model can still be wrong in important ways. This chapter explains how to evaluate a Bayesian model by checking whether its assumptions produce sensible simulated data before seeing the observations, whether the fitted model can reproduce the data after learning from it, and how to compare competing models using Bayesian measures of fit. It uses the tea-versus-coffee example and house-price regression to show that even simple models can fail unless they are tested against intuition and reality.
A key practical tool is sampling from probability distributions, since both prior predictive and posterior predictive checks rely on generating simulated values from priors or posteriors and then examining the resulting datasets. Prior predictive checks ask whether the prior alone leads to realistic outcomes: in the beverage example, a uniform prior may seem reasonable, while a highly skewed prior can predict implausibly low tea preference; in the house-price model, a normal prior on slope can produce negative house prices, revealing that the prior needs adjustment. Posterior predictive checks use the learned posterior instead, comparing simulated data to the observed data and checking whether the model reproduces patterns such as reasonable counts, credible intervals that cover the observations, or roughly normal residual behavior.
The chapter then turns to model comparison with marginal likelihoods and Bayes factors. The marginal likelihood measures how well a model explains the observed data by averaging likelihoods over all parameter values allowed by the model, and the Bayes factor compares two models by taking the ratio of their marginal likelihoods. In the tea example, the data favor the posterior model over the prior, and they can also favor one prior choice over another. This comparison naturally reflects a Bayesian version of Occam’s razor: simpler models are preferred when they explain the data at least as well as more complex alternatives, helping us choose models that are both plausible and not unnecessarily complicated.
True PDFs of Beta(1, 1) and 𝒩(100,100²) (left column) and the corresponding histograms and 10,000 samples drawn from the two probability distributions (right column). Under infinite samples, the shapes of the histograms approach the respective PDFs.
The procedure of a prior predictive check for the tea preference model. Each sample of the proportion 𝑝 from the prior yields a possible dataset in the form of the number of tea drinkers 𝑘 out of 𝑛 = 100 people surveyed. A prior predictive check fails if the simulated behavior doesn’t match our intuition.
The distribution of samples of 𝑘, the number of people preferring tea over coffee, based on the uniform prior of 𝑝 when we set 𝑛 = 100.
The distribution of samples of 𝑘, the number of people preferring tea over coffee, based on a skewed prior of 𝑝 when we set 𝑛 = 100.
The distributions of the samples of the price of a house whose square footage is denoted by the 𝑥-axis.
The distributions of the samples of the price of a house whose square footage is denoted by the 𝑥-axis, induced by an adjusted prior for the slope 𝑚.
The distribution of posterior samples of 𝑘, the number of people preferring tea over coffee, based on the posterior of 𝑝 when we set 𝑛 = 5.
The distribution of posterior samples of 𝑘, the number of people preferring tea over coffee, based on the posterior of 𝑝 that started from a skewed prior when we set 𝑛 = 5.
The distributions of the posterior samples of the price of a house whose square footage is denoted by the 𝑥-axis against the observed data.
The histogram of the 𝑧-scores under the Bayesian linear regression model.
Summary
- Sampling from a probability distribution allows us to simulate plausible outcomes from our beliefs and is essential for model checking in Bayesian analysis.
- Prior predictive checks simulate datasets from the prior to ensure that our model encodes reasonable assumptions before seeing the data.
- Posterior predictive checks simulate datasets from the posterior to see whether the model can replicate the observed data.
- Posterior predictive checks are necessary, but not sufficient, for validating a model—they ensure the model hasn’t failed, but don’t prove it’s correct.
- Bayesian models can produce unrealistic predictions if their priors or likelihoods are poorly chosen.
- Bayes factors provide a principled way to compare models by computing how well each explains the observed data.
- The Bayesian Occam’s razor effect favors simpler models that explain the data well, penalizing overly complex ones that do not improve fit.
- Bayes factors can be interpreted numerically, with values over 3.2 suggesting substantial evidence and values over 10 indicating strong evidence.
- Bayesian model comparison enables us to evaluate tradeoffs between generality (complexity) and specificity (fit to data).
Grokking Bayes ebook for free