fairadapt: Causal Reasoning for Fair Data Preprocessing

Drago Plecko, Nicolas Bennett, Nicolai Meinshausen

In the field of machine learning, the adage "garbage in, garbage out" has a more insidious counterpart: "bias in, bias out." When algorithms are trained on datasets reflecting historical inequities, they do not merely learn to predict; they learn to perpetuate discrimination. While many existing tools attempt to mitigate this at the prediction stage, a new R package from researchers at ETH Zürich, fairadapt, offers a fundamental shift by preprocessing the data itself through the lens of causal reasoning.

The Causal Challenge in Algorithmic Fairness

Most algorithmic fairness techniques focus on achieving parity in final predictions—for example, ensuring equal pass rates for different demographic groups. However, these "black-box" interventions often lack legal or philosophical grounding because they ignore the underlying mechanisms of bias.

Fairness is inherently a causal problem. If a gender gap in salary is the result of discriminatory hiring practices, an effective solution must account for that specific causal pathway. The challenge lies in creating a tool capable of navigating complex real-world data where variables are deeply interconnected and noise is often correlated. Furthermore, researchers require the flexibility to distinguish between "fair" and "unfair" pathways; for instance, a physician's salary might legitimately depend on years of specialized training, even if access to that training was historically influenced by gender.

Methodology: Counterfactuals and Quantile Matching

The core of fairadapt is built upon counterfactual reasoning derived from Structural Causal Models (SCMs). The process begins with the user defining the underlying structure of the data.

Causal Graphs and Structure

Users provide a Directed Acyclic Graph (DAG) that represents the hypothesized relationships between variables. This allows the algorithm to respect the mechanisms that generated the data rather than relying solely on surface-level correlations.

A sample Directed Acyclic Graph (DAG) representing causal relationships between variables A, E, T, and Y.

The "Secret Sauce": Quantile Matching

To transform a variable (such as a test score or salary) into a "fair" version, fairadapt employs a technique called quantile matching. For any given individual, the tool identifies their rank within their own demographic group (e.g., the 70th percentile among men) and maps it to the equivalent rank in a baseline group (e.g., the 70th percentile among women). This preservation of relative standing ensures that individual merit is maintained while group-level disparities are eliminated.

Visualization of quantile matching, mapping the distribution of one group (e.g., Male) to another (e.g., Female) to remove disparity.

Beyond simple mapping, fairadapt supports semi-Markovian models, making it robust against unobserved "noise" variables that may be correlated—a common occurrence in social science datasets. Additionally, users can designate "resolving variables," which are factors deemed non-discriminatory that the algorithm should leave unadjusted.

Empirical Validation

The package's efficacy was demonstrated across three diverse datasets:

  1. University Admissions: A synthetic dataset modeled after the Berkeley admissions case, used to illustrate how resolving variables (like department choice) influence fairness outcomes.
  2. COMPAS: The recidivism dataset, utilized to showcase the package's ability to quantify uncertainty in fairness adjustments.
  3. US Census (2018): Real-world data from the American Community Survey focused on the gender pay gap.

In the University Admission example, an initial disparity of -0.7045 was reduced to -0.066 after adaptation. In the Census study, the package successfully shifted salary distributions so that the curves for men and women overlapped almost perfectly, effectively removing the gender-based gap at the data level.

Key Insights and Transparency

fairadapt is currently the only R package that is "causally aware," providing a level of transparency often missing in fairness research. By allowing researchers to inspect "fair twins"—the counterfactual versions of real individuals—the tool enables a sanity check on the data transformations. Furthermore, through the fairadaptBoot function, the authors emphasize that fairness is not a static number; they provide tools to quantify how training data variance and quantile estimation affect final predictions.

Limitations and Future Directions

While a significant step forward, the authors acknowledge several areas for future development. Currently, the protected attribute (e.g., race or gender) must be binary. Expanding the framework to support multi-class or continuous attributes is a high priority. Additionally, future versions aim to address selection bias—where the training data is not representative of the broader population—and incorporate support for more complex causal structures like "front-door" identification.

Paper Citation: Plečko D, Bennett N, Meinshausen N (2024). "fairadapt: Causal Reasoning for Fair Data Preprocessing." Journal of Statistical Software, 110(4). doi:10.18637/jss.v110.i04.

Summary updated

BibTeX
@article{plecko2024fairadapt,
  author = {Drago Plecko and Nicolas Bennett and Nicolai Meinshausen},
  title = {{fairadapt: Causal Reasoning for Fair Data Preprocessing}},
  journal = {J. Stat. Softw.},
  year = {2024},
  doi = {10.18637/jss.v110.i04},
}
Figure