plot_collider <- dagify(
y ~ x,
z ~ x + y,
coords = list(
x = c(x = 1, y = 3, z = 2),
y = c(x = 1, y = 1, z = 2)
)
) |>
tidy_dagitty() |>
mutate(var_type = case_match(
name,
"x" ~ "Treatment",
"y" ~ "Outcome",
"z" ~ "Third thing"
)) |>
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_edges() +
geom_dag_point(aes(color = var_type)) +
geom_dag_text() +
scale_color_manual(values = node_clrs, guide = "none") +
scale_y_continuous(expand = expansion(mult = 0.2)) +
labs(title = "(1) Collider") +
theme_dag(base_family = "Noto Sans")
plot_confounder <- dagify(
y ~ x + z,
x ~ z,
coords = list(
x = c(x = 1, y = 3, z = 2),
y = c(x = 1, y = 1, z = 2)
)
) |>
tidy_dagitty() |>
mutate(var_type = case_match(
name,
"x" ~ "Treatment",
"y" ~ "Outcome",
"z" ~ "Third thing"
)) |>
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_edges() +
geom_dag_point(aes(color = var_type)) +
geom_dag_text() +
scale_color_manual(values = node_clrs, guide = "none") +
scale_y_continuous(expand = expansion(mult = 0.2)) +
labs(title = "(2) Confounder") +
theme_dag(base_family = "Noto Sans") +
theme(plot.margin = unit(c(0, 0, 0, 2), "lines"))
plot_mediator <- dagify(
y ~ z,
z ~ x,
coords = list(
x = c(x = 1, y = 3, z = 2),
y = c(x = 1, y = 1, z = 2)
)
) |>
tidy_dagitty() |>
mutate(var_type = case_match(
name,
"x" ~ "Treatment",
"y" ~ "Outcome",
"z" ~ "Third thing"
)) |>
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_edges() +
geom_dag_point(aes(color = var_type)) +
geom_dag_text() +
scale_color_manual(values = node_clrs, guide = "none") +
scale_y_continuous(expand = expansion(mult = 0.2)) +
labs(title = "(3) Mediator") +
theme_dag(base_family = "Noto Sans")
plot_m <- dagify(
y ~ x + u2,
x ~ u1,
z ~ u1 + u2,
coords = list(
x = c(x = 1, y = 3, z = 2, u1 = 1.5, u2 = 2.5),
y = c(x = 1, y = 1, z = 2, u1 = 2.5, u2 = 2.5)
)
) |>
tidy_dagitty() |>
mutate(var_type = case_match(name,
"x" ~ "Treatment",
"y" ~ "Outcome",
"z" ~ "Third thing",
.default = "Other"
)) |>
ggplot(aes(x = x, y = y, xend = xend, yend = yend)) +
geom_dag_edges() +
geom_dag_point(aes(color = var_type)) +
geom_dag_text() +
scale_color_manual(values = node_clrs, guide = "none") +
scale_y_continuous(expand = expansion(mult = 0.2)) +
labs(title = "(4) M-bias") +
theme_dag(base_family = "Noto Sans") +
theme(plot.margin = unit(c(2, 0, 0, 2), "lines"))
(plot_collider | plot_confounder) / (plot_mediator | plot_m)