Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAGs with multiple exposures #127

Open
lorenzoFabbri opened this issue Jan 22, 2024 · 0 comments
Open

DAGs with multiple exposures #127

lorenzoFabbri opened this issue Jan 22, 2024 · 0 comments
Milestone

Comments

@lorenzoFabbri
Copy link

dagitty, both the web interface and the R package, now supports the selection of multiple nodes as exposure. ggdag seems to work out-of-the box for e.g., finding the adjustment sets.

Using dagitty:

mult_exposures <- dagitty::dagitty(
  'dag {
    bb="0,0,1,1"
    E1 [exposure,pos="0.263,0.295"]
    E2 [exposure,pos="0.269,0.481"]
    W [pos="0.413,0.186"]
    Y [outcome,pos="0.496,0.411"]
    E1 -> Y
    E2 -> Y
    W -> E1
    W -> E2
    W -> Y
  }'
)
# Prints: `{ W }`
dagitty::adjustmentSets(mult_exposures)

Using ggdag:

tidy <- ggdag::tidy_dagitty(mult_exposures)
# Prints:
# # A DAG with 4 nodes and 5 edges
# #
# # Exposure: E1, E2
# # Outcome: Y
# #
# # A tibble: 6 × 10
# name      x     y direction to      xend   yend circular adjusted   set  
# <chr> <dbl> <dbl> <fct>     <chr>  <dbl>  <dbl> <lgl>    <chr>      <chr>
# 1 E1    0.263 0.295 ->        Y      0.496  0.411 FALSE    unadjusted {W}  
# 2 E2    0.269 0.481 ->        Y      0.496  0.411 FALSE    unadjusted {W}  
# 3 W     0.413 0.186 ->        E1     0.263  0.295 FALSE    adjusted   {W}  
# 4 W     0.413 0.186 ->        E2     0.269  0.481 FALSE    adjusted   {W}  
# 5 W     0.413 0.186 ->        Y      0.496  0.411 FALSE    adjusted   {W}  
# 6 Y     0.496 0.411 NA        NA    NA     NA     FALSE    unadjusted {W}
ggdag::dag_adjustment_sets(tidy)

Using ggdag with tidy interface:

tidy_raw <- ggdag::dagify(
  Y ~ E1 + E2 + W,
  E1 ~ W,
  E2 ~ W,
  exposure = c("E1", "E2"),
  outcome = "Y"
)
ggdag::dag_adjustment_sets(tidy_raw)
# Prints:
# # A DAG with 4 nodes and 5 edges
# #
# # Exposure: E1, E2
# # Outcome: Y
# #
# # A tibble: 6 × 10
# name       x       y direction to      xend    yend circular adjusted   set  
# <chr>  <dbl>   <dbl> <fct>     <chr>  <dbl>   <dbl> <lgl>    <chr>      <chr>
# 1 E1    -0.239  0.606  ->        Y      0.616 -0.0778 FALSE    unadjusted {W}  
# 2 E2     1.69   0.129  ->        Y      0.616 -0.0778 FALSE    unadjusted {W}  
# 3 W      0.837  0.813  ->        E1    -0.239  0.606  FALSE    adjusted   {W}  
# 4 W      0.837  0.813  ->        E2     1.69   0.129  FALSE    adjusted   {W}  
# 5 W      0.837  0.813  ->        Y      0.616 -0.0778 FALSE    adjusted   {W}  
# 6 Y      0.616 -0.0778 NA        NA    NA     NA      FALSE    unadjusted {W}

So apparently everything works just fine. Perhaps it would be nice to upload the documentation and/or add a vignette.

System information:

> Sys.info()
                                                           sysname 
                                                           "Linux" 
                                                           release 
                                                "6.2.0-39-generic" 
                                                           version 
"#40~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 16 10:53:04 UTC 2"

> R.version
               _                           
platform       x86_64-pc-linux-gnu         
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          4                           
minor          3.2                         
year           2023                        
month          10                          
day            31                          
svn rev        85441                       
language       R                           
version.string R version 4.3.2 (2023-10-31)
nickname       Eye Holes

> packageVersion("ggdag")
[1] ‘0.2.10’

Original discussion here.

@malcolmbarrett malcolmbarrett added this to the ggdag 0.3.0 milestone Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants