Skip to contents

In this example, we use the semmcci package to generate Monte Carlo confidence intervals from full-information maximum likelihood estimates as described in Pesigan & Cheung (2023). We use data from a study by Elliot and others (2007) on the effects of an intervention on healthy dietary behavior mediated by knowledge of healthy dietary behavior. This data was used as an empirical example in Yuan and MacKinnon (2009) and Wu and Jia (2013).

Data

The data frame elliot2007(), which is included in the manMCMedMiss package, has 354 cases and 3 variables:

  • x - Intervention group membership.
  • m - Knowledge of healthy dietary behavior (knowledge post-intervention minus knowledge pre-intervention).
  • y - Healthy dietary behavior (behavior post-intervention minus behavior pre-intervention).
knitr::kable(head(elliot2007))
x m y
0 1.0 1.666666
0 0.0 4.000000
0 0.0 0.000000
0 -0.5 -0.666667
0 0.5 1.333333
0 1.0 2.333334

Amputation

Generate sample data with missing values. The missing data mechanism is missing at random (MAR). The proportion of missing cases is 0.30.

set.seed(42)
data_missing <- AmputeData(
  elliot2007,
  mech = "MAR",
  prop = 0.10
)
knitr::kable(head(data_missing, n = 10))
x m y
0 1.000000 1.666666
0 0.000000 4.000000
0 0.000000 0.000000
0 -0.500000 -0.666667
0 0.500000 1.333333
0 1.000000 2.333334
NA 1.166667 3.333333
NA 0.833333 NA
0 1.666667 1.666667
0 -0.333333 1.666666

Model Fitting

We fit the model using the argument missing = "fiml" to use full-information maximum likelihood to deal with missing data. Note that we need to define the indirect effect as the product of a and b using the := operator in the model syntax.

library(lavaan)
model <- "
  y ~ x + b * m
  m ~ a * x
  x ~~ x
  indirect := a * b
"
fit <- sem(
  model = model,
  data = data_missing,
  missing = "fiml"
)

Monte Carlo Confidence Intervals

The fitted lavaan model saved in the object fit is passed as the first argument to the semmcci::MC() function to generate Monte Carlo confidence intervals.

library(semmcci)
MC(fit, alpha = 0.05)
#> Monte Carlo Confidence Intervals
#>             est     se     R    2.5%  97.5%
#> y~x      0.1513 0.1267 20000 -0.0983 0.3979
#> b        0.1521 0.0555 20000  0.0422 0.2597
#> a        0.3697 0.1280 20000  0.1205 0.6240
#> x~~x     0.2415 0.0190 20000  0.2042 0.2791
#> y~~y     1.1491 0.0906 20000  0.9732 1.3270
#> m~~m     1.2120 0.0939 20000  1.0277 1.3968
#> y~1      0.3364 0.0773 20000  0.1870 0.4914
#> m~1      0.0068 0.0785 20000 -0.1474 0.1575
#> x~1      0.4119 0.0272 20000  0.3586 0.4652
#> indirect 0.0562 0.0292 20000  0.0092 0.1222

References

Elliot, D. L., Goldberg, L., Kuehl, K. S., Moe, E. L., Breger, R. K., & Pickering, M. A. (2007). The PHLAME (Promoting Healthy Lifestyles: Alternative Models’ Effects) firefighter study: Outcomes of two models of behavior change. Journal of occupational and environmental medicine, 49(2), 204–213. http://doi.org/10.1097/JOM.0b013e3180329a8d

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

Wu, W., & Jia, F. (2013). A new procedure to test mediation with missing data through nonparametric bootstrapping and multiple imputation, Multivariate Behavioral Research, 48(5), 663-691. http://doi.org/10.1080/00273171.2013.816235

Yuan, Y., & MacKinnon, D. P. (2009). Bayesian mediation analysis. Psychological methods, 14(4), 301–322. http://doi.org/10.1037/a0016972