Abstract
Khoshnevis et al., (2024). GPCERF - An R package for implementing Gaussian processes for estimating causal exposure response curves. Journal of Open Source Software, 9(95), 5465, https://doi.org/10.21105/joss.05465
Introduction
In causal inference, estimating the relationship between a continuous exposure—such as air pollution levels or medication dosage—and an outcome is a fundamental task. This relationship is formally defined as the Causal Exposure-Response Function (CERF). Estimating the CERF from observational data is complicated by confounding, where covariates influence both exposure and outcome. While Gaussian Processes (GPs) offer a flexible, Bayesian approach to this problem, they typically suffer from high computational costs ($O(n^3)$) and lack integrated tools for ensuring covariate balance.
The GPCERF R package introduces a novel framework that combines the flexibility of GPs with efficient nearest-neighbor approximations (nnGP) and a dedicated "design phase" to optimize for causal validity.
Methodology
GPCERF employs a two-step Bayesian approach to separate the study design from the outcome analysis, preventing "data snooping."
1. The Design Phase (Tuning)
The algorithm performs a grid search to identify optimal hyperparameters for the GP kernel. Unlike standard machine learning tasks that optimize for predictive accuracy, GPCERF optimizes for covariate balance. It aims to create a weighted pseudo-population where the correlation between exposure and covariates is minimized, effectively mimicking the conditions of a randomized controlled trial. Crucially, the outcome data is not used in this step to maintain the integrity of the causal design.
2. The Analysis Phase (Estimation)
Once the study is "designed" (balanced), the package estimates the CERF. A significant advantage of this Bayesian approach is the "automatic" quantification of uncertainty. The posterior distribution provides credible bands for the estimated response curve without the need for computationally expensive frequentist resampling methods like bootstrapping.
Scalability via nnGP
To address the cubic scaling of standard GPs, GPCERF implements Nearest-Neighbor Gaussian Processes (nnGP). By considering only a small number of neighbors ($m$) for each point, the computational complexity is reduced to $O(n \cdot m^3)$, allowing the package to scale to datasets with over 100,000 observations that would otherwise be computationally prohibitive.
Key Results and Performance
Validation using synthetic datasets demonstrates the package's ability to recover the true exposure-response relationship while maintaining rigorous covariate balance.
As shown in the figure above, the package successfully reduces the absolute weighted correlation of confounders (e.g., cf1 through cf6) to well below the 0.1 threshold, a standard benchmark for acceptable balance in causal inference literature. The resulting CERF (left panel) provides a clear visualization of the population average counterfactual outcome across exposure levels, complete with 1.96 standard deviation credible bands.
Performance benchmarks confirm that while standard GPs follow a strict $O(n^3)$ growth rate, the nnGP implementation maintains linear scaling ($O(n)$). This efficiency makes sophisticated Bayesian non-parametrics accessible for large-scale observational studies.
Limitations
While GPCERF provides a robust toolkit, users must be aware of certain trade-offs. The nnGP is an approximation, and results may vary slightly based on the chosen number of neighbors. Furthermore, like all causal inference methods based on observed data, the package assumes "no unobserved confounding." If critical variables influencing both exposure and outcome are missing from the dataset, the resulting CERF may still be biased.
Summary updated