Calculate a data frame of total effects, representing the estimated effect of every variable on every other variable and any time-lag from 0 (simultaneous effects) to a user-specified maximum lag.
Arguments
- object
Output from
dsem
- n_lags
Number of lags over which to calculate total effects
Value
A data frame listing the time-lag (lag), variable that is undergoing some exogenous change (from), and the variable being impacted (to), along with the total effect (total_effect) including direct and indirect pathways, and the partial "direct" effect (direct_effect)
Details
Total effects are taken from the Leontief matrix \(\mathbf{(I-P)^{-1}}\), where \(\mathbf{P}\) is the path matrix across variables and times. This calculates the effect of a pulse perturbation at lag=0 for a given variable (from) upon any other variable (to) either in the same time (lag=0), or subsequent times (lag >= 1).
Examples
# Define linear model with slope of 0.5
sem = "
# from, to, lag, name, starting_value
x -> y, 0, slope, 0.5
"
# Build DSEM with specified value for path coefficients
mod = dsem(
sem = sem,
tsdata = ts(data.frame(x=rep(0,20),y=rep(0,20))),
control = dsem_control( run_model = FALSE )
)
#> List of estimated fixed and random effects:
#> Coefficient_name Number_of_coefficients Type
#> 1 beta_z 3 Fixed
#> 2 mu_j 2 Random
# Show that total effect of X on Y is 0.5 but does not propagate over time
total_effect(mod, n_lags = 2)
#> lag to from total_effect direct_effect
#> 1 0 x x 1.0 0.0
#> 2 1 x x 0.0 0.0
#> 3 0 y x 0.5 0.5
#> 4 1 y x 0.0 0.0
#> 5 0 x y 0.0 0.0
#> 6 1 x y 0.0 0.0
#> 7 0 y y 1.0 0.0
#> 8 1 y y 0.0 0.0
# Define linear model with slope of 0.5 and autocorrelated response
sem = "
x -> y, 0, slope, 0.5
y -> y, 1, ar_y, 0.8
"
mod = dsem(
sem = sem,
tsdata = ts(data.frame(x=rep(0,20),y=rep(0,20))),
control = dsem_control( run_model = FALSE )
)
#> List of estimated fixed and random effects:
#> Coefficient_name Number_of_coefficients Type
#> 1 beta_z 4 Fixed
#> 2 mu_j 2 Random
# Show that total effect of X on Y is 0.5 with decay of 0.8 for each time
total_effect(mod, n_lags = 4)
#> lag to from total_effect direct_effect
#> 1 0 x x 1.000 0.0
#> 2 1 x x 0.000 0.0
#> 3 2 x x 0.000 0.0
#> 4 3 x x 0.000 0.0
#> 5 0 y x 0.500 0.5
#> 6 1 y x 0.400 0.0
#> 7 2 y x 0.320 0.0
#> 8 3 y x 0.256 0.0
#> 9 0 x y 0.000 0.0
#> 10 1 x y 0.000 0.0
#> 11 2 x y 0.000 0.0
#> 12 3 x y 0.000 0.0
#> 13 0 y y 1.000 0.0
#> 14 1 y y 0.800 0.8
#> 15 2 y y 0.640 0.0
#> 16 3 y y 0.512 0.0