Skip to contents

Data

summary(df)
#>        X                  M                  Y           
#>  Min.   :-3.19956   Min.   :-3.37128   Min.   :-3.61432  
#>  1st Qu.:-0.63268   1st Qu.:-0.70516   1st Qu.:-0.66921  
#>  Median : 0.02823   Median : 0.02825   Median :-0.04833  
#>  Mean   : 0.00269   Mean   :-0.01992   Mean   :-0.01538  
#>  3rd Qu.: 0.65754   3rd Qu.: 0.65240   3rd Qu.: 0.65293  
#>  Max.   : 3.47091   Max.   : 2.93497   Max.   : 3.09950  
#>  NA's   :100        NA's   :100        NA's   :100

Multiple 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(
  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 <- sem(data = df, model = model)

Monte Carlo Confidence Intervals

unstd <- MCMI(fit, mi = mi, R = 20000L, alpha = 0.05)

Methods

print

print(unstd)
#> Monte Carlo Confidence Intervals (Multiple Imputation Estimates)
#>             est     se     R   2.5%  97.5%
#> cp       0.2328 0.0299 20000 0.1745 0.2909
#> b        0.5113 0.0298 20000 0.4526 0.5698
#> a        0.4811 0.0287 20000 0.4248 0.5370
#> X~~X     1.0617 0.0498 20000 0.9634 1.1594
#> Y~~Y     0.5533 0.0273 20000 0.5004 0.6071
#> M~~M     0.7568 0.0362 20000 0.6862 0.8293
#> indirect 0.2460 0.0204 20000 0.2071 0.2868
#> direct   0.2328 0.0299 20000 0.1745 0.2909
#> total    0.4788 0.0285 20000 0.4233 0.5338

summary

summary(unstd)
#> Monte Carlo Confidence Intervals (Multiple Imputation Estimates)
#>             est     se     R   2.5%  97.5%
#> cp       0.2328 0.0299 20000 0.1745 0.2909
#> b        0.5113 0.0298 20000 0.4526 0.5698
#> a        0.4811 0.0287 20000 0.4248 0.5370
#> X~~X     1.0617 0.0498 20000 0.9634 1.1594
#> Y~~Y     0.5533 0.0273 20000 0.5004 0.6071
#> M~~M     0.7568 0.0362 20000 0.6862 0.8293
#> indirect 0.2460 0.0204 20000 0.2071 0.2868
#> direct   0.2328 0.0299 20000 0.1745 0.2909
#> total    0.4788 0.0285 20000 0.4233 0.5338

coef

coef(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.4787907

vcov

vcov(unstd)
#>                     cp             b             a          X~~X          Y~~Y
#> cp        8.943569e-04 -4.831282e-04 -3.423363e-05  8.313977e-06 -2.528988e-05
#> b        -4.831282e-04  8.903650e-04 -1.110843e-05  3.426335e-06 -2.211357e-05
#> a        -3.423363e-05 -1.110843e-05  8.253544e-04 -8.348106e-06  2.390819e-05
#> X~~X      8.313977e-06  3.426335e-06 -8.348106e-06  2.482088e-03 -3.473128e-05
#> Y~~Y     -2.528988e-05 -2.211357e-05  2.390819e-05 -3.473128e-05  7.461105e-04
#> M~~M     -5.812966e-06  7.335175e-06 -7.254267e-05 -3.145606e-05  2.028020e-06
#> indirect -2.497870e-04  4.223324e-04  4.165626e-04 -2.547179e-06  1.278967e-06
#> direct    8.943569e-04 -4.831282e-04 -3.423363e-05  8.313977e-06 -2.528988e-05
#> total     6.445700e-04 -6.079582e-05  3.823290e-04  5.766798e-06 -2.401091e-05
#>                   M~~M      indirect        direct         total
#> cp       -5.812966e-06 -2.497870e-04  8.943569e-04  6.445700e-04
#> b         7.335175e-06  4.223324e-04 -4.831282e-04 -6.079582e-05
#> a        -7.254267e-05  4.165626e-04 -3.423363e-05  3.823290e-04
#> X~~X     -3.145606e-05 -2.547179e-06  8.313977e-06  5.766798e-06
#> Y~~Y      2.028020e-06  1.278967e-06 -2.528988e-05 -2.401091e-05
#> M~~M      1.309986e-03 -3.349766e-05 -5.812966e-06 -3.931063e-05
#> indirect -3.349766e-05  4.166920e-04 -2.497870e-04  1.669050e-04
#> direct   -5.812966e-06 -2.497870e-04  8.943569e-04  6.445700e-04
#> total    -3.931063e-05  1.669050e-04  6.445700e-04  8.114750e-04

confint

confint(unstd, level = 0.95)
#>              2.5 %    97.5 %
#> cp       0.1745148 0.2908682
#> b        0.4525977 0.5697833
#> a        0.4247560 0.5370047
#> X~~X     0.9633807 1.1594261
#> Y~~Y     0.5003952 0.6070687
#> M~~M     0.6862436 0.8292795
#> indirect 0.2071186 0.2867967
#> direct   0.1745148 0.2908682
#> total    0.4233013 0.5337567

Standardized Monte Carlo Confidence Intervals

fit <- sem(data = df, model = model, fixed.x = FALSE)
unstd <- MCMI(fit, mi = mi, R = 20000L, alpha = 0.05)
std <- MCStd(unstd, alpha = 0.05)

Methods

print(std)
#> Standardized Monte Carlo Confidence Intervals
#>             est     se     R   2.5%  97.5%
#> cp       0.2450 0.0304 20000 0.1804 0.3006
#> b        0.5189 0.0271 20000 0.4592 0.5659
#> a        0.5031 0.0261 20000 0.4432 0.5452
#> X~~X     1.0000 0.0000 20000 1.0000 1.0000
#> Y~~Y     0.5429 0.0250 20000 0.5063 0.6047
#> M~~M     0.7469 0.0258 20000 0.7028 0.8035
#> indirect 0.2610 0.0189 20000 0.2183 0.2924
#> direct   0.2450 0.0304 20000 0.1804 0.3006
#> total    0.5060 0.0262 20000 0.4422 0.5444

summary

summary(std)
#> Standardized Monte Carlo Confidence Intervals
#>             est     se     R   2.5%  97.5%
#> cp       0.2450 0.0304 20000 0.1804 0.3006
#> b        0.5189 0.0271 20000 0.4592 0.5659
#> a        0.5031 0.0261 20000 0.4432 0.5452
#> X~~X     1.0000 0.0000 20000 1.0000 1.0000
#> Y~~Y     0.5429 0.0250 20000 0.5063 0.6047
#> M~~M     0.7469 0.0258 20000 0.7028 0.8035
#> indirect 0.2610 0.0189 20000 0.2183 0.2924
#> direct   0.2450 0.0304 20000 0.1804 0.3006
#> total    0.5060 0.0262 20000 0.4422 0.5444

coef

coef(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.5060033

vcov

vcov(std)
#>                     cp             b             a          X~~X          Y~~Y
#> cp        9.262683e-04 -5.963270e-04 -5.810115e-06  3.060285e-21 -1.600048e-04
#> b        -5.963270e-04  7.365269e-04 -9.081271e-06 -1.431459e-20 -3.385029e-04
#> a        -5.810115e-06 -9.081271e-06  6.790679e-04 -4.537926e-21 -1.497373e-04
#> X~~X      3.060285e-21 -1.431459e-20 -4.537926e-21  1.184337e-32  1.760685e-20
#> Y~~Y     -1.600048e-04 -3.385029e-04 -1.497373e-04  1.760685e-20  6.231579e-04
#> M~~M      5.787999e-06  8.982322e-06 -6.710890e-04  3.531641e-21  1.479133e-04
#> indirect -2.983751e-04  3.601056e-04  3.440031e-04 -9.773505e-21 -2.442477e-04
#> direct    9.262683e-04 -5.963270e-04 -5.810115e-06  3.060285e-21 -1.600048e-04
#> total     6.278932e-04 -2.362214e-04  3.381930e-04 -6.713220e-21 -4.042524e-04
#>                   M~~M      indirect        direct         total
#> cp        5.787999e-06 -2.983751e-04  9.262683e-04  6.278932e-04
#> b         8.982322e-06  3.601056e-04 -5.963270e-04 -2.362214e-04
#> a        -6.710890e-04  3.440031e-04 -5.810115e-06  3.381930e-04
#> X~~X      3.531641e-21 -9.773505e-21  3.060285e-21 -6.713220e-21
#> Y~~Y      1.479133e-04 -2.442477e-04 -1.600048e-04 -4.042524e-04
#> M~~M      6.641077e-04 -3.399516e-04  5.787999e-06 -3.341636e-04
#> indirect -3.399516e-04  3.553942e-04 -2.983751e-04  5.701905e-05
#> direct    5.787999e-06 -2.983751e-04  9.262683e-04  6.278932e-04
#> total    -3.341636e-04  5.701905e-05  6.278932e-04  6.849123e-04

confint

confint(std, level = 0.95)
#>              2.5 %    97.5 %
#> cp       0.1803751 0.3005559
#> b        0.4591996 0.5658582
#> a        0.4432376 0.5451754
#> X~~X     1.0000000 1.0000000
#> Y~~Y     0.5062647 0.6047042
#> M~~M     0.7027838 0.8035405
#> indirect 0.2183313 0.2923565
#> direct   0.1803751 0.3005559
#> total    0.4422243 0.5444044

References

Pesigan, I. J. A., & Cheung, S. F. (2023). 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