dagitty
DAG + formula to a compact
reportLaTeX
/ Word
/
Excel
/ text
DAGassist
See the Getting Started vignette for a guide on using different parameters get the most out of DAGassist. For the purpose of this tutorial, we will keep it simple.
See the Supported
Models vignette for documentation on what engines
DAGassist
supports. Since DAGassist
is
model-agnostic, if an engine accepts a standard
formula + data
interface, it will usually work.
Interpreting the output:
DAGassist
classifies the
variables in your formula by causal role, based on the relationships in
your DAG. It classifies according to these categories.
treatment
/
independent variable
/ exposure
.outcome
/
dependent variable
.confounder
, a common
cause of X and Y. Confounders create a spurious association between X
and Y, and must be adjusted for.mediator
, a variable
that lies on a path from X to Y, which transmit some of the effect from
X to Y. One should not adjust for mediators if one wants to estimate the
total effect of X on Y.collider
, a direct
common descendant of X and Y. Colliders already block paths, so
adjusting for it opens a spurious association between X and Y.intermediate outcome
, a
descendant of Y, which introduces bias if adjusted for.descendant of a mediator
, which should not be adjusted for
when estimating total effect.descendant of a collider
. Adjusting for a descendant of a
collider opens a spurious association between X and Y.other
variables’ effects are
generally neutral, it is usually best to use the minimal adjustment set
as your baseline model.Minimal
is the smallest adjustment set necessary to
close all back-door paths from the independent to the dependent
variable. The minimal set only includes confounders
as
controls.Canonical
is the largest permissible adjustment set.
Essentially, the canonical
set contains all control
variables that are not confounders
, mediators
,
intermediate outcomes
,
descendants of mediatiors
, or
descendants of colliders
.
DAGassist(
dag = dag_model,
formula = lm(Y ~ X + M + Z + A, data = df)
)
#> DAGassist Report:
#>
#> Roles:
#> variable role X Y conf med col IO dMed dCol
#> X exposure x
#> Y outcome x x
#> Z confounder x
#> M mediator x
#> A other
#>
#> (!) Bad controls in your formula: {M}
#> Minimal controls 1: {Z}
#> Canonical controls: {A, Z}
#>
#> Formulas:
#> original: Y ~ X + M + Z + A
#>
#> Model comparison:
#>
#> +---+----------+-----------+-----------+
#> | | Original | Minimal 1 | Canonical |
#> +===+==========+===========+===========+
#> | X | 1.089*** | 1.091*** | 1.092*** |
#> +---+----------+-----------+-----------+
#> | | (0.051) | (0.044) | (0.044) |
#> +---+----------+-----------+-----------+
#> | M | 0.007 | | |
#> +---+----------+-----------+-----------+
#> | | (0.044) | | |
#> +---+----------+-----------+-----------+
#> | Z | 0.461*** | 0.463*** | 0.463*** |
#> +---+----------+-----------+-----------+
#> | | (0.051) | (0.050) | (0.050) |
#> +---+----------+-----------+-----------+
#> | A | 0.020 | | 0.020 |
#> +---+----------+-----------+-----------+
#> | | (0.041) | | (0.041) |
#> +===+==========+===========+===========+
#> | + p < 0.1, * p < 0.05, ** p < 0.01, |
#> | *** p < 0.001 |
#> +===+==========+===========+===========+
See the Making
Reports vignette for more detailed information on producing
publication-quality DAGassist
reports in
LaTex
, Word
, Excel
, and
plaintext
.
Since DAGassist
is designed to make appendix robustness
checks, this is an example of how to output a report in
LaTeX
.
#initialize a temporary path
out_tex <- file.path(tempdir(), "dagassist_report.tex")
DAGassist(
dag = dag_model,
formula = lm(Y ~ X + M + Z + A, data = df),
type = "latex",
out = out_tex) #put your output directory and file name here
cat(readLines(out_tex, n = 15), sep = "\n") # briefly show the output
#> % ---- DAGassist LaTeX fragment (no preamble) ----
#> % Requires: \usepackage{tabularray} \UseTblrLibrary{booktabs,siunitx,talltblr}
#> \begingroup\footnotesize
#> \begingroup\setlength{\emergencystretch}{3em}
#> \begin{longtblr}[presep=0pt, postsep=0pt, caption={DAGassist Report:}, label={tab:dagassist}]%
#> {width=\textwidth,colsep=1.5pt,rowsep=0pt,abovesep=0pt,belowsep=0pt,colspec={X[35,l]X[15,l]X[8,c]X[8,c]X[8,c]X[8,c]X[8,c]X[8,c]X[8,c]X[8,c]}}
#> \toprule
#> Variable & Role & X & Y & CON & MED & COL & IO & dMed & dCol \\
#> \midrule
#> A & other & & & & & & & & \\
#> M & mediator & & & & x & & & & \\
#> X & exposure & x & & & & & & & \\
#> Y & outcome & & x & & & & & x & \\
#> Z & confounder & & & x & & & & & \\
#> \bottomrule