Example 4.1: The Simple Mediation Model with Missing Data (FIML)
Ivan Jacob Agaloos Pesigan
2024-10-22
Source:vignettes/example-4-1-simple-miss-fiml.Rmd
example-4-1-simple-miss-fiml.Rmd
In this example, the Monte Carlo method is used to generate
confidence intervals for the indirect effect in a simple mediation model
with missing data where variable X
has an effect on
variable Y
, through a mediating variable
M
.
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
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 <- "
Y ~ cp * X + b * M
M ~ a * X
X ~~ X
indirect := a * b
direct := cp
total := cp + (a * b)
"
Model Fitting
We can now fit the model using the sem()
function from
lavaan
. We are using missing = "fiml"
to
handle missing data in lavaan
.
fit <- sem(data = df, model = model, missing = "fiml")
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%
#> cp 0.2335 0.0293 20000 0.1769 0.2912
#> b 0.5113 0.0297 20000 0.4528 0.5699
#> a 0.4809 0.0286 20000 0.4254 0.5364
#> X~~X 1.0591 0.0499 20000 0.9619 1.1570
#> Y~~Y 0.5542 0.0268 20000 0.5014 0.6060
#> M~~M 0.7564 0.0361 20000 0.6861 0.8267
#> Y~1 -0.0127 0.0253 20000 -0.0619 0.0376
#> M~1 -0.0223 0.0292 20000 -0.0802 0.0341
#> X~1 0.0025 0.0338 20000 -0.0644 0.0692
#> indirect 0.2458 0.0203 20000 0.2076 0.2871
#> direct 0.2335 0.0293 20000 0.1769 0.2912
#> total 0.4794 0.0286 20000 0.4239 0.5359
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.
MCStd(unstd, alpha = 0.05)
#> Standardized Monte Carlo Confidence Intervals
#> est se R 2.5% 97.5%
#> cp 0.2409 0.0299 20000 0.1820 0.2989
#> b 0.5128 0.0268 20000 0.4589 0.5642
#> a 0.4946 0.0256 20000 0.4433 0.5436
#> X~~X 1.0000 0.0000 20000 1.0000 1.0000
#> Y~~Y 0.5568 0.0249 20000 0.5079 0.6054
#> M~~M 0.7554 0.0252 20000 0.7045 0.8035
#> indirect -0.0128 0.0187 20000 0.2173 0.2900
#> direct -0.0222 0.0299 20000 0.1820 0.2989
#> total 0.0024 0.0258 20000 0.4423 0.5440