Which diagnostics would catch a sampler that mixes badly, and which would catch one that computes the wrong posterior?
Notebook capstone 6~30 minadvanced Simulated measurements for a normal-location model
The story
A colleague hands you two inference routines for the same simple model and a folder of diagnostics: the chains look fine, and simulation-based calibration (SBC) passes. One routine is correct. The other was refactored and, by mistake, never reads the data: it returns draws from the prior.
The model is small enough to have an exact posterior, so you can check the samplers against arithmetic rather than against another approximation. You'll run Metropolis chains with a well-tuned and a sticky proposal and compute split R-hat, then run SBC on both routines, first ranking the parameter itself and then a quantity that depends on the data. The failure kept on purpose: a passing diagnostic is evidence only about the errors it can see.
Data: Simulated measurements for a normal-location model · Simulated. Generated in the notebooks with a written-out Wichmann–Hill stream (ML reference, computational-validation workflow).
Compute the exact posterior mean, then split R-hat for four well-tuned chains and four sticky ones started far apart.
Which chains agree with each other and with the exact posterior, and what does R-hat say about the sticky ones?
Notebook exercise: Metropolis chains and split R-hat. Check a Metropolis sampler against an exact posterior, then compute split R-hat for a well-tuned and a sticky sampler. 3 checks in Python or R.
Stage 2 · notebooks · ~15 min
SBC and the data-ignoring algorithm
Run SBC on the correct and the data-ignoring routine by ranking the parameter, then rank a quantity that uses the data, and compare the chi-square statistics.
Why does SBC on the parameter alone pass the broken routine, and what exposes it?
Notebook exercise: Simulation-based calibration and the wrong algorithm. Run simulation-based calibration on a correct and a data-ignoring posterior sampler, and see which test quantity catches the broken one. 3 checks in Python or R.
Hints
A high acceptance rate can mean tiny steps; compare chains started far apart.
When the true value is drawn from the prior, prior draws rank it uniformly too.
Rank a quantity that depends on the data, such as closeness to the data mean.
report
Validation report for the two routines
Write the validation report: which checks each routine passed and failed, why parameter-only SBC missed the bug, which check caught it, and what you would add to the routine's test suite.
Exact reference
Mixing
Calibration
What to test from now on
Rubric
Criterion
Points
Compares the samplers with the exact posterior.
1
Reports split R-hat for both proposals and explains why the sticky chains fail.
2
Explains why parameter-only SBC passes the data-ignoring routine.
2
Shows that a data-dependent quantity exposes it.
2
Proposes tests that include data-dependent quantities and an exact reference.
1
Model answer
Show the model answer
Exact reference. With a known observation SD and a normal prior, the posterior is exactly normal; the well-tuned Metropolis chains agree with its mean, outlier included in the model.
Mixing. Started far apart, the four well-tuned chains mix and their split R-hat sits near 1. The sticky chains accept almost every tiny step, which looks healthy, but they still remember where they started, and split R-hat is well above the usual 1.01 alarm.
Calibration. SBC ranking the parameter passes the correct routine, and it also passes the routine that ignores the data: when the true value is drawn from the prior, prior draws rank it uniformly too. Ranking closeness to each replicate's data mean instead exposes the bug at once, with a chi-square far above anything uniform ranks produce, because the true value sits much nearer the data than prior draws do.
What to test from now on. Keep the exact-posterior comparison as a unit test, add SBC on data-dependent quantities, and report rank-normalized split R-hat and effective sample size for every fit. None of these says whether the model, outlier and all, fits the data; posterior predictive checks answer that.