Deep Counterfactual Estimation with Categorical Background Variables

Edward De Brouwer

Deep Counterfactual Estimation with Categorical Background Variables

TL;DR

Estimating counterfactuals—answering "what would have happened if I had acted differently?"—is notoriously difficult because multiple causal models can explain the same observed data while predicting entirely different counterfactual outcomes. This paper introduces CounterFactual Query Prediction (CFQP), a method that achieves reliable counterfactual estimation by assuming the primary hidden factors driving treatment responses are categorical. By leveraging a neural Expectation-Maximization (EM) approach, CFQP outperforms existing deep-learning models on complex data like images and clinical time series.

The Challenge of Counterfactuals

In the "ladder of causation," counterfactuals sit at the highest rung. Unlike standard machine learning (which predicts associations) or interventional studies (which predict the average effect of a treatment), counterfactuals are retrospective. They ask about a specific individual: "Given that this patient received Treatment A and had Outcome Y, what would have happened if they had received Treatment B instead?"

The fundamental challenge is non-identifiability. To calculate a counterfactual, you typically need a Structural Equation Model (SEM) that describes the underlying data-generating process. However, many different SEMs can produce the exact same observed data distribution but yield completely different counterfactual results. Without further assumptions, we simply cannot know which one is "correct" from observational data alone. This is particularly problematic for high-dimensional data like medical images or sensor time series, where traditional causal models struggle to scale.

Bridging the Gap: Categorical Background Variables

The authors bridge the gap between rigid causal theory and flexible deep learning by introducing a specific assumption: Categorical Background Variables. They posit that while the observed data (covariates $X$, outcome $Y$, treatment $T$) is continuous, the hidden "noise" or background variables ($U$) that dictate how an individual responds to treatment can be decomposed into a categorical latent variable ($U_Z$) and independent continuous noise ($U_\eta$).

Think of this as "patient types": two patients might look similar based on their observed covariates ($X$), but belong to different hidden physiological groups ($U_Z$) that react differently to the same drug.

The CFQP Method

To implement this, the authors propose CFQP, which uses a Neural Expectation-Maximization mechanism to iteratively discover these hidden groups and learn their specific treatment responses.

The CFQP architecture utilizing a Neural Expectation-Maximization approach.

The process works in three main steps:

  1. Initialization: Train a global "average" model ($m_0$) to predict outcomes across the entire dataset.
  2. Expectation (Clustering): Group data points into $K$ clusters based on their residuals (how much their actual outcome differs from the global average). This identifies the likely latent category ($U_Z$).
  3. Maximization (Learning): Train $K$ separate neural networks ($m_k$), one for each category, to specialize in that group's specific treatment response.

To predict a counterfactual for a new case, the model first determines which cluster the individual belongs to based on their observed factual outcome, and then uses that cluster's specific model to simulate the alternative treatment.

Key Insights and Results

The core theoretical insight of the paper is identifiability through discreteness. If hidden factors are discrete (clusterable), the counterfactual becomes identifiable. We can use the observed outcome as a "fingerprint" to assign an individual to a latent class, which then uniquely determines their counterfactual path. The authors provide mathematical proofs showing that under their clustering assumptions, the counterfactual distribution is identifiable in the limit.

The authors evaluated CFQP on three high-dimensional datasets where ground-truth counterfactuals are known: a Harmonic Oscillator physics simulation, a Cardiovascular Simulator, and Counterfactual MNIST. CFQP significantly outperformed state-of-the-art baselines like Deep-SCM and Diff-SCM (diffusion-based models) across all tasks.

  • Accuracy: On the Cardiovascular dataset, CFQP achieved a Mean Squared Error (MSE) of 0.077, compared to 0.206 for the next best model (Diff-SCM).
  • Image Consistency: In the Counterfactual MNIST task (where treatment is rotation and the hidden variable is color), CFQP was the only model that consistently preserved the "hidden" color of the digit across different counterfactual rotation angles. Other models tended to revert to an "average" color or lose the digit's identity entirely.
Counterfactual MNIST results showing CFQP successfully preserving the hidden color variable across different treatments (rotations).

Limitations and Future Work

While powerful, the method has a few notable constraints:

  • The "K" Problem: The model requires the number of latent clusters ($K$) as a hyperparameter. While it can be tuned using validation on factual data, the "true" number of hidden groups in real-world scenarios may be unknown or ill-defined.
  • Clusterability Assumption: The method relies on the data being "clusterable"—meaning the differences between hidden groups are larger than the random noise within those groups. If background variables are purely continuous and smooth, this approach might struggle.
  • Strong Ignorability: Like most causal methods, it assumes there are no unobserved confounders that affect both the treatment assignment and the outcome.

Overall, CFQP provides a practical and theoretically backed framework for bringing counterfactual reasoning to complex, high-dimensional domains like precision medicine, where understanding individual-level "what-ifs" is critical.

Summary updated

Abstract

Referred to as the third rung of the causal inference ladder, counterfactual queries typically ask the "What if ?" question retrospectively. The standard approach to estimate counterfactuals resides in using a structural equation model that accurately reflects the underlying data generating process. However, such models are seldom available in practice and one usually wishes to infer them from observational data alone. Unfortunately, the correct structural equation model is in general not identifiable from the observed factual distribution. Nevertheless, in this work, we show that under the assumption that the main latent contributors to the treatment responses are categorical, the counterfactuals can be still reliably predicted. Building upon this assumption, we introduce CounterFactual Query Prediction (\method), a novel method to infer counterfactuals from continuous observations when the background variables are categorical. We show that our method significantly outperforms previously available deep-learning-based counterfactual methods, both theoretically and empirically on time series and image data. Our code is available at https://github.com/edebrouwer/cfqp.
BibTeX
@inproceedings{brouwer2022deep,
  author = {Edward De Brouwer},
  title = {{Deep Counterfactual Estimation with Categorical Background Variables}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=57ZKV2YuwjL},
}
Figure