Generate G from XYZ Specification
Arguments
- dir_xz, dir_yz
Effect direction between Z and X or Y (see details)
- gamma
Signed variance of Y explained by X, see details
- taux_xz, tau_yz
Effect size between Z and X or Y as signed percent variance explained (see details)
Details
This function generates a matrix G of direct effects corresponding to a model in with variables Y, X, and Z_1, ..., Z_K.
There is a causal effect of X on Y given by gamma, which specifies the proportion of the variance of Y explained by X.
The K variables Z_1, ..., Z_K can have
effects to or from X and Y but do not have direct effects on each other. Vectors dir_xz
and dir_yz
specify the direction
of these effects with +1 corresponding to "to" effects and -1 corresponding to "from" effects. For example, dir_xz = c(1, -1)
and dir_yz = c(1, 1)
would indicate two variables Z_1 and Z_2 with Z_1 being a common cause of both X and Y and Z_2
being a cause of $Y$ and caused by X (Z_2 is a mediator between X and Y). The function will give an error if there
is any index with dir_xz
equal to -1 and dir_yz
equal 1. This would indicate a variable that is a mediator between Y and
X, however, because there is an effect from X to Y assumed, the resulting graph would be cyclic and not allowed.
The inputs `tau_xz` and `tau_yz` specify the effect sizes of each of the Z_k variables on or
from X and $Y$. These are given in signed percent variance explained. If we again used dir_xz = c(1, -1)
and dir_yz = c(1, 1)
with tau_xz = c(0.2, -0.3)
and tau_yz = c(0.1, 0.25)
,
this means that the confounder, Z_1 explains 20% of the variance of X and 10% of the
variance of Y and both effects are positive. X explains 30% of the variance of the mediate Z_2 with a negative effect direction and
Z_2 explains 25% of the variance of Y.
Examples
xyz_to_G(tau_xz = c(0.2, -0.3), tau_yz = c(0.1, 0.25),
dir_xz = c(1, -1), dir_yz = c(1,1), gamma = 0)
#> [,1] [,2] [,3] [,4]
#> [1,] 0.0000000 0.0000000 0 0.0000000
#> [2,] 0.0000000 0.0000000 0 -0.5477226
#> [3,] 0.3162278 0.4472136 0 0.0000000
#> [4,] 0.5000000 0.0000000 0 0.0000000
# code below will give an error due to specification of a cyclic graph.
if (FALSE) {
xyz_to_G(tau_xz = c(0.2), tau_yz = c(0.1),
dir_xz = c(1), dir_yz = c(-1), gamma = 0.1)
}
# with gamma = 0, there is no cycle so no error
xyz_to_G(tau_xz = c(0.2), tau_yz = c(0.1),
dir_xz = c(1), dir_yz = c(-1), gamma = 0)
#> [,1] [,2] [,3]
#> [1,] 0 0.0000000 0.3162278
#> [2,] 0 0.0000000 0.0000000
#> [3,] 0 0.4472136 0.0000000