Py-Tetrad and RPy-Tetrad: A New Python Interface with R Support for Tetrad Causal Search

Joseph D. Ramsey, Bryan Andrews

Abstract

Causal discovery is essential for identifying cause-and-effect relationships in observational data. For decades, the Tetrad project has served as a gold standard for these algorithms, yet its Java-based implementation has created barriers for researchers in the Python and R ecosystems. This paper introduces Py-Tetrad and RPy-Tetrad, modern interfaces that leverage JPype and Reticulate to provide seamless, full-codebase access to Tetrad. These tools eliminate the installation and compatibility issues of previous bridges, enabling robust causal search within modern data science workflows.

Introduction

Identifying causal structures from data is a cornerstone of scientific inquiry. The Tetrad project, developed at Carnegie Mellon University, houses a comprehensive library of causal discovery algorithms, including classic methods like PC and FCI alongside modern innovations. However, as the data science community has coalesced around Python and R, the Java-centric nature of Tetrad has become a technical silo.

Previous attempts to bridge this gap, such as py-causal and r-causal, have largely become "abandonware." These legacy tools often rely on outdated Java versions and complex installation processes that are particularly prone to failure on modern operating systems. Py-Tetrad and RPy-Tetrad address these challenges by providing a stable, high-performance connection to the entire Tetrad library.

Methods: Bridging the Ecosystems

The authors developed two distinct but related packages to integrate Tetrad into modern environments:

  1. Py-Tetrad: This package utilizes JPype, a library that allows Python to access Java classes and methods directly. Unlike earlier wrappers that were limited to a subset of the API, Py-Tetrad provides access to the entire Tetrad codebase, allowing users to utilize niche methods and internal Java formats.
  2. RPy-Tetrad: To ensure sustainability and reduce maintenance overhead, RPy-Tetrad routes R through Python using the Reticulate package. This "daisy-chain" (R → Python → Java) ensures that improvements to the Python interface are immediately available to R users.
Comparison of Tetrad interfaces and their technical requirements.

Both packages include a high-level TetradSearch class and specialized translators to convert data between Python/R data frames and Tetrad’s internal Java structures. This architecture supports mixed-type data handling and the integration of background knowledge, such as temporal tiers (e.g., ensuring an effect cannot precede its cause).

Applications and Key Results

The utility of these interfaces was demonstrated through two primary case studies:

Fitbit and Apple Watch Data

Using a mixed-type dataset containing continuous and discrete variables, the authors applied the SP-FCI algorithm via Py-Tetrad. By incorporating "knowledge tiers," the search was constrained to respect logical temporal flows. The analysis successfully produced a probability table for edge types, notably identifying a 93% probability of a bi-directed edge between activity and calories, suggesting a complex feedback loop or unmeasured confounding.

Causal graph generated from Fitbit data using Py-Tetrad, illustrating relationships between physiological and activity metrics.

NASA Airfoil Self-Noise Data

In the R environment, the GRaSP algorithm was applied to a continuous dataset. This example highlighted the synergy between Tetrad’s computational power and R’s visualization ecosystem, using packages like DiagrammaR to render the resulting causal structures.

Conclusion

Py-Tetrad and RPy-Tetrad represent a significant step forward in making advanced causal discovery tools accessible to the broader research community. By moving away from fragile bridge architectures toward stable libraries like JPype, the authors have provided a sustainable path for integrating Tetrad into Python and R. Future work will focus on simplifying installation via standard package managers like pip and CRAN and expanding support for background knowledge across all Tetrad algorithms.

Summary updated

BibTeX
@inproceedings{ramsey2023py,
  author = {Joseph D. Ramsey and Bryan Andrews},
  title = {{Py-Tetrad and RPy-Tetrad: A New Python Interface with R Support for Tetrad Causal Search}},
  booktitle = {CAWS},
  year = {2023},
}
Figure