Skip to contents

In this example, the Monte Carlo method is used to generate confidence intervals for the indirect effects in a simple mediation model with latent variables. X, M, and Y are latent variables with three indicators each where X is the predictor, M is the mediator, and Y is the dependent variable.

The Simple Mediation Model with Latent Variables
The Simple Mediation Model with Latent Variables

Model Specification

The indirect effect is defined by the product of the slopes of paths X to M labeled as a and M to Y labeled as b. In this example, we are interested in the confidence intervals of indirect defined as the product of a and b using the := operator in the lavaan model syntax.

model <- "
  X =~ x1 + x2 + x3
  M =~ x4 + x5 + x6
  Y =~ x7 + x8 + x9
  M ~ a * X
  Y ~ b * M
  indirect := a * b
"

Model Fitting

We can now fit the model using the sem() function from lavaan using the Holzinger and Swineford (1939) data set.

df <- lavaan::HolzingerSwineford1939
fit <- sem(data = df, model = model)

Monte Carlo Confidence Intervals

The fit lavaan object can then be passed to the MC() function from semmcci to generate Monte Carlo confidence intervals.

MC(fit, R = 20000L, alpha = 0.05)
#> Monte Carlo Confidence Intervals
#>             est     se     R   2.5%  97.5%
#> X=~x1    1.0000 0.0000 20000 1.0000 1.0000
#> X=~x2    0.5554 0.1043 20000 0.3541 0.7594
#> X=~x3    0.7045 0.1172 20000 0.4744 0.9338
#> M=~x4    1.0000 0.0000 20000 1.0000 1.0000
#> M=~x5    1.1106 0.0648 20000 0.9839 1.2389
#> M=~x6    0.9268 0.0554 20000 0.8185 1.0372
#> Y=~x7    1.0000 0.0000 20000 1.0000 1.0000
#> Y=~x8    1.1482 0.1647 20000 0.8245 1.4665
#> Y=~x9    0.8854 0.1241 20000 0.6417 1.1284
#> a        0.5107 0.0954 20000 0.3259 0.6987
#> b        0.1884 0.0517 20000 0.0875 0.2889
#> x1~~x1   0.5320 0.1299 20000 0.2766 0.7884
#> x2~~x2   1.1269 0.1033 20000 0.9252 1.3283
#> x3~~x3   0.8647 0.0951 20000 0.6764 1.0502
#> x4~~x4   0.3714 0.0476 20000 0.2784 0.4650
#> x5~~x5   0.4519 0.0586 20000 0.3383 0.5678
#> x6~~x6   0.3551 0.0427 20000 0.2709 0.4381
#> x7~~x7   0.7309 0.0833 20000 0.5680 0.8954
#> x8~~x8   0.4257 0.0828 20000 0.2656 0.5887
#> x9~~x9   0.6605 0.0710 20000 0.5206 0.8010
#> X~~X     0.8264 0.1590 20000 0.5164 1.1385
#> M~~M     0.7638 0.0972 20000 0.5728 0.9551
#> Y~~Y     0.4175 0.0893 20000 0.2418 0.5901
#> indirect 0.0962 0.0319 20000 0.0399 0.1641

Standardized Monte Carlo Confidence Intervals

Standardized Monte Carlo Confidence intervals can be generated by passing the result of the MC() function to the MCStd() function.

fit <- sem(data = df, model = model)
unstd <- MC(fit, R = 20000L, alpha = 0.05)
MCStd(unstd, alpha = 0.05)
#> Standardized Monte Carlo Confidence Intervals
#>             est     se     R   2.5%  97.5%
#> X=~x1    0.7800 0.0629 20000 0.6419 0.8907
#> X=~x2    0.4295 0.0613 20000 0.2965 0.5391
#> X=~x3    0.5672 0.0601 20000 0.4327 0.6702
#> M=~x4    0.8515 0.0230 20000 0.8023 0.8925
#> M=~x5    0.8531 0.0228 20000 0.8039 0.8939
#> M=~x6    0.8385 0.0235 20000 0.7881 0.8804
#> Y=~x7    0.6183 0.0543 20000 0.4990 0.7131
#> Y=~x8    0.7639 0.0553 20000 0.6408 0.8575
#> Y=~x9    0.5910 0.0545 20000 0.4749 0.6876
#> a        0.4691 0.0646 20000 0.3306 0.5845
#> b        0.2772 0.0698 20000 0.1352 0.4111
#> x1~~x1   0.3917 0.0965 20000 0.2066 0.5879
#> x2~~x2   0.8155 0.0515 20000 0.7093 0.9121
#> x3~~x3   0.6783 0.0663 20000 0.5509 0.8127
#> x4~~x4   0.2750 0.0391 20000 0.2035 0.3562
#> x5~~x5   0.2722 0.0387 20000 0.2010 0.3538
#> x6~~x6   0.2969 0.0392 20000 0.2250 0.3789
#> x7~~x7   0.6177 0.0658 20000 0.4915 0.7510
#> x8~~x8   0.4165 0.0829 20000 0.2648 0.5893
#> x9~~x9   0.6507 0.0635 20000 0.5273 0.7744
#> X~~X     1.0000 0.0000 20000 1.0000 1.0000
#> M~~M     0.7799 0.0593 20000 0.6584 0.8907
#> Y~~Y     0.9231 0.0388 20000 0.8310 0.9817
#> indirect 0.1301 0.0377 20000 0.0579 0.2057

References

Pesigan, I. J. A., & Cheung, S. F. (2023). Monte Carlo confidence intervals for the indirect effect with missing data. Behavior Research Methods. https://doi.org/10.3758/s13428-023-02114-4