Share this article on:

dagR: A Suite of R Functions for Directed Acyclic Graphs

Breitling, Lutz Philipp

doi: 10.1097/EDE.0b013e3181e09112

Division of Clinical Epidemiology and Aging Research; German Cancer Research Center; Heidelberg, Germany;

Back to Top | Article Outline

To the Editors:

I have read with great interest the recent letter by Knüppel and Stang introducing a DOS program for assessing directed acyclic graphs (DAGs) with respect to minimal sufficient adjustment sets.1 Others have elaborated on the value of DAGs for epidemiologists,2 and any efforts to make these methodologies more accessible appear worthwhile. With this in mind, I would like to draw your attention to dagR (/′dægər/), a set of functions for the statistical software R (R Foundation for Statistical Computing, Vienna/Austria, 2009), programmed originally for training rather than distribution. I present dagR version 1.0.1 in the form of an R script (including example DAGs) as an eAppendix,; it has also recently been published as an R add-on package with documentation of its functionalities on

The functions in essence implement the graphical rules outlined elsewhere.2 After initializing a new DAG using a command line, the researcher can evaluate what associations are introduced by adjusting for covariables. Potentially biasing paths from exposure to outcome can be identified (see eFig. 1, demonstrating harmful adjustment using an example DAG from Fleischer and Diez Roux3). Functions to conveniently add or remove nodes and arcs are included, as is a function checking introduced associations and biasing paths for all possible adjustment sets (with options to force in adjustment or exclude unmeasured variables; see eFig. 2, for a re-evaluation of example 3 of the DAG program manual1), thereby allowing the identification of minimal sufficient adjustment sets. Note that the evaluation of all possible adjustment sets for more complex DAGs may be somewhat resource-intensive (see eFig. 3, for such a DAG motivated by Shrier and Platt4).

Some convenient features result from using R as the programming platform. dagR should run on all operating systems running R. DAGs generated and manipulated using dagR can be saved as an R object and transferred to another computer to continue manipulation and evaluation with dagR. The graphics capabilities of R allow fairly straightforward programming of basic DAG drawing routines, while also supporting the interactive repositioning of nodes and arcs. Generally, it also appears feasible to create convenient interfaces to R functions for any DAG-related methods, for example, structural models. Finally, R is popular with epidemiologists and statisticians. dagR hopefully will be extended and any new issues tackled through the community in a timely manner.

Lutz Philipp Breitling

Division of Clinical Epidemiology and Aging Research

German Cancer Research Center

Heidelberg, Germany

Back to Top | Article Outline


1.Knüppel S, Stang A. DAG program: identifying minimal sufficient adjustment sets. Epidemiology. 2010;21:159.
2.Greenland S, Pearl J, Robins JM. Causal diagrams for epidemiologic research. Epidemiology. 1999;10:37–48.
3.Fleischer NL, Diez Roux AV. Using directed acyclic graphs to guide analyses of neighbourhood health effects: an introduction. J Epidemiol Community Health. 2008;62:842–846.
4.Shrier I, Platt RW. Reducing bias through directed acyclic graphs. BMC Med Res Methodol. 2008;8:70.

Supplemental Digital Content

Back to Top | Article Outline
© 2010 Lippincott Williams & Wilkins, Inc.