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.0298 20000 0.1744 0.2915
#> b        0.5113 0.0300 20000 0.4527 0.5699
#> a        0.4811 0.0287 20000 0.4249 0.5375
#> X~~X     1.0617 0.0498 20000 0.9633 1.1595
#> Y~~Y     0.5533 0.0273 20000 0.5005 0.6070
#> M~~M     0.7568 0.0362 20000 0.6861 0.8292
#> indirect 0.2460 0.0204 20000 0.2075 0.2872
#> direct   0.2328 0.0298 20000 0.1744 0.2915
#> total    0.4788 0.0283 20000 0.4237 0.5348

summary

summary(unstd)
#> Monte Carlo Confidence Intervals (Multiple Imputation Estimates)
#>             est     se     R   2.5%  97.5%
#> cp       0.2328 0.0298 20000 0.1744 0.2915
#> b        0.5113 0.0300 20000 0.4527 0.5699
#> a        0.4811 0.0287 20000 0.4249 0.5375
#> X~~X     1.0617 0.0498 20000 0.9633 1.1595
#> Y~~Y     0.5533 0.0273 20000 0.5005 0.6070
#> M~~M     0.7568 0.0362 20000 0.6861 0.8292
#> indirect 0.2460 0.0204 20000 0.2075 0.2872
#> direct   0.2328 0.0298 20000 0.1744 0.2915
#> total    0.4788 0.0283 20000 0.4237 0.5348

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.872611e-04 -4.825737e-04 -3.824669e-05 -4.321272e-06 -2.555582e-05
#> b        -4.825737e-04  8.984624e-04 -1.424868e-05 -9.094629e-06 -2.138968e-05
#> a        -3.824669e-05 -1.424868e-05  8.245502e-04 -9.762738e-06  2.345948e-05
#> X~~X     -4.321272e-06 -9.094629e-06 -9.762738e-06  2.482004e-03 -3.637155e-05
#> Y~~Y     -2.555582e-05 -2.138968e-05  2.345948e-05 -3.637155e-05  7.461613e-04
#> M~~M     -1.184334e-05  1.451844e-06 -7.325707e-05 -3.164943e-05  1.253165e-06
#> indirect -2.515291e-04  4.250558e-04  4.146088e-04 -9.410465e-06  1.205793e-06
#> direct    8.872611e-04 -4.825737e-04 -3.824669e-05 -4.321272e-06 -2.555582e-05
#> total     6.357320e-04 -5.751788e-05  3.763621e-04 -1.373174e-05 -2.435003e-05
#>                   M~~M      indirect        direct         total
#> cp       -1.184334e-05 -2.515291e-04  8.872611e-04  6.357320e-04
#> b         1.451844e-06  4.250558e-04 -4.825737e-04 -5.751788e-05
#> a        -7.325707e-05  4.146088e-04 -3.824669e-05  3.763621e-04
#> X~~X     -3.164943e-05 -9.410465e-06 -4.321272e-06 -1.373174e-05
#> Y~~Y      1.253165e-06  1.205793e-06 -2.555582e-05 -2.435003e-05
#> M~~M      1.309822e-03 -3.670129e-05 -1.184334e-05 -4.854463e-05
#> indirect -3.670129e-05  4.171909e-04 -2.515291e-04  1.656619e-04
#> direct   -1.184334e-05 -2.515291e-04  8.872611e-04  6.357320e-04
#> total    -4.854463e-05  1.656619e-04  6.357320e-04  8.013939e-04

confint

