Assess if a variable confounds a relationship
Details
A confounder is a common cause of x and y. z therefore has to reach
x by a directed path that does not run through y, and reach y by a
directed path that does not run through x. Being a descendant of z is
not enough: descent is transitive through x, so every upstream cause of the
exposure, such as an instrument, would qualify even though it opens no
backdoor path.
Examples
dag <- dagify(y ~ z, x ~ z)
is_confounder(dag, "z", "x", "y")
#> [1] TRUE
is_confounder(dag, "x", "z", "y")
#> [1] FALSE
