-
Notifications
You must be signed in to change notification settings - Fork 1
Description
library(lavaan)
library(manymome)
data(data_mome_demo_missing)
print(head(data_mome_demo_missing), digits = 3)
x1 x2 m1 m2 m3 y1 y2 w1 w2 c1 c2
1 4.54 4.86 4.44 NA 4.51 7.58 4.01 4.40 6.12 6.37 5.28
2 4.72 6.46 3.09 3.75 4.66 1.56 5.87 4.65 4.23 5.89 5.74
3 4.17 4.90 4.50 5.60 3.53 5.26 3.16 3.07 NA 4.86 6.49
4 6.47 5.75 5.92 4.12 6.92 4.80 5.80 6.19 5.12 3.04 4.40
5 6.36 5.46 6.30 7.83 6.16 19.83 4.63 3.63 9.61 5.19 6.36
6 4.36 3.85 5.20 4.48 1.68 5.09 2.89 6.54 4.70 6.41 3.48
data_centered <- as.data.frame(scale(data_mome_demo_missing, scale = FALSE))
data_centered$w1x1 <- data_centered$w1 * data_centered$x1
data_centered$w2m2 <- data_centered$w2 * data_centered$m2
mod <-
- "
- m1 ~ x1 + w1 + x2 + c1 + c2
- m2 ~ m1 + c1 + c2
- m3 ~ x2 + x1 + c1 + c2
- y1 ~ m2 + w2 + x1 + x2 + m3 + c1 + c2
- y2 ~ m3 + x2 + x1 + m2 + c1 + c2
-
Covariances for the error term of m2
- m2 ~~ w2
-
Covariances between all exogenous variables
- w2 ~~ x1 + w1 + x2 + c1 + c2
- x1 ~~ w1 + x2 + c1 + c2
- w1 ~~ x2 + c1 + c2
- x2 ~~ c1 + c2
- c1 ~~ c2
- "
library(lavaan)
fit <- sem(mod, data_centered, meanstructure = TRUE,
-
fixed.x = FALSE, missing = "fiml")
fit.s = summary(fit, fit.measures = TRUE)
all_p <- all_indirect_paths(fit)
all_p
Call:
all_indirect_paths(fit = fit)
Path(s):
path
1 m1 -> m2 -> y1
2 m1 -> m2 -> y2
3 x1 -> m1 -> m2
4 x1 -> m1 -> m2 -> y1
5 x1 -> m3 -> y1
6 x1 -> m1 -> m2 -> y2
7 x1 -> m3 -> y2
8 w1 -> m1 -> m2
9 w1 -> m1 -> m2 -> y1
10 w1 -> m1 -> m2 -> y2
11 x2 -> m1 -> m2
12 x2 -> m1 -> m2 -> y1
13 x2 -> m3 -> y1
14 x2 -> m1 -> m2 -> y2
15 x2 -> m3 -> y2
16 c1 -> m1 -> m2
17 c1 -> m1 -> m2 -> y1
18 c1 -> m2 -> y1
19 c1 -> m3 -> y1
20 c1 -> m1 -> m2 -> y2
21 c1 -> m2 -> y2
22 c1 -> m3 -> y2
23 c2 -> m1 -> m2
24 c2 -> m1 -> m2 -> y1
25 c2 -> m2 -> y1
26 c2 -> m3 -> y1
27 c2 -> m1 -> m2 -> y2
28 c2 -> m2 -> y2
29 c2 -> m3 -> y2
ind_t <- many_indirect_effects(paths = all_p,
-
fit = fit, -
mc_out = mc_med, -
boot_ci = F, -
R = 1000, -
mc_ci = TRUE, -
standardized_x = TRUE, -
standardized_y = TRUE, -
seed = 43143)
An error occurred at (function (x, y, m = NULL, fit = NULL, est = NULL, implied_stats = NULL, ...): No path from 'm1' to 'y1' through 'm2'. Please check the arguments x, y, and m.
This error message occurred when I used your data, removed the moderation term, and tested all indirect effects.