-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
Wrapper around ggdag and dagitty #761
Conversation
@easystats/core-team What do you think? A "check" function for DAGs in performance? Plots still needs some improvements (e.g. get rid of the "adjusted line" legend). Benefits over ggdag:
|
Can you give an example of where this would fit in the model-building workflow? |
library(performance)
# error for cyclic model
dag <- check_dag(
y ~ x + b + c + d,
x ~ c + d,
b ~ x,
b ~ y,
outcome = "y",
exposure = "x",
adjusted = "c"
)
#> Error: Model is cyclic. Causal effects can't be determined for cyclic models.
#> Please remove cycles from the model. To do so, check following
#> variables: b and y
# collider-bias
dag <- check_dag(
y ~ x + c + d,
x ~ c + d,
b ~ x,
b ~ y,
outcome = "y",
exposure = "x",
adjusted = "c"
)
dag
#> # Correct adjustments for identifying direct effects
#>
#> Incorrectly adjusted!
#> - Outcome: y
#> - Exposure: x
#>
#> To estimate the direct effect, also adjust for: c and d.
#> Currently, the model currently only adjusts for c.
#>
#> # Correct adjustments for identifying total effects
#>
#> Incorrectly adjusted!
#> - Outcome: y
#> - Exposure: x
#>
#> To estimate the total effect, also adjust for: c and d.
#> Currently, the model currently only adjusts for c.
plot(dag) Created on 2024-08-03 with reprex v2.1.1 |
What do you exactly mean? You can use this at the point where you involve DAGs. Like you would do with the online tool dagitty.net, you can easily specify your "dependencies" (causal paths) via familiar formula-syntax and then check if you adjusted correctly or not. The "check" here is that you get the corrected DAG, telling you what you need to adjust for. |
not sure why the geoms look so ugly in the reprex, though |
Created on 2024-08-03 with reprex v2.1.1