Robust causal inference using directed acyclic graphs: the R package ‘dagitty’

Johannes Textor, Benito van der Zander, Mark S. Gilthorpe, Maciej Liśkiewicz, George T. H. EllisonInternational Journal of Epidemiology 2016

Abstract

Directed acyclic graphs (DAGs), which offer systematic representations of causal relationships, have become an established framework for the analysis of causal inference in epidemiology, often being used to determine covariate adjustment sets for minimizing confounding bias. DAGitty is a popular web application for drawing and analysing DAGs. Here we introduce the R package 'dagitty', which provides access to all of the capabilities of the DAGitty web application within the R platform for statistical computing, and also offers several new functions. We describe how the R package 'dagitty' can be used to: evaluate whether a DAG is consistent with the dataset it is intended to represent; enumerate 'statistically equivalent' but causally different DAGs; and identify exposure-outcome adjustment sets that are valid for causally different but statistically equivalent DAGs. This functionality enables epidemiologists to detect causal misspecifications in DAGs and make robust inferences that remain valid for a range of different DAGs.

Introduction

In fields such as epidemiology and the social sciences, Directed Acyclic Graphs (DAGs) are indispensable for visualizing hypothesized causal pathways and identifying potential confounders. However, traditional workflows often suffer from "tool fragmentation," where researchers design graphs in graphical interfaces but perform statistical analysis in separate environments. This separation can lead to errors and discourages the rigorous testing of the causal assumptions embedded in the DAG. Furthermore, researchers often overlook the "assumption problem": multiple distinct graph structures can be statistically equivalent, meaning they are indistinguishable based on data alone. Selecting a single DAG without considering its equivalence class can lead to biased or invalid causal inferences.

The dagitty R Package

The dagitty R package bridges the gap between qualitative causal modeling and quantitative data analysis by porting the logic of the DAGitty web application into the R environment. By utilizing the V8 package to run the original JavaScript library, it ensures consistency between the web and R versions.

The package treats DAGs as testable hypotheses. Using the principle of d-separation, it identifies every statistical independence implied by a graph structure. These implications can then be tested against empirical data using the localTests() function, which supports both partial correlations and non-parametric regression.

Workflow of the `dagitty` R package, including DAG specification (A), R code implementation (B), consistency testing (C), adjustment set identification (D), and equivalent model enumeration (E).

Beyond consistency testing, dagitty allows researchers to explore the "equivalence class" of a model—the set of all DAGs that imply the same set of independencies. A key innovation is the ability to identify "robust" adjustment sets: groups of variables that provide valid causal estimates across every graph in an equivalence class.

Case Studies and Results

The paper demonstrates these capabilities through two distinct scenarios:

  1. Sports Medicine Example: A simplified model examining the link between warm-up exercises (WUE) and injury risk (I). As shown in the workflow figure, the package's diagnostic tools identified a misspecification in the initial model. The data failed to support the predicted independence between "team motivation" (TM) and "warm-up exercises," suggesting a missing causal link that was subsequently incorporated to improve model fit.
  2. Bilirubin and Hypertension Study: In a complex real-world application involving 41 causal arrows, the package identified 40 statistically equivalent DAGs. Despite this structural ambiguity, dagitty successfully identified a single minimal adjustment set that remained valid for all 40 versions, significantly increasing the robustness of the study's conclusions.

Discussion

The dagitty package shifts the perception of DAGs from purely qualitative diagrams to rigorous, testable statistical models. By forcing researchers to acknowledge where data is ambiguous—through the identification of equivalence classes—and providing tools for robust inference, it mitigates the risks associated with model misspecification.

While the current implementation relies on certain distributional assumptions for its default tests, it provides a foundation for incorporating more advanced non-parametric methods. The authors caution against using these tools for "data fishing" or overfitting; rather, they should be used to refine models based on a combination of prior knowledge and empirical evidence. Ultimately, dagitty empowers researchers to make causal inferences that are both statistically sound and robust to structural uncertainties.

Summary updated

Abstract

Directed acyclic graphs (DAGs), which offer systematic representations of causal relationships, have become an established framework for the analysis of causal inference in epidemiology, often being used to determine covariate adjustment sets for minimizing confounding bias. DAGitty is a popular web application for drawing and analysing DAGs. Here we introduce the R package 'dagitty', which provides access to all of the capabilities of the DAGitty web application within the R platform for statistical computing, and also offers several new functions. We describe how the R package 'dagitty' can be used to: evaluate whether a DAG is consistent with the dataset it is intended to represent; enumerate 'statistically equivalent' but causally different DAGs; and identify exposure-outcome adjustment sets that are valid for causally different but statistically equivalent DAGs. This functionality enables epidemiologists to detect causal misspecifications in DAGs and make robust inferences that remain valid for a range of different DAGs. The R package 'dagitty' is available through the comprehensive R archive network (CRAN) at [https://cran.r-project.org/web/packages/dagitty/]. The source code is available on github at [https://github.com/jtextor/dagitty]. The web application 'DAGitty' is free software, licensed under the GNU general public licence (GPL) version 2 and is available at [http://dagitty.net/].
BibTeX
@article{textor2016robust,
  author = {Johannes Textor and Benito van der Zander and Mark S. Gilthorpe and Maciej Liśkiewicz and George T. H. Ellison},
  title = {{Robust causal inference using directed acyclic graphs: the R package ‘dagitty’}},
  journal = {International Journal of Epidemiology},
  year = {2016},
  doi = {10.1093/ije/dyw341},
}
Figure