Monte Carlo stability audit
A contrast between two models is a sum over units of paired per-unit predictive
score differences, each estimated by Monte Carlo (often importance sampling with
heavy-tailed weights). op_infer.audit checks the reproducibility of such a
total before it is read, on a sample of units (Vehtari, Gelman and Gabry 2017,
Statistics and Computing 27:1413; Sivula, Magnusson, Matamoros and Vehtari
2025, Bayesian Analysis, on the uncertainty of elpd differences).
- Choose the sample from a tail diagnostic only.
audit.audit_sample(diagnostic, edges=..., per_stratum=..., seed=...)takes a per-unit diagnostic (for example the largest Pareto shape over the models) and draws a stratified sample. It has no argument through which a score could enter (enforced by its signature), so the sample cannot depend on the scores. A non-finite diagnostic goes to the top stratum, never out of the frame. - Re-score the sample with independent random keys and larger Monte Carlo settings, using your own scorer.
- Estimate.
audit.stability_estimate(original, audit, sample)takes the per-unit contrast values of the sampled units in both scorings and returns the estimated shift of the total, its sampling standard error (finite population correction included) andmc_sd, a conservative standard deviation of the Monte Carlo noise of the total over all units.var(audit - original)holds the noise of both runs, somc_sdoverstates the noise of the original run. - Label.
audit.stability_label(estimate, se, max_mc_ratio=..., max_shift_ratio=...)returnsstableornot_assessable, nevertied. Stable needs no failed audited unit,mc_sd <= max_mc_ratio * seand|shift| + z * shift_se <= max_shift_ratio * se, withsethe standard error of the original total. An audit too small to bound the shift is not assessable. The ratios have no defaults: they are reading-rule choices to fix before the audit is read.
A nonempty stratum with fewer than two usable audited units makes the estimate
insufficient (NaN errors) and the label not_assessable. A sampled unit with a non-finite value in either scoring is counted in
n_failed and left out of the moments; any failure makes the contrast not
assessable. The estimates assume finite-variance, independent per-unit Monte Carlo errors
and independent random keys in the two scorings; correlated errors, shared keys
and heavy-tailed importance-sampling errors (Pareto shape above 0.5) can make
mc_sd understate the noise. A stable label means the total is reproducible
against an independent rerun, not that it is accurate. z (default 1.645) is the
only default of the rule. The package does not score units; use your estimator
and, for paired contrasts, compare.paired_predictive_contrast
(design studies).
Reading a paired contrast
compare.three_valued_contrast reads a paired held-out contrast with a rule
fixed in advance. With mean paired difference d, its standard error se, a
caller-supplied floor in score units and a multiplicity quantile z_K for the
K registered contrasts, the contrast is separated when
|d| > max(floor, z_K * se), tied when |d| <= max(floor, 1.96 * se), and
borderline in between. Convert the result of audit.stability_label to a
Boolean with stable=(audit_result["label"] == "stable"); omit stable or
pass None only when no audit was run. Passing a label string or the result
dictionary itself is rejected. A contrast whose
audit failed, or whose scores are non-finite or fewer than two, is
not assessable, never tied. Tied means the difference lies within the fixed
bounds, not that the models are equivalent; the normal approximation to a
predictive-score difference is poorly calibrated when predictions are similar,
under misspecification with outliers and for few units (Sivula, Magnusson,
Matamoros and Vehtari 2025, arXiv:2008.10296), which is why the floor exists.