esem_compare: Compare ESEM Against a Standard CFA

View source: R/compare.R

esem_compareR Documentation

Compare ESEM Against a Standard CFA

Description

Fits a user-specified CFA model on the same data and compares it against an esem_fit object using fit indices and, where applicable, a chi-square difference test (when models are nested).

Usage

esem_compare(esem_model, cfa_model, data = NULL, estimator = NULL, ...)

Arguments

esem_model

An esem_fit object from esem.

cfa_model

A lavaan model string for the comparison CFA. All items must be the same as in the ESEM.

data

A data.frame used to fit the CFA. If NULL (default), the data are re-extracted from the esem_model lavaan object.

estimator

Estimator for the CFA model. Defaults to the same estimator used in esem_model.

...

Additional arguments passed to lavaan::cfa().

Value

A list of class "esem_comparison" with:

fit_table

A data.frame of fit indices for both models.

esem_fit

The original esem_fit object.

cfa_fit

The fitted lavaan CFA object.

lavtest

Output of lavaan::lavTestLRT() if models are nested, else NULL.

See Also

esem

Examples

data("HolzingerSwineford1939", package = "lavaan")
d <- HolzingerSwineford1939[, paste0("x", 1:9)]


# Fit ESEM
esem_result <- esem(d, nfactors = 3)

# Define comparison CFA (no cross-loadings)
cfa_model <- "
  Visual  =~ x1 + x2 + x3
  Textual =~ x4 + x5 + x6
  Speed   =~ x7 + x8 + x9
"
comparison <- esem_compare(esem_result, cfa_model, data = d)
print(comparison)



bifactory documentation built on Oct. 28, 2026, 1:06 a.m.