Goodness of fit and posterior predictive checks
Compare observed discrepancies with a correctly generated reference distribution and separate parameter estimation from model criticism.
On this page
The question for today
What you’ll understand
- Specify a discrepancy and its reference experiment.
- Account for fitted parameters when calibrating a goodness-of-fit statistic.
- Construct a posterior predictive probability without mistaking it for a hypothesis probability.
A precise parameter estimate can be scientifically unhelpful if the observation model is wrong. Model checking asks whether important features of the data are consistent with that model, including its noise, selection and dependence assumptions. A single discrepancy reduces a data set to one diagnostic, so no successful check proves every aspect correct. We will compare a simple exact frequentist reference calculation with a posterior predictive calculation, making clear which uncertainty is averaged in each.
A discrepancy needs a sampling reference
Suppose independent Gaussian observations have known standard deviations and a fully specified mean vector. The sum of squared standardized residuals has a chi-square distribution with the number of observations as its degrees of freedom. If instead linear mean parameters are fitted from the same data with full-rank design and known covariance, the minimized quadratic residual has fewer degrees of freedom. This exact result depends on the linear Gaussian model; an arbitrary nonlinear fit or estimated noise scale needs additional justification.
For a discrepancy where larger values indicate worse fit, the frequentist p-value is the probability under the specified model of a discrepancy at least as large as observed. It is not the probability that the model is true, nor the probability that the data arose by chance. Discrete discrepancies have discrete tail probabilities, and nuisance parameters can make the reference law uncertain. A simulation calibration should reproduce fitting and selection as well as generate events; otherwise it may compare unlike procedures.
Posterior prediction includes parameter uncertainty
A Bayesian model check can generate a parameter from the posterior and then generate replicated data from the corresponding sampling model. This gives the posterior predictive distribution. The replicated experiment must match the aspect being checked: a new measurement, a repeated count at the same exposure, or a conditional shape sample are different targets. Holding a fitted parameter fixed instead produces a plug-in prediction and can understate predictive variation. The posterior predictive mixture retains uncertainty about the parameters within the chosen model.
Compare a chosen discrepancy of replicated and observed data. A discrepancy may depend on the unknown parameter, in which case both sides must use the same sampled parameter in the comparison. Posterior predictive tail areas use observed data both to fit and to check, so their null distribution is generally not uniform. They should not automatically be interpreted using the same repeated-sampling thresholds as a calibrated frequentist p-value. A prediction of a particular future count is also not itself a discrepancy-based p-value.
Choose diagnostics that expose plausible failure modes
A total residual sum can miss time drift, asymmetric tails or a narrow local excess. Inspect residuals versus acquisition time, detector region and predicted scale when those comparisons are physically relevant. The covariance used to standardize residuals matters: correlated residuals cannot generally be treated as independent pulls. Quantile checks, held-out predictions and control-region comparisons can reveal different failures. Selection of the most surprising plot after many checks needs acknowledgment, rather than treating its tail probability as a predeclared single test.
A model can fail because the physical mean is wrong or because the measurement process is wrong. An omitted background or a time-dependent efficiency may mimic a new physical effect. Follow a failed check with a physically motivated revision and test its implications, ideally with independent information. A large p-value can also reflect low power, overestimated errors or an overflexible model. Report the discrepancy, reference construction and diagnostic limitations so another analyst can judge which alternatives the check could actually detect.
Work it through
A fixed two-reading Gaussian model
Two independent readings are 1 and 3 V. The fully specified model gives mean 2 V and known standard deviation 1 V for each; no parameters are fitted. Compute the residual discrepancy and its upper-tail probability, using .
The standardized residuals are minus one and plus one, because each difference from the fixed mean is divided by one volt.
Their squared sum is . There are two independent Gaussian residual directions and no fitted mean, so the reference is chi-square with two degrees of freedom.
The upper-tail probability is . It describes a tail event under this fixed model; it does not give a 36.8% probability that the model is true.
The discrepancy is 2 and its exact model-based upper-tail p-value is approximately 0.368.
The living notebook
Explore the model
Interactive lab · sampling
The reference distribution changes with the model
Reset and set BOTH Success probability p = 0.5 and Independent samples n = 20; predict mean sample proportion 0.5 and variance 0.0125. For a fresh comparison, Reset and set p = 0.25 and n = 20; predict mean 0.25 and variance 0.009375.
- Mean sample proportion
- 0.5
- Sample-mean variance
- 0.0125
- Uniform CDF error bound
- ≤ 0.1062
Exact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forThese are exact binomial sampling distributions at fixed p with a normal comparison. The lab does not fit a model, calculate a goodness-of-fit p-value or simulate posterior predictive replicates.
Pause & reason
Check your understanding
Your turn
Try it yourself
One Bernoulli success is observed with a uniform Beta(1,1) prior. For two new conditionally independent trials sharing the same p, find the posterior predictive probability that both succeed. Compare with plugging the posterior mean into p squared.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The posterior is Beta(2,1). Integrate p squared, using the beta moment a(a+1)/[(a+b)(a+b+1)].
Compare with the solution
The posterior predictive probability is . Plugging in the posterior mean instead gives . Their difference is the posterior variance of p, since the exact prediction uses the posterior expectation of p squared. The two future trials are independent conditional on p, but not after averaging over uncertainty about their shared p. This is a future-event probability, not a goodness-of-fit tail area or a probability that the Bernoulli model is true.
Keep the idea
Take it with you
- A goodness-of-fit statistic needs the reference law of the actual procedure.
- Posterior prediction averages sampling variation and parameter uncertainty.
- A successful diagnostic cannot prove every part of a model correct.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.