edge_backdoor()
identifies edges as being on backdoor paths or direct
causal paths between an exposure and outcome. This function adds edge-level
information to the tidy DAG object, classifying each edge based on the types
of paths it appears on.
Arguments
- .dag
A
tidy_dagitty
ordagitty
object- from
A character vector with starting node name(s), or
NULL
. IfNULL
, checks DAG for exposure variable.- to
A character vector with ending node name(s), or
NULL
. IfNULL
, checks DAG for outcome variable.- adjust_for
character vector, a set of variables to control for. Default is
NULL
.- open_only
logical. If
TRUE
(default), only considers open paths. IfFALSE
, includes information about closed paths as well.- ...
additional arguments passed to
tidy_dagitty()
Value
A tidy_dagitty
object with additional columns:
path_type
: "backdoor", "direct", or "both" classification for each edgeopen
: logical indicating if the edge is part of an open path
Details
Edges are classified by examining the paths between exposure and outcome:
Direct edges appear only on directed causal paths
Backdoor edges appear only on backdoor paths
Both edges appear on both direct and backdoor paths
When open_only = TRUE
(default), path_type
will be NA for edges that are
only part of closed paths.
Examples
# Create a DAG with both direct and backdoor paths
dag <- dagify(
y ~ x + z,
x ~ z,
exposure = "x",
outcome = "y"
)
# Classify edges
edge_backdoor(dag)
#> # DAG:
#> # A `dagitty` DAG with: 3 nodes and 3 edges
#> # Exposure: x
#> # Outcome: y
#> #
#> # Data:
#> # A tibble: 4 × 9
#> name x y direction to xend yend path_type open
#> <chr> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <lgl>
#> 1 x 0.0682 -0.0250 -> y 0.939 -0.506 direct TRUE
#> 2 y 0.939 -0.506 NA NA NA NA NA NA
#> 3 z 0.0871 -1.02 -> x 0.0682 -0.0250 backdoor TRUE
#> 4 z 0.0871 -1.02 -> y 0.939 -0.506 backdoor TRUE
#> #
#> # ℹ Use `pull_dag() (`?pull_dag`)` to retrieve the DAG object and `pull_dag_data() (`?pull_dag_data`)` for the data frame
# Include closed paths
edge_backdoor(dag, open_only = FALSE)
#> # DAG:
#> # A `dagitty` DAG with: 3 nodes and 3 edges
#> # Exposure: x
#> # Outcome: y
#> #
#> # Data:
#> # A tibble: 4 × 9
#> name x y direction to xend yend path_type open
#> <chr> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <lgl>
#> 1 x -0.0289 -0.516 -> y 0.447 0.369 direct TRUE
#> 2 y 0.447 0.369 NA NA NA NA NA NA
#> 3 z 0.976 -0.486 -> x -0.0289 -0.516 backdoor TRUE
#> 4 z 0.976 -0.486 -> y 0.447 0.369 backdoor TRUE
#> #
#> # ℹ Use `pull_dag() (`?pull_dag`)` to retrieve the DAG object and `pull_dag_data() (`?pull_dag_data`)` for the data frame