semmcci: Methods (MI)
Ivan Jacob Agaloos Pesigan
2026-11-30
Source:vignettes/methods-mc-mi.Rmd
methods-mc-mi.RmdData
summary(object = df)
#> X M Y
#> Min. :-3.199558 Min. :-3.37128 Min. :-3.61432
#> 1st Qu.:-0.632676 1st Qu.:-0.70516 1st Qu.:-0.66921
#> Median : 0.028235 Median : 0.02825 Median :-0.04833
#> Mean : 0.002688 Mean :-0.01992 Mean :-0.01538
#> 3rd Qu.: 0.657543 3rd Qu.: 0.65240 3rd Qu.: 0.65293
#> Max. : 3.470910 Max. : 2.93497 Max. : 3.09950
#> NAs :100 NAs :100 NAs :100Multiple Imputation
Perform the appropriate multiple imputation approach to deal with missing values. In this example, we impute multivariate missing data under the normal model.
mi <- mice::mice(
data = df,
method = "norm",
m = 100,
print = FALSE,
seed = 42
)Model Specification
model <- "
Y ~ cp * X + b * M
M ~ a * X
X ~~ X
indirect := a * b
direct := cp
total := cp + (a * b)
"Model Fitting
fit <- lavaan::sem(data = df, model = model)Monte Carlo Confidence Intervals
unstd <- MCMI(lav = fit, mi = mi, R = 20000L, alpha = 0.05)Methods
print(x = unstd)
#> Monte Carlo Confidence Intervals (Multiple Imputation Estimates)
#> est se R 2.5% 97.5%
#> cp 0.2328 0.0298 20000 0.1743 0.2917
#> b 0.5113 0.0300 20000 0.4530 0.5698
#> a 0.4811 0.0286 20000 0.4254 0.5376
#> X~~X 1.0617 0.0498 20000 0.9633 1.1595
#> Y~~Y 0.5533 0.0273 20000 0.5003 0.6070
#> M~~M 0.7568 0.0363 20000 0.6848 0.8274
#> indirect 0.2460 0.0204 20000 0.2078 0.2873
#> direct 0.2328 0.0298 20000 0.1743 0.2917
#> total 0.4788 0.0283 20000 0.4232 0.5347summary
summary(object = unstd)
#> Monte Carlo Confidence Intervals (Multiple Imputation Estimates)
#> est se R 2.5% 97.5%
#> cp 0.2328 0.0298 20000 0.1743 0.2917
#> b 0.5113 0.0300 20000 0.4530 0.5698
#> a 0.4811 0.0286 20000 0.4254 0.5376
#> X~~X 1.0617 0.0498 20000 0.9633 1.1595
#> Y~~Y 0.5533 0.0273 20000 0.5003 0.6070
#> M~~M 0.7568 0.0363 20000 0.6848 0.8274
#> indirect 0.2460 0.0204 20000 0.2078 0.2873
#> direct 0.2328 0.0298 20000 0.1743 0.2917
#> total 0.4788 0.0283 20000 0.4232 0.5347coef
stats::coef(object = unstd)
#> cp b a X~~X Y~~Y M~~M indirect direct
#> 0.2328242 0.5113353 0.4810732 1.0617011 0.5533052 0.7567771 0.2459664 0.2328242
#> total
#> 0.4787907vcov
stats::vcov(object = unstd)
#> cp b a X~~X Y~~Y
#> cp 8.883655e-04 -4.829675e-04 -3.781824e-05 -1.435922e-06 -2.692413e-05
#> b -4.829675e-04 8.982023e-04 -1.603699e-05 -1.181034e-05 -2.030995e-05
#> a -3.781824e-05 -1.603699e-05 8.180364e-04 -1.553315e-05 2.534591e-05
#> X~~X -1.435922e-06 -1.181034e-05 -1.553315e-05 2.482437e-03 -3.745333e-05
#> Y~~Y -2.692413e-05 -2.030995e-05 2.534591e-05 -3.745333e-05 7.469819e-04
#> M~~M -2.583432e-06 3.565247e-06 -4.754760e-05 1.535558e-05 -1.822341e-05
#> indirect -2.515315e-04 4.241191e-04 4.104538e-04 -1.369479e-05 2.687306e-06
#> direct 8.883655e-04 -4.829675e-04 -3.781824e-05 -1.435922e-06 -2.692413e-05
#> total 6.368339e-04 -5.884838e-05 3.726356e-04 -1.513071e-05 -2.423682e-05
#> M~~M indirect direct total
#> cp -2.583432e-06 -2.515315e-04 8.883655e-04 6.368339e-04
#> b 3.565247e-06 4.241191e-04 -4.829675e-04 -5.884838e-05
#> a -4.754760e-05 4.104538e-04 -3.781824e-05 3.726356e-04
#> X~~X 1.535558e-05 -1.369479e-05 -1.435922e-06 -1.513071e-05
#> Y~~Y -1.822341e-05 2.687306e-06 -2.692413e-05 -2.423682e-05
#> M~~M 1.314238e-03 -2.249550e-05 -2.583432e-06 -2.507893e-05
#> indirect -2.249550e-05 4.146730e-04 -2.515315e-04 1.631415e-04
#> direct -2.583432e-06 -2.515315e-04 8.883655e-04 6.368339e-04
#> total -2.507893e-05 1.631415e-04 6.368339e-04 7.999754e-04confint
stats::confint(object = unstd, level = 0.95)
#> 2.5 % 97.5 %
#> cp 0.1743356 0.2916594
#> b 0.4530140 0.5698479
#> a 0.4253709 0.5375688
#> X~~X 0.9632723 1.1594869
#> Y~~Y 0.5003001 0.6070128
#> M~~M 0.6848319 0.8273614
#> indirect 0.2078498 0.2872534
#> direct 0.1743356 0.2916594
#> total 0.4232401 0.5347094Standardized Monte Carlo Confidence Intervals
fit <- lavaan::sem(data = df, model = model, fixed.x = FALSE)
unstd <- MCMI(lav = fit, mi = mi, R = 20000L, alpha = 0.05)
std <- MCStd(mc = unstd, alpha = 0.05)Methods
print(x = std)
#> Standardized Monte Carlo Confidence Intervals
#> est se R 2.5% 97.5%
#> cp 0.2450 0.0304 20000 0.1806 0.2991
#> b 0.5189 0.0271 20000 0.4595 0.5657
#> a 0.5031 0.0259 20000 0.4439 0.5441
#> X~~X 1.0000 0.0000 20000 1.0000 1.0000
#> Y~~Y 0.5429 0.0251 20000 0.5067 0.6058
#> M~~M 0.7469 0.0256 20000 0.7039 0.8030
#> indirect 0.2610 0.0189 20000 0.2179 0.2919
#> direct 0.2450 0.0304 20000 0.1806 0.2991
#> total 0.5060 0.0263 20000 0.4417 0.5445summary
summary(object = std)
#> Standardized Monte Carlo Confidence Intervals
#> est se R 2.5% 97.5%
#> cp 0.2450 0.0304 20000 0.1806 0.2991
#> b 0.5189 0.0271 20000 0.4595 0.5657
#> a 0.5031 0.0259 20000 0.4439 0.5441
#> X~~X 1.0000 0.0000 20000 1.0000 1.0000
#> Y~~Y 0.5429 0.0251 20000 0.5067 0.6058
#> M~~M 0.7469 0.0256 20000 0.7039 0.8030
#> indirect 0.2610 0.0189 20000 0.2179 0.2919
#> direct 0.2450 0.0304 20000 0.1806 0.2991
#> total 0.5060 0.0263 20000 0.4417 0.5445coef
stats::coef(object = std)
#> cp b a X~~X Y~~Y M~~M indirect direct
#> 0.2449797 0.5188628 0.5030687 1.0000000 0.5428754 0.7469219 0.2610236 0.2449797
#> total
#> 0.5060033vcov
stats::vcov(object = std)
#> cp b a X~~X Y~~Y
#> cp 9.224575e-04 -5.949309e-04 1.736329e-06 3.537922e-21 -1.598052e-04
#> b -5.949309e-04 7.352536e-04 2.360717e-06 -1.635531e-21 -3.410438e-04
#> a 1.736329e-06 2.360717e-06 6.691549e-04 2.768279e-20 -1.689271e-04
#> X~~X 3.537922e-21 -1.635531e-21 2.768279e-20 8.370356e-33 -8.317204e-21
#> Y~~Y -1.598052e-04 -3.410438e-04 -1.689271e-04 -8.317204e-21 6.306953e-04
#> M~~M -1.765563e-06 -2.213886e-06 -6.610245e-04 -2.807903e-20 1.667893e-04
#> indirect -2.938264e-04 3.651671e-04 3.443190e-04 1.343414e-20 -2.550644e-04
#> direct 9.224575e-04 -5.949309e-04 1.736329e-06 3.537922e-21 -1.598052e-04
#> total 6.286311e-04 -2.297638e-04 3.460553e-04 1.697206e-20 -4.148696e-04
#> M~~M indirect direct total
#> cp -1.765563e-06 -2.938264e-04 9.224575e-04 6.286311e-04
#> b -2.213886e-06 3.651671e-04 -5.949309e-04 -2.297638e-04
#> a -6.610245e-04 3.443190e-04 1.736329e-06 3.460553e-04
#> X~~X -2.807903e-20 1.343414e-20 3.537922e-21 1.697206e-20
#> Y~~Y 1.667893e-04 -2.550644e-04 -1.598052e-04 -4.148696e-04
#> M~~M 6.538735e-04 -3.400845e-04 -1.765563e-06 -3.418500e-04
#> indirect -3.400845e-04 3.578292e-04 -2.938264e-04 6.400278e-05
#> direct -1.765563e-06 -2.938264e-04 9.224575e-04 6.286311e-04
#> total -3.418500e-04 6.400278e-05 6.286311e-04 6.926339e-04confint
stats::confint(object = std, level = 0.95)
#> 2.5 % 97.5 %
#> cp 0.1806353 0.2991427
#> b 0.4594885 0.5656630
#> a 0.4438533 0.5441467
#> X~~X 1.0000000 1.0000000
#> Y~~Y 0.5066862 0.6057645
#> M~~M 0.7039043 0.8029943
#> indirect 0.2179194 0.2918704
#> direct 0.1806353 0.2991427
#> total 0.4416713 0.5445210References
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