confint(unstd, level = 0.95)
#>              2.5 %    97.5 %
#> cp       0.1743744 0.2915214
#> b        0.4527060 0.5699042
#> a        0.4248983 0.5375377
#> X~~X     0.9632929 1.1594564
#> Y~~Y     0.5004785 0.6069742
#> M~~M     0.6861364 0.8292369
#> indirect 0.2074642 0.2872096
#> direct   0.1743744 0.2915214
#> total    0.4236592 0.5347576

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.1807 0.2994
#> b        0.5189 0.0272 20000 0.4593 0.5655
#> a        0.5031 0.0261 20000 0.4428 0.5452
#> X~~X     1.0000 0.0000 20000 1.0000 1.0000
#> Y~~Y     0.5429 0.0251 20000 0.5064 0.6057
#> M~~M     0.7469 0.0258 20000 0.7028 0.8039
#> indirect 0.2610 0.0189 20000 0.2179 0.2921
#> direct   0.2450 0.0304 20000 0.1807 0.2994
#> total    0.5060 0.0264 20000 0.4420 0.5446

summary

summary(std)
#> Standardized Monte Carlo Confidence Intervals
#>             est     se     R   2.5%  97.5%
#> cp       0.2450 0.0304 20000 0.1807 0.2994
#> b        0.5189 0.0272 20000 0.4593 0.5655
#> a        0.5031 0.0261 20000 0.4428 0.5452
#> X~~X     1.0000 0.0000 20000 1.0000 1.0000
#> Y~~Y     0.5429 0.0251 20000 0.5064 0.6057
#> M~~M     0.7469 0.0258 20000 0.7028 0.8039
#> indirect 0.2610 0.0189 20000 0.2179 0.2921
#> direct   0.2450 0.0304 20000 0.1807 0.2994
#> total    0.5060 0.0264 20000 0.4420 0.5446

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.215025e-04 -5.956069e-04  4.381277e-06  3.385322e-20 -1.585313e-04
#> b        -5.956069e-04  7.376605e-04 -3.232885e-06 -2.679735e-20 -3.419181e-04
#> a         4.381277e-06 -3.232885e-06  6.814976e-04  5.385400e-21 -1.676857e-04
#> X~~X      3.385322e-20 -2.679735e-20  5.385400e-21  1.188158e-32 -1.088669e-21
#> Y~~Y     -1.585313e-04 -3.419181e-04 -1.676857e-04 -1.088669e-21  6.300103e-04
#> M~~M     -4.427549e-06  3.161828e-06 -6.734774e-04 -6.296948e-21  1.658590e-04
#> indirect -2.928057e-04  3.635322e-04  3.480811e-04 -1.123125e-20 -2.549488e-04
#> direct    9.215025e-04 -5.956069e-04  4.381277e-06  3.385322e-20 -1.585313e-04
#> total     6.286968e-04 -2.320747e-04  3.524624e-04  2.262197e-20 -4.134800e-04
#>                   M~~M      indirect        direct         total
#> cp       -4.427549e-06 -2.928057e-04  9.215025e-04  6.286968e-04
#> b         3.161828e-06  3.635322e-04 -5.956069e-04 -2.320747e-04
#> a        -6.734774e-04  3.480811e-04  4.381277e-06  3.524624e-04
#> X~~X     -6.296948e-21 -1.123125e-20  3.385322e-20  2.262197e-20
#> Y~~Y      1.658590e-04 -2.549488e-04 -1.585313e-04 -4.134800e-04
#> M~~M      6.664645e-04 -3.440059e-04 -4.427549e-06 -3.484334e-04
#> indirect -3.440059e-04  3.590863e-04 -2.928057e-04  6.628063e-05
#> direct   -4.427549e-06 -2.928057e-04  9.215025e-04  6.286968e-04
#> total    -3.484334e-04  6.628063e-05  6.286968e-04  6.949775e-04

confint

confint(std, level = 0.95)
#>              2.5 %    97.5 %
#> cp       0.1807323 0.2993557
#> b        0.4592814 0.5655437
#> a        0.4428161 0.5451581
#> X~~X     1.0000000 1.0000000
#> Y~~Y     0.5063594 0.6056866
#> M~~M     0.7028027 0.8039139
#> indirect 0.2178821 0.2920912
#> direct   0.1807323 0.2993557
#> total    0.4419650 0.5445680

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