
Converts total effects to direct effects and visa verse
Source:R/total_to_direct.R
total_direct_conversion.Rd
Assuming a matrix of total linear effects W we can convert this to a matrix of direct effects W_dir This assume that W_tot = W_dir + W_dir^2 + W_dir^3 + ... We can solve for W_dir = I - (I + W_tot)^-1 assume that the spectral radius (largest absolute eigenvalue) of W_dir < 1 This condition is the same that abs(eigenvalue(W_tot) / (1 + eigenvalue(W_tot))) < 1
Usage
total_to_direct(W, restrict_dag = TRUE, enforce_spectral_radius = TRUE)
direct_to_total(W, restrict_dag = TRUE)
Examples
B <- matrix(c(0, 0.6, -0.5, 0), nrow = 2, byrow = TRUE)
total_to_direct(B, restrict_dag = F)
#> [,1] [,2]
#> [1,] 0.2307692 0.4615385
#> [2,] -0.3846154 0.2307692
all(zapsmall(direct_to_total(total_to_direct(B, restrict_dag = F), restrict_dag = F)) == B)
#> [1] TRUE
B2 <- matrix(c(0,0,0,
1,0,0,
1,1,0), nrow = 3, byrow = TRUE)
total_to_direct(B2)
#> [,1] [,2] [,3]
#> [1,] 0 0 0
#> [2,] 1 0 0
#> [3,] 0 1 0