Skip to contents

A simple mediation model with two groups.

Usage

data_med_mg

Format

A data frame with 100 rows and 5 variables:

x

Predictor. Numeric.

m

Mediator. Numeric.

y

Outcome variable. Numeric.

c1

Control variable. Numeric.

c2

Control variable. Numeric.

group

Group variable. Character. "Group A" or "Group B"

Examples

library(lavaan)
data(data_med_mg)
mod <-
"
m ~ c(a1, a2) * x + c1 + c2
y ~ c(b1, b2) * m + x + c1 + c2
a1b1 := a1 * b1
a2b2 := a2 * b2
abdiff := a2b2 - a1b1
"
fit <- sem(mod, data_med_mg, fixed.x = FALSE,
           group = "group")
parameterEstimates(fit)
#>       lhs op       rhs block group  label    est    se       z pvalue ci.lower
#> 1       m  ~         x     1     1     a1  0.880 0.093   9.507  0.000    0.698
#> 2       m  ~        c1     1     1         0.264 0.104   2.531  0.011    0.059
#> 3       m  ~        c2     1     1        -0.316 0.095  -3.315  0.001   -0.502
#> 4       y  ~         m     1     1     b1  0.465 0.190   2.446  0.014    0.092
#> 5       y  ~         x     1     1         0.321 0.243   1.324  0.186   -0.154
#> 6       y  ~        c1     1     1         0.285 0.204   1.395  0.163   -0.115
#> 7       y  ~        c2     1     1        -0.228 0.191  -1.195  0.232   -0.602
#> 8       m ~~         m     1     1         1.006 0.142   7.071  0.000    0.727
#> 9       y ~~         y     1     1         3.633 0.514   7.071  0.000    2.626
#> 10      x ~~         x     1     1         1.222 0.173   7.071  0.000    0.883
#> 11      x ~~        c1     1     1        -0.080 0.107  -0.741  0.459   -0.290
#> 12      x ~~        c2     1     1        -0.212 0.121  -1.761  0.078   -0.449
#> 13     c1 ~~        c1     1     1         0.939 0.133   7.071  0.000    0.678
#> 14     c1 ~~        c2     1     1        -0.071 0.104  -0.677  0.499   -0.275
#> 15     c2 ~~        c2     1     1         1.154 0.163   7.071  0.000    0.834
#> 16      m ~1               1     1        10.647 1.156   9.211  0.000    8.382
#> 17      y ~1               1     1         6.724 2.987   2.251  0.024    0.870
#> 18      x ~1               1     1         9.985 0.111  90.313  0.000    9.768
#> 19     c1 ~1               1     1         2.055 0.097  21.214  0.000    1.865
#> 20     c2 ~1               1     1         4.883 0.107  45.454  0.000    4.672
#> 21      m  ~         x     2     2     a2  0.597 0.081   7.335  0.000    0.438
#> 22      m  ~        c1     2     2         0.226 0.087   2.610  0.009    0.056
#> 23      m  ~        c2     2     2        -0.181 0.078  -2.335  0.020   -0.333
#> 24      y  ~         m     2     2     b2  1.110 0.171   6.492  0.000    0.775
#> 25      y  ~         x     2     2         0.264 0.199   1.330  0.183   -0.125
#> 26      y  ~        c1     2     2        -0.016 0.186  -0.088  0.930   -0.381
#> 27      y  ~        c2     2     2        -0.072 0.165  -0.437  0.662   -0.396
#> 28      m ~~         m     2     2         0.998 0.115   8.660  0.000    0.772
#> 29      y ~~         y     2     2         4.379 0.506   8.660  0.000    3.388
#> 30      x ~~         x     2     2         1.019 0.118   8.660  0.000    0.788
#> 31      x ~~        c1     2     2         0.102 0.079   1.299  0.194   -0.052
#> 32      x ~~        c2     2     2        -0.050 0.087  -0.574  0.566   -0.221
#> 33     c1 ~~        c1     2     2         0.906 0.105   8.660  0.000    0.701
#> 34     c1 ~~        c2     2     2         0.109 0.083   1.313  0.189   -0.054
#> 35     c2 ~~        c2     2     2         1.122 0.130   8.660  0.000    0.868
#> 36      m ~1               2     2         7.862 0.924   8.511  0.000    6.051
#> 37      y ~1               2     2         1.757 2.356   0.746  0.456   -2.861
#> 38      x ~1               2     2        10.046 0.082 121.888  0.000    9.884
#> 39     c1 ~1               2     2         2.138 0.078  27.515  0.000    1.986
#> 40     c2 ~1               2     2         5.088 0.087  58.820  0.000    4.918
#> 41   a1b1 :=     a1*b1     0     0   a1b1  0.409 0.173   2.368  0.018    0.071
#> 42   a2b2 :=     a2*b2     0     0   a2b2  0.663 0.136   4.861  0.000    0.396
#> 43 abdiff := a2b2-a1b1     0     0 abdiff  0.254 0.220   1.155  0.248   -0.177
#>    ci.upper
#> 1     1.061
#> 2     0.468
#> 3    -0.129
#> 4     0.837
#> 5     0.797
#> 6     0.685
#> 7     0.146
#> 8     1.284
#> 9     4.639
#> 10    1.561
#> 11    0.131
#> 12    0.024
#> 13    1.199
#> 14    0.134
#> 15    1.474
#> 16   12.913
#> 17   12.578
#> 18   10.201
#> 19    2.245
#> 20    5.093
#> 21    0.757
#> 22    0.396
#> 23   -0.029
#> 24    1.446
#> 25    0.654
#> 26    0.348
#> 27    0.252
#> 28    1.224
#> 29    5.370
#> 30    1.250
#> 31    0.257
#> 32    0.121
#> 33    1.111
#> 34    0.271
#> 35    1.376
#> 36    9.672
#> 37    6.375
#> 38   10.208
#> 39    2.291
#> 40    5.258
#> 41    0.747
#> 42    0.930
#> 43    0.685