Model fitting and inference for infectious disease dynamics
In the last session we asked whether the sampler worked: R̂, effective sample size, trace plots, divergences.
A converged chain tells you the algorithm did its job.
It says nothing about whether the model is any good.
You can have a perfectly converged posterior for a model that cannot possibly have produced your data.
| Question | Tools | |
|---|---|---|
| Diagnostics | Did the algorithm work? | R̂, ESS, trace plots, divergences |
| Model checking | Does the model make sense? | Prior and posterior predictive checks, residuals, SBC |
This session is about the second row.
Model checking is not a step at the end. Gelman et al. (2020) describe fitting as an iterative workflow:
Specify model Prior predictive check Fit Diagnose sampler Posterior predictive check
↺ if the checks fail, revise the model and go round again
So far the course has covered specifying, fitting and diagnosing. This session covers the two checking steps, and what to do when they fail.
The aim is not to prove the model is correct. Every model is wrong. The aim is to find the ways in which it is wrong that matter for the question you are asking.
The most remote inhabited island in the world: 284 people, one ship every few months.
An influenza-like illness arrived with a visiting ship and infected most of the island over eight weeks.
Two features make it interesting for our purposes:
A prior predictive check simulates data from the model using parameters drawn from the prior alone.
Then ask: do these simulated epidemics look like something that could plausibly happen?
Two hundred draws from this session’s priors, on an island of 284. Most burn through the population in a week.
Priors that put weight on impossible outcomes — attack rates above 100%, epidemics lasting decades, negative durations.
Priors that are far too vague, so the model considers almost anything possible and the data have to do all the work.
Priors that are accidentally informative, ruling out the truth before you start.
This needs no data and no fitting.
“Uninformative” priors are rarely uninformative on the scale you care about.
You saw this in the first session: Uniform(1, 20) on sounds reasonable but most of its range produces infeasible epidemics.
A uniform says an of 19 is exactly as plausible as one of 3.
A posterior predictive check simulates data using parameters drawn from the posterior:
If the model is adequate, the observed data should look like a typical draw from this distribution, not an outlier.
Pick a summary statistic — peak height, epidemic duration, final size — and compare the observed value against its distribution under replication:
These are not frequentist p-values and should not be thresholded at 0.05. They are a diagnostic for “which feature is my model missing”, not a test.
Scattered about zero, spread the same throughout.
Runs above then below zero: the model is wrong, not just noisy.
Spread grows with the prediction: try a negative binomial.
Autocorrelation in the residuals breaks the conditional-independence assumption in the likelihood.
Predictive checks compare the model to one dataset. Simulation-based calibration (Talts et al. 2018) checks whether the inference is correct on average, across datasets:
If the model and sampler are working, those ranks are uniformly distributed.
is itself a draw from the posterior it is ranked against, so its rank is uniform by construction. Nothing about the model being right enters it: SBC tests the inference, not the model.
The grey band is where a uniform histogram should sit.
SBC is expensive: it means fitting the model hundreds of times.
Failure is information. In rough order of what to try:
A model that fits everything is likely not to predict anything well.
There is no threshold.
Good enough means
Document the checks you ran, including the ones that failed.
A reader who knows where the model breaks can judge how far to trust it. A reader shown only the final results cannot.
In the practical you will
predict and deconditionSimulation-based calibration is written up at the end, to work through afterwards.
Model checking and validation