lavaan.mi: Fit a lavaan Model to Multiple Imputed Data Sets

View source: R/lavaan.mi.R

lavaan.miR Documentation

Fit a lavaan Model to Multiple Imputed Data Sets

Description

This function fits a lavaan model to a list of imputed data sets.

Usage

lavaan.mi(model, data, ...)

cfa.mi(model, data, ...)

sem.mi(model, data, ...)

growth.mi(model, data, ...)

Arguments

model

The analysis model can be specified using lavaan lavaan::model.syntax() or a parameter table (as generated by lavaan::lavaanify() or returned by lavaan::parTable()).

data

A a list of imputed data sets, or an object class from which imputed data can be extracted. Recognized classes are lavaan.mi (stored in the ⁠@DataList⁠ slot), amelia (created by the Amelia package), or mids (created by the mice package).

...

additional arguments to pass to lavaan::lavaan() or lavaan::lavaanList(). See also lavaan::lavOptions(). Note that lavaanList provides parallel computing options, as well as a ⁠FUN=⁠ argument so the user can extract custom output after the model is fitted to each imputed data set (see Examples). TIP: If a custom FUN is used and parallel = "snow" is requested, the user-supplied function should explicitly call library or use :: for any functions not part of the base distribution.

Value

A lavaan.mi object

Note

This functionality was originally provided via runMI() in the semTools package, but there are differences. See the README file on the GitHub page for this package (find link in DESCRIPTION).

Author(s)

Terrence D. Jorgensen (University of Amsterdam; TJorgensen314@gmail.com)

References

Enders, C. K. (2010). Applied missing data analysis. New York, NY: Guilford.

Rubin, D. B. (1987). Multiple imputation for nonresponse in surveys. New York, NY: Wiley. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1002/9780470316696")}

See Also

poolSat() for a more efficient method to obtain SEM results for multiple imputations

Examples

data(HS20imps) # import a list of 20 imputed data sets

## specify CFA model from lavaan's ?cfa help page
HS.model <- '
  visual  =~ x1 + x2 + x3
  textual =~ x4 + x5 + x6
  speed   =~ x7 + x8 + x9
'

## fit model to imputed data sets
fit <- cfa.mi(HS.model, data = HS20imps)


summary(fit, fit.measures = TRUE, fmi = TRUE)
summary(fit, standardized = "std.all", rsquare = TRUE)


## You can pass other lavaanList() arguments, such as FUN=, which allows
## you to save any custom output from each imputation's fitted model.

## An example with ordered-categorical data:
data(binHS5imps) # import a list of 5 imputed data sets

## Define a function to save a list with 2 custom outputs per imputation:
##  - zero-cell tables
##  - the obsolete "WRMR" fit index
myCustomFunc <- function(object) {
  list(wrmr      = lavaan::fitMeasures(object, "wrmr"),
       zeroCells = lavaan::lavInspect(object, "zero.cell.tables"))
}
## fit the model
catout <- cfa.mi(HS.model, data = binHS5imps, ordered = TRUE,
                 FUN = myCustomFunc)
## pooled results

summary(catout)


## extract custom output (per imputation)
sapply(catout@funList, function(x) x$wrmr) # WRMR for each imputation
catout@funList[[1]]$zeroCells # zero-cell tables for first imputation
catout@funList[[2]]$zeroCells # zero-cell tables for second imputation ...



lavaan.mi documentation built on April 3, 2025, 9:36 p.m.