Example 4.2: The Simple Mediation Model with Missing Data (MI)
Ivan Jacob Agaloos Pesigan
2024-10-22
Source:vignettes/example-4-2-simple-miss-mi.Rmd
example-4-2-simple-miss-mi.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
with multiply imputed data sets.
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
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 do not need to deal with missing values in this
stage.
fit <- sem(data = df, model = model)
Monte Carlo Confidence Intervals
The fit
lavaan
object and mi
mids
object can then be passed to the MCMI()
function from semmcci
to generate Monte Carlo confidence
intervals using multiple imputation as described in Pesigan and Cheung
(2023).
MCMI(fit, mi = mi, R = 20000L, alpha = 0.05, seed = 42)
#> Monte Carlo Confidence Intervals (Multiple Imputation Estimates)
#> est se R 2.5% 97.5%
#> cp 0.2328 0.0299 20000 0.1741 0.2917
#> b 0.5113 0.0301 20000 0.4529 0.5701
#> a 0.4811 0.0287 20000 0.4241 0.5374
#> X~~X 1.0617 0.0495 20000 0.9650 1.1591
#> Y~~Y 0.5533 0.0272 20000 0.5005 0.6069
#> M~~M 0.7568 0.0361 20000 0.6856 0.8278
#> indirect 0.2460 0.0204 20000 0.2070 0.2864
#> direct 0.2328 0.0299 20000 0.1741 0.2917
#> total 0.4788 0.0285 20000 0.4236 0.5349
Standardized Monte Carlo Confidence Intervals
Standardized Monte Carlo Confidence intervals can be generated by
passing the result of the MCMI()
function to the
MCStd()
function.
fit <- sem(data = df, model = model)
unstd <- MCMI(fit, mi = mi, R = 20000L, alpha = 0.05, seed = 42)
MCStd(unstd, alpha = 0.05)
#> Standardized Monte Carlo Confidence Intervals
#> est se R 2.5% 97.5%
#> cp 0.2450 0.0307 20000 0.1802 0.3000
#> b 0.5189 0.0277 20000 0.4587 0.5663
#> a 0.5031 0.0260 20000 0.4429 0.5454
#> X~~X 1.0000 0.0000 20000 1.0000 1.0000
#> Y~~Y 0.5429 0.0250 20000 0.5071 0.6053
#> M~~M 0.7469 0.0258 20000 0.7026 0.8038
#> indirect 0.2610 0.0190 20000 0.2168 0.2915
#> direct 0.2450 0.0307 20000 0.1802 0.3000
#> total 0.5060 0.0261 20000 0.4416 0.5444