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.
A prior predictive check simulates data from the model using parameters drawn from the prior alone.
\[\theta^{(i)} \sim p(\theta), \qquad y^{(i)} \sim p(y \mid \theta^{(i)})\]
Then ask: do these simulated epidemics look like something that could plausibly happen?
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 is the cheapest check in the workflow: it needs no data and no fitting.
“Uninformative” priors are rarely uninformative on the scale you care about.
A flat prior on \(R_0\) from 1 to 20 sounds humble. Push it through the model and most of that range produces epidemics that infect the entire population within a fortnight.
Vague on the parameter is not vague on the outcome.
A posterior predictive check simulates data using parameters drawn from the posterior:
\[\theta^{(i)} \sim p(\theta \mid y), \qquad y^{\text{rep},(i)} \sim p(y \mid \theta^{(i)})\]
If the model is adequate, the observed data should look like a typical draw from this distribution, not an outlier.
Pick a summary statistic \(T(y)\) — peak height, epidemic duration, final size — and compare the observed value against its distribution under replication:
\[p_B = \Pr\big(T(y^\text{rep}) \geq T(y) \mid y\big)\]
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.
Plot observed minus predicted over time.
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.
SBC is expensive: it means fitting the model hundreds of times. Reserve it for models you intend to rely on repeatedly.
Failure is information. In rough order of what to try:
Resist the temptation to keep adding parameters until the fit looks good. A model that fits everything predicts nothing.
There is no threshold. The honest answer is: when it captures the features relevant to the question, and you understand the ways it does not.
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 good plots cannot.
In the practical you will
predict and deconditionSimulation-based calibration is written up at the end of the session for you to work through afterwards.
Model checking and validation