Counterfactual Marginalisation: Framework for Evaluating Robustness to Nuisance Variables

Yasin Ibrahim, Hermione Warr, Robin J. Evans, Konstantinos KamnitsasarXiv 2026

TL;DR

This paper introduces counterfactual marginalisation, a test-time evaluation framework that uses causal generative models to audit medical image classifiers. By generating counterfactual variants of test images (e.g., altering a patient's apparent age or sex) and averaging predictions across them, the framework exposes hidden demographic biases and model instabilities—even when ground-truth disease labels are entirely missing.

What Problem Does This Paper Address?

Deep learning models frequently achieve high accuracy on medical imaging test sets by exploiting "shortcuts"—relying on demographic attributes (like age or sex) or image acquisition artifacts (like scanner types) rather than genuine pathology.

Standard evaluation methods, which rely on point-estimate accuracy on a held-out dataset, fail to detect these brittle decision rules. While structural causal models (SCMs) have previously been used to generate counterfactuals for data augmentation or explainability, this paper tackles a different challenge: how to rigorously evaluate a trained model's robustness and fairness at test time against these nuisance variables.

Methods

The authors propose a test-time evaluation procedure called Counterfactual Marginalisation:

  1. Counterfactual Generation: For each test image, an SCM-based generative model intervenes on specific nuisance variables (e.g., changing sex from Male to Female, or sweeping across different ages) while keeping patient-specific latent features (exogenous noise) fixed.
  2. Marginalisation: The trained classifier runs on all these counterfactual variations. The framework then averages the predicted probabilities over a target intervention distribution (such as a uniform distribution across demographic strata).
  3. Robustness Metrics: Using these marginalised predictions, the authors define several novel evaluation metrics:
  4. Counterfactual Risk & Tail Risk: Evaluates predictive performance after marginalising out demographic effects, including a tail-risk measure (using Conditional Value at Risk, CVaR) to test vulnerability to the most adverse demographic interventions.
  5. Counterfactual Calibration: Measures whether the probabilities obtained after marginalisation remain clinically interpretable as calibrated risk estimates.
  6. Counterfactual Stability: Quantifies how much a model's predictions vary or flip solely due to changes in nuisance attributes (e.g., variance and label-flip rates).
Fig. 1: Overview of the proposed Counterfactual Marginalisation evaluation framework

Datasets

The framework was validated using two large-scale chest X-ray datasets:

  • CheXpert: Used for training the counterfactual generator and evaluating the classifiers.
  • MIMIC-CXR: Used to test cross-dataset generalization robustness.

The evaluation focused on the binary classification of Pleural Effusion (PE), with test splits carefully balanced across sex and age groups to ensure controlled experimental settings.

Key Insights and Ideas

  • Causal Test-Time Augmentation: Instead of averaging predictions over ad-hoc image transformations like rotations or crops, this method averages over clinically meaningful, causally-defined demographic perturbations.
  • Evaluation Without Labels: A major "aha" moment of the paper is that stability metrics (like variance and label-flip rates across counterfactuals) can measure a model's sensitivity to nuisance variables without requiring ground-truth disease labels.
  • Variance Reduction: Mathematically, the authors prove that the counterfactual estimator achieves lower variance than standard observational subgroup estimators (Proposition 1). Instead of splitting data into smaller, rarer subgroup buckets, it leverages the entire test set by synthetically shifting every image into every subgroup.

Key Results

  • Detecting Hidden Bias: The authors simulated biased predictors by injecting artificial logit offsets or corrupting training distributions to induce spurious correlations. Standard risk metrics ($R_{orig}$) often failed to flag increasing bias, whereas counterfactual risk metrics consistently tracked and exposed it.
  • Better Calibration Assessment: Marginalised Expected Calibration Error (ECE) increased reliably as models became more biased, providing a truer picture of clinical utility than standard ECE.
  • Strong Proxy for Performance Gaps: The label-free stability metrics correlated strongly ($r = 0.78$ to $0.92$) with actual worst-case AUC gaps across subgroups, proving they can serve as excellent proxies for bias when ground-truth labels are missing at test time.

Model calibration comparison Stability metrics correlation with AUC gaps

Limitations and Future Work

  • Dependence on the Generator: The framework's validity hinges entirely on the realism and causal accuracy of the underlying counterfactual image generator. If the generator introduces artifacts or fails to perfectly isolate the nuisance variable, the evaluation metrics will be skewed. Consequently, it must be used alongside generator validation, not as a total replacement for conventional external evaluation.
  • Scope: The current implementation focuses on binary classification and a small set of demographic variables.
  • Future Directions: The authors suggest exploring sensitivity to causal graph specifications, incorporating generator uncertainty into the metrics, and extending the framework to multi-label clinical settings.

Summary updated

BibTeX
@misc{ibrahim2026counterfactual,
  author = {Yasin Ibrahim and Hermione Warr and Robin J. Evans and Konstantinos Kamnitsas},
  title = {{Counterfactual Marginalisation: Framework for Evaluating Robustness to Nuisance Variables}},
  year = {2026},
  eprint = {2609.10778},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.10778},
}
Figure