Skip to content

frederikfabriciusbjerre/causalDisco

 
 

Repository files navigation

causalDisco

codecov R-CMD-check

causalDisco provides a unified interface for causal discovery on observational data. It wraps multiple causal discovery backends under a common, consistent syntax.

Motivation

Causal discovery methods exist in many ecosystems, for example in bnlearn, pcalg, or Tetrad, but their APIs vary widely.

causalDisco unifies them under one clear grammar, making it easy to compare results, switch algorithms, and focus on scientific questions rather than package quirks.

Time to hit the disco 🪩

Installation

Install pak

pak is the easiest way to install causalDisco and its dependencies:

install.packages("pak",
  repos =
    sprintf(
      "https://r-lib.github.io/p/pak/stable/%s/%s/%s",
      .Platform$pkgType,
      R.Version()$os,
      R.Version()$arch
    )
)

Install causalDisco

Once pak is installed, run:

pak::pkg_install("github::frederikfabriciusbjerre/causalDisco")

If needed, you can check and install system dependencies first:

pak::pkg_sysreqs("github::frederikfabriciusbjerre/causalDisco",
  dependencies = TRUE,
  upgrade = TRUE
)

This will give you a list of system dependencies, which you need to install first, if they are not already on your system.

Installing Java / JDK

Some algorithms require Java. Install JDK 21 or 25 following this guide,

or use your system’s package manager.

Example

With causalDisco you can currently run causal discovery algorithms from the packages causalDisco itself, the Java library Tetrad, bnlearn, and pcalg.

library(causalDisco)

# load data
data("tpcExample")

# define background knowledge object
kn <- knowledge(
  tpcExample,
  tier(
    child ~ starts_with("child"),
    youth ~ starts_with("youth"),
    old ~ starts_with("old")
  )
)

# use Tetrad PC algorithm with conditional Gaussian test
tetrad_pc <- pc(engine = "tetrad", test = "conditional_gaussian", alpha = 0.05)
disco(data = tpcExample, method = tetrad_pc, knowledge = kn)

# similarly, one could do
tetrad_pc <- tetrad_pc |> set_knowledge(kn)
tetrad_pc(tpcExample)

# use causalDisco's own tges algorithm with temporal BIC score
cd_tges <- tges(engine = "causalDisco", score = "tbic")
disco(data = tpcExample, method = cd_tges, knowledge = kn)

Bugs & requests

Bug reports and feature requests are welcome:

👉 open an issue.

About

Tools for causal discovery in R

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 95.8%
  • R 4.2%