Carnegie Mellon University

Tetrad in R

R is heavily used in many of the sciences and statistics, and causal search software (PCALG, Bnlearn) is made available in R.

We make Tetrad causal search software available in R through the package rpy-tetrad using the Reticulate package in R.

https://github.com/cmu-phil/py-tetrad/tree/main/pytetrad/R

Rpy-tetrad requires that up-to-date versions of Java 9+ and Python 3.5+ be installed (see installation instructions at the link above). Once the requisite Java and Python are installed, rpy-tetrad gives Tetrad a simple and intuitive interface to Tetrad search functionality. It works well, for instance, in RStudio. Several such examples are included with the rpy-tetrad package and can be modified to suit particular purposes.

Data translators and graph translators specific to R are available in the TetradSearch.py Python model, and so made available in R. With Reticulate, Python and R are able to share data frame data; mixed continuous and discrete data, for instance, can be formatted in R and used without any translation other than what Reticular provides in py-tetrad, and py-tetrad efficiently makes the data available in Java. This solves some data translation difficulties reported for an earlier project connecting R to Java, r-causal; even large datasets can be passed quickly to Tetrad, provided enough RAM is allocated for the process. Graphs can be returned in String form, as causal-learn GeneralGraphs, as PCALG-style edge matrices, or if they are directed acyclic graphs (DAGs), in Lavaan format, or in DOT format if Graphviz rendering is needed. So, interaction with other packages in R is straightforward.

So far as we know, JPype cannot be called directly from R. Still, a Python module, TetradSearch.py, makes a wide swath of Tetrad search functionality available for R. Future development will make more of the Tetrad API available as needed for R researchers, so feedback from the community would be welcome. We will add any functionality from Tetrad that is needed in R on request.

Despite being a new project as of April 2023, we hope, with user feedback, to make this a useful tool for R researchers. We have yet to make this project installable via CRAN but are working toward that.

A working paper describing how py-tetrad and rpy-tetrad work may be found on arXiv: 

Ramsey, J. D., & Andrews, B. (2023). Py-Tetrad and RPy-Tetrad: A New Python Interface with R Support for Tetrad Causal Search. arXiv preprint arXiv:2308.07346.