lav_mice | R Documentation |
Fits a SEM model to each dataset in a mids
object without pooling the results.
This function is an extension for the lavaan::sem()
function to handle mice::mids objects from the mice package.
It allows for both a SEM model syntax as a character string or a pre-fitted lavaan model object.
lav_mice(model, mids, ...)
model |
Either a character string representing the SEM model to be fitted or a pre-fitted lavaan model object. |
mids |
A |
... |
Additional arguments to be passed to |
A list of lavaan model fits, one for each imputed dataset.
Davood Tofighi dtofighi@gmail.com
## Not run:
# library(mice)
# library(lavaan)
# Load Holzinger and Swineford (1939) dataset
data("HolzingerSwineford1939", package = "lavaan")
# Introduce missing data
df_complete <- na.omit(HolzingerSwineford1939)
amp <- mice::ampute(df_complete, prop = 0.2, mech = "MAR")
data_with_missing <- amp$amp
# Perform multiple imputation
imputed_data <- mice::mice(data_with_missing, m = 3, maxit = 5, seed = 12345, printFlag = FALSE)
# fit the Holzinger and Swineford (1939) example model
HS_model <- " visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 "
# Fit the SEM model without running
fit_HS <- lavaan::sem(HS_model, data = data_with_missing, do.fit = FALSE)
# Fit the SEM model without pooling to each imputed dataset
fit_list1 <- lav_mice(HS_model, imputed_data)
# 'fit_list1' now contains a list of lavaan objects, one for each imputed dataset
# Fit the SEM model without pooling to each imputed dataset using a pre-fitted model object
fit_list2 <- lav_mice(fit_HS, imputed_data)
# 'fit_list2' now contains a list of lavaan objects, one for each imputed dataset
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.