Find ancestor nodes for specified variables in a DAG.
Value
A tibble with columns:
node
: The nodeancestor_set
: String representation of ancestor nodesancestors
: List column containing ancestor nodesn_ancestors
: Number of ancestors
Examples
library(ggdag)
dag <- dagify(
y ~ x + z,
x ~ w
)
query_ancestors(dag)
#> # A tibble: 4 × 4
#> node ancestor_set ancestors n_ancestors
#> <chr> <chr> <list> <int>
#> 1 w NA <chr [1]> 0
#> 2 x {w} <chr [1]> 1
#> 3 y {w, x, z} <chr [3]> 3
#> 4 z NA <chr [1]> 0
query_ancestors(dag, .var = "y")
#> # A tibble: 1 × 4
#> node ancestor_set ancestors n_ancestors
#> <chr> <chr> <list> <int>
#> 1 y {w, x, z} <chr [3]> 3