Skip to contents

See dagitty::adjustmentSets() for details.

Usage

dag_adjustment_sets(.tdy_dag, exposure = NULL, outcome = NULL, ...)

ggdag_adjustment_set(
  .tdy_dag,
  exposure = NULL,
  outcome = NULL,
  ...,
  shadow = TRUE,
  size = 1,
  node_size = 16,
  text_size = 3.88,
  label_size = text_size,
  text_col = "white",
  label_col = "black",
  edge_width = 0.6,
  edge_cap = 10,
  arrow_length = 5,
  use_edges = TRUE,
  use_nodes = TRUE,
  use_stylized = FALSE,
  use_text = TRUE,
  use_labels = FALSE,
  label_geom = geom_dag_label_repel,
  label = NULL,
  text = NULL,
  node = deprecated(),
  stylized = deprecated(),
  expand_x = expansion(c(0.25, 0.25)),
  expand_y = expansion(c(0.2, 0.2))
)

Arguments

.tdy_dag

A tidy_dagitty or dagitty object

exposure

A character vector, the exposure variable. Default is NULL, in which case it will be determined from the DAG.

outcome

A character vector, the outcome variable. Default is NULL, in which case it will be determined from the DAG.

...

additional arguments to adjustmentSets

shadow

logical. Show paths blocked by adjustment?

size

A numeric value scaling the size of all elements in the DAG. This allows you to change the scale of the DAG without changing the proportions.

node_size

The size of the nodes.

text_size

The size of the text.

label_size

The size of the labels.

text_col

The color of the text.

label_col

The color of the labels.

edge_width

The width of the edges.

edge_cap

The size of edge caps (the distance between the arrowheads and the node borders).

arrow_length

The length of arrows on edges.

use_edges

A logical value. Include a geom_dag_edges*() function? If TRUE, which is determined by edge_type.

use_nodes

A logical value. Include geom_dag_point()?

use_stylized

A logical value. Include geom_dag_node()?

use_text

A logical value. Include geom_dag_text()?

use_labels

A logical value. Include a label geom? The specific geom used is controlled by label_geom.

label_geom

A geom function to use for drawing labels when use_labels = TRUE. Default is geom_dag_label_repel. Other options include geom_dag_label, geom_dag_text_repel, geom_dag_label_repel2, and geom_dag_text_repel2.

label

The bare name of a column to use for labels. If use_labels = TRUE, the default is to use label.

text

The bare name of a column to use for geom_dag_text(). If use_text = TRUE, the default is to use name.

node

Deprecated.

stylized

Deprecated.

expand_x, expand_y

Vector of range expansion constants used to add some padding around the data, to ensure that they are placed some distance away from the axes. Use the convenience function ggplot2::expansion() to generate the values for the expand argument.

Value

a tidy_dagitty with an adjusted column and set column, indicating adjustment status and DAG ID, respectively, for the adjustment sets or a ggplot

Examples

dag <- dagify(
  y ~ x + z2 + w2 + w1,
  x ~ z1 + w1,
  z1 ~ w1 + v,
  z2 ~ w2 + v,
  w1 ~ ~w2,
  exposure = "x",
  outcome = "y"
)

tidy_dagitty(dag) |> dag_adjustment_sets()
#> # DAG:
#> # A `dagitty` DAG with: 7 nodes and 11 edges
#> # Exposure: x
#> # Outcome: y
#> # Adjustment sets: 3 sets: {w1, w2, z2}, {v, w1}, {w1, z1}
#> #
#> # Data:
#> # A tibble: 36 × 9
#>    name        x      y direction to      xend   yend adjusted   set         
#>    <chr>   <dbl>  <dbl> <fct>     <chr>  <dbl>  <dbl> <chr>      <chr>       
#>  1 v     -0.0993 -1.12  ->        z1    -0.938 -2.26  unadjusted {w1, w2, z2}
#>  2 v     -0.0993 -1.12  ->        z2    -1.20  -0.305 unadjusted {w1, w2, z2}
#>  3 w1    -2.34   -1.88  ->        x     -1.93  -2.66  adjusted   {w1, w2, z2}
#>  4 w1    -2.34   -1.88  ->        y     -1.98  -1.23  adjusted   {w1, w2, z2}
#>  5 w1    -2.34   -1.88  ->        z1    -0.938 -2.26  adjusted   {w1, w2, z2}
#>  6 w1    -2.34   -1.88  <->       w2    -2.47  -0.486 adjusted   {w1, w2, z2}
#>  7 w2    -2.47   -0.486 ->        y     -1.98  -1.23  adjusted   {w1, w2, z2}
#>  8 w2    -2.47   -0.486 ->        z2    -1.20  -0.305 adjusted   {w1, w2, z2}
#>  9 x     -1.93   -2.66  ->        y     -1.98  -1.23  unadjusted {w1, w2, z2}
#> 10 y     -1.98   -1.23  NA        NA    NA     NA     unadjusted {w1, w2, z2}
#> # ℹ 26 more rows
#> #
#> # ℹ Use `pull_dag() (`?pull_dag`)` to retrieve the DAG object and `pull_dag_data() (`?pull_dag_data`)` for the data frame

ggdag_adjustment_set(dag)


ggdag_adjustment_set(
  dagitty::randomDAG(10, .5),
  exposure = "x3",
  outcome = "x5"
)