Counterfactual Generative Models for Time-Varying Treatments

Shenghao Wu, Wenbin Zhou, Minshuo Chen, Shixiang Zhu

TL;DR

This paper introduces a novel generative framework for estimating counterfactual outcomes in scenarios where treatments change over time. By integrating Inverse Probability of Treatment Weighting (IPTW) into the loss functions of state-of-the-art generative models like Diffusion and CVAEs, the authors can produce high-quality, high-dimensional counterfactual samples that capture individual disparities and multi-modal outcomes better than traditional average-effect methods.

What Problem Does This Paper Address?

In fields like public health and clinical science, decision-makers often need to know the "counterfactual": what would have happened to a patient or a population if a different sequence of treatments had been applied?

Two major hurdles make this difficult:

  1. Time-Varying Treatments: Treatments are rarely one-off events; they are sequential (e.g., a series of mask mandates over several weeks). This leads to an exponential explosion of possible treatment histories.
  2. High-Dimensional & Heterogeneous Outcomes: Traditional methods often focus on the Average Treatment Effect (ATE). However, the "average" can be misleading if the treatment affects different groups in wildly different ways (heterogeneity) or if the outcome is complex, such as a map of COVID-19 cases across dozens of counties.

Existing methods for counterfactual density estimation struggle to scale to these high-dimensional spaces or fail to account for the distributional mismatch between observed data (where treatments are assigned based on covariates) and the counterfactual world (where we want to fix the treatment).

Figure 1: Challenges in estimating the counterfactual outcomes of time-varying treat- ments. Left: The mean is incapable of describing the heterogeneous effect in counterfac- tual distributions. Middle: In a realistic scenario where the treatment is the state-level mask mandate, the outcome is a 67-dimensional vector, corresponding to the number of COVID-19 cases of the 67 counties in Pennsylvania. Right: The longer the dependence on the treatment history, the greater the distributional mismatch tends to be. Here d denotes the length of the history dependence.

Methods

The authors propose a conditional generative framework that implicitly learns the counterfactual distribution without needing explicit density estimation.

The Core Framework

The model uses a generator $g_\theta(z, \bar{a})$ that takes a random noise vector $z$ and a treatment history $\bar{a}$ to produce a counterfactual sample. The "secret sauce" is how they train this generator to handle selection bias.

Key Innovations:

  • IPTW-Weighted Loss: They establish a statistical link between the observed data and the counterfactual distribution using the g-formula. They optimize the generator using a novel loss function based on Inverse Probability of Treatment Weighting (IPTW). This reweighting creates a "pseudo-population" where the distribution of outcomes matches the desired counterfactual distribution.
  • Model Agnosticism: The framework is flexible. The authors demonstrate its effectiveness by implementing it with two different backends:
  • MSCVAE: A Marginal Structural Conditional Variational Autoencoder.
  • MSDiffusion: A Marginal Structural Guided Diffusion model, particularly suited for very high-dimensional data like images.
Figure 3: The architecture of the proposed counterfactual generative models. The generator gθ is designed to produce samples of the outcome variable Y (a) with a given time-varying treatment a. The generated samples are expected to conform to the proxy conditional distribution fθ, which is an approximate of the underlying counterfactual distribution fa.

Datasets

The authors evaluated their approach on a mix of synthetic and real-world benchmarks:

  • Fully Synthetic Data: Linear models with varying history dependence lengths ($d=1, 3, 5$) to test the model's ability to capture complex temporal dependencies.
  • TV-MNIST (Semi-synthetic): A time-varying version of the MNIST digit dataset where treatments and covariates influence which digit (0-9) is generated. This tests high-dimensional (784-D) image generation.
  • Pennsylvania COVID-19 (Semi-synthetic): A 67-dimensional outcome representing new cases across all counties in PA. It was designed to be bimodal, with "hotspots" appearing in either Pittsburgh or Philadelphia depending on covariates.
  • Real-world US COVID-19 Data: A dataset covering 3,219 U.S. counties over 49 weeks, used to study the actual impact of mask mandates.

Key Insights and Ideas

  • Generative vs. Discriminative: Instead of predicting a single "best" outcome (which fails in multi-modal scenarios), generating samples allows policymakers to see the range of probable outcomes. For example, a policy might lead to a low average case count but carry a risk of a massive outbreak in a specific city—a detail an average-based model would miss.
  • The Power of Reweighting: The transition from Figure 4's "Observed distribution" to the "True counterfactual distribution" via the $\omega_\phi$ (IPTW) weights is the theoretical heart of the paper. It proves that you can train a generative model on biased observational data and still get unbiased counterfactual samples.
  • Uncovering Multi-modality: In the COVID-19 hotspot experiments, the model successfully identified that outbreaks could shift between major cities, a critical insight for resource allocation that deterministic models overlook.
Figure 4: An illustration of our learning objective. We aim to minimize the KL-divergence between the proxy distribution fθ(·|a) and the true counterfactual distribution fa.

Key Results

  • Superior Accuracy: In synthetic tests, the MSCVAE consistently achieved the lowest Wasserstein distance (a measure of how close two distributions are) compared to baselines like G-Net and CRN.
  • High-Quality Samples: On the TV-MNIST and COVID-19 datasets, the proposed models (MSCVAE and MSDiffusion) significantly outperformed others in FID* scores (an adaptation of the Fréchet Inception Distance used to measure image quality and diversity).
  • Real-World Policy Insight: When applied to real U.S. mask mandate data, the model found that while mandates significantly lowered the mean number of cases, they also led to higher variance. This suggests that while mandates are effective on average, their impact is highly sensitive to local county-level characteristics.

Limitations and Future Work

The authors highlight a few critical caveats:

  • Causal Assumptions: The method relies on "sequential strong ignorability" (no unmeasured confounders) and "positivity" (every treatment sequence must have a non-zero probability of occurring). In the real world, these are hard to verify and can be violated.
  • The Curse of History: As the history length $d$ increases, the number of treatment combinations grows exponentially, which can make the positivity assumption fragile.
  • Future Directions: The authors suggest exploring doubly-robust generative estimators to improve stability and extending the framework to handle continuous treatments (e.g., varying dosage levels) rather than just binary (on/off) mandates.

Summary updated

Abstract

Estimating the counterfactual outcome of treatment is essential for decision-making in public health and clinical science, among others. Often, treatments are administered in a sequential, time-varying manner, leading to an exponentially increased number of possible counterfactual outcomes. Furthermore, in modern applications, the outcomes are high-dimensional and conventional average treatment effect estimation fails to capture disparities in individuals. To tackle these challenges, we propose a novel conditional generative framework capable of producing counterfactual samples under time-varying treatment, without the need for explicit density estimation. Our method carefully addresses the distribution mismatch between the observed and counterfactual distributions via a loss function based on inverse probability re-weighting, and supports integration with state-of-the-art conditional generative models such as the guided diffusion and conditional variational autoencoder. We present a thorough evaluation of our method using both synthetic and real-world data. Our results demonstrate that our method is capable of generating high-quality counterfactual samples and outperforms the state-of-the-art baselines.
BibTeX
@inproceedings{wu2024counterfactual,
  author = {Shenghao Wu and Wenbin Zhou and Minshuo Chen and Shixiang Zhu},
  title = {{Counterfactual Generative Models for Time-Varying Treatments}},
  booktitle = {ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
  year = {2024},
  doi = {10.1145/3637528.3671950},
}
Figure