Overview

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.
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 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 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 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.
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 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 𝑝 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 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 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.
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).

FAQ

What is the purpose of model checking in Bayesian analysis?Model checking helps us evaluate whether a Bayesian model is sensible and useful, since a model can still be wrong even if the math and posterior look reasonable. It lets us test whether the prior and likelihood match our knowledge and the observed data.
What is a prior predictive check?A prior predictive check generates simulated data from the prior before seeing the real data, then compares those simulations with our expectations. It is a sanity check for whether the prior can produce realistic outcomes.
How do prior predictive checks work in the tea vs. coffee example?We first sample values of the tea preference proportion p from the prior, then use each sampled p to generate possible counts k of tea drinkers out of n people. If the simulated counts look unreasonable, the prior fails the check.
Why are prior predictive checks useful before fitting a model?They can reveal a bad prior early, before we spend time fitting the model to data. This saves effort and helps avoid using assumptions that would generate unrealistic predictions.
What is a posterior predictive check?A posterior predictive check generates simulated data from the posterior after conditioning on observed data, then compares those simulations with the actual data. It checks whether the trained model can reproduce patterns seen in reality.
How is a posterior predictive check different from prediction on future test data?Posterior predictive checks are mainly a sanity check against the training data, not a forecast for future unseen cases. Their goal is to see whether the model can explain the data it was fit on.
What does it mean if the observed data lies in the tails of the posterior predictive distribution?It means the model considers the observed data unlikely, suggesting a mismatch between the model and the data. If too many samples fall on one side of the observation, the model may be misspecified.
What is the marginal likelihood of a Bayesian model?The marginal likelihood is the probability of the observed data under a model after averaging over all possible parameter values weighted by the prior. It measures how well the model explains the data overall.
What is a Bayes factor?A Bayes factor is the ratio of the marginal likelihoods of two models. It tells us how much more one model is supported by the data compared with another.
How does the Bayes factor relate to Occam’s razor?The Bayes factor naturally balances fit and simplicity: a simpler model is favored if it explains the data nearly as well as a more complex one. In this way, it acts like a Bayesian version of Occam’s razor.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Bayes Grokking Bayes ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking Bayes Grokking Bayes ebook for free