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.1044 20000 0.3542 0.7598
#> X=~x3    0.7045 0.1176 20000 0.4744 0.9376
#> M=~x4    1.0000 0.0000 20000 1.0000 1.0000
#> M=~x5    1.1106 0.0650 20000 0.9837 1.2410
#> M=~x6    0.9268 0.0555 20000 0.8177 1.0362
#> Y=~x7    1.0000 0.0000 20000 1.0000 1.0000
#> Y=~x8    1.1482 0.1647 20000 0.8261 1.4663
#> Y=~x9    0.8854 0.1241 20000 0.6416 1.1283
#> a        0.5107 0.0955 20000 0.3265 0.6999
#> b        0.1884 0.0516 20000 0.0878 0.2886
#> x1~~x1   0.5320 0.1296 20000 0.2792 0.7852
#> x2~~x2   1.1269 0.1033 20000 0.9253 1.3276
#> x3~~x3   0.8647 0.0952 20000 0.6794 1.0512
#> x4~~x4   0.3714 0.0473 20000 0.2786 0.4642
#> x5~~x5   0.4519 0.0584 20000 0.3393 0.5658
#> x6~~x6   0.3551 0.0426 20000 0.2711 0.4386
#> x7~~x7   0.7309 0.0833 20000 0.5679 0.8955
#> x8~~x8   0.4257 0.0828 20000 0.2655 0.5886
#> x9~~x9   0.6605 0.0710 20000 0.5204 0.8008
#> X~~X     0.8264 0.1589 20000 0.5131 1.1396
#> M~~M     0.7638 0.0973 20000 0.5698 0.9548
#> Y~~Y     0.4175 0.0893 20000 0.2419 0.5909
#> indirect 0.0962 0.0319 20000 0.0398 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.6421 0.8916
#> X=~x2    0.4295 0.0614 20000 0.2969 0.5391
#> X=~x3    0.5672 0.0602 20000 0.4325 0.6688
#> M=~x4    0.8515 0.0230 20000 0.8025 0.8922
#> M=~x5    0.8531 0.0227 20000 0.8041 0.8938
#> M=~x6    0.8385 0.0234 20000 0.7891 0.8805
#> Y=~x7    0.6183 0.0543 20000 0.4991 0.7131
#> Y=~x8    0.7639 0.0553 20000 0.6410 0.8573
#> Y=~x9    0.5910 0.0545 20000 0.4747 0.6876
#> a        0.4691 0.0646 20000 0.3307 0.5844
#> b        0.2772 0.0698 20000 0.1346 0.4113
#> x1~~x1   0.3917 0.0964 20000 0.2051 0.5877
#> x2~~x2   0.8155 0.0515 20000 0.7093 0.9118
#> x3~~x3   0.6783 0.0664 20000 0.5528 0.8130
#> x4~~x4   0.2750 0.0389 20000 0.2039 0.3560
#> x5~~x5   0.2722 0.0385 20000 0.2012 0.3534
#> x6~~x6   0.2969 0.0391 20000 0.2248 0.3773
#> x7~~x7   0.6177 0.0658 20000 0.4915 0.7509
#> x8~~x8   0.4165 0.0829 20000 0.2651 0.5891
#> x9~~x9   0.6507 0.0635 20000 0.5272 0.7746
#> X~~X     1.0000 0.0000 20000 1.0000 1.0000
#> M~~M     0.7799 0.0593 20000 0.6585 0.8906
#> Y~~Y     0.9231 0.0389 20000 0.8308 0.9819
#> indirect 0.1301 0.0378 20000 0.0583 0.2062

References

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