# 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 )
)
# Show that total effect of X on Y is 0.5 but does not propagate over time
total_effect(mod, n_lags = 2)
# 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 )
)
# 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)
Run the code above in your browser using DataLab