compareFit: Build an object summarizing fit indices across multiple...

View source: R/compareFit.R

compareFitR Documentation

Build an object summarizing fit indices across multiple models

Description

This function will create the template to compare fit indices across multiple fitted lavaan objects. The results can be exported to a clipboard or a file later.

Usage

compareFit(..., nested = TRUE, argsLRT = list(), indices = TRUE,
  moreIndices = FALSE, baseline.model = NULL, nPrior = 1)

Arguments

...

fitted lavaan models or list(s) of lavaan objects. lavaan.mi::lavaan.mi objects are also accepted, but all models must belong to the same class.

nested

logical indicating whether the models in ... are nested. See net() for an empirical test of nesting.

argsLRT

list of arguments to pass to lavaan::lavTestLRT(), as well as to lavaan.mi::lavTestLRT.mi() and lavaan::fitMeasures() when comparing lavaan.mi::lavaan.mi models.

indices

logical indicating whether to return fit indices from the lavaan::fitMeasures() function. Selecting particular indices is controlled in the summary method; see FitDiff.

moreIndices

logical indicating whether to return fit indices from the moreFitIndices() function. Selecting particular indices is controlled in the summary method; see FitDiff.

baseline.model

optional fitted lavaan::lavaan model passed to lavaan::fitMeasures() to calculate incremental fit indices.

nPrior

passed to moreFitIndices(), if relevant

Value

A FitDiff object that saves model fit comparisons across multiple models. If the models are not nested, only fit indices for each model are returned. If the models are nested, the differences in fit indices are additionally returned, as well as test statistics comparing each sequential pair of models (ordered by their degrees of freedom).

Author(s)

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

Sunthud Pornprasertmanit (psunthud@gmail.com)

See Also

FitDiff, clipboard()

Examples


HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9 '

## non-nested models
fit1 <- cfa(HS.model, data = HolzingerSwineford1939)

m2 <- ' f1 =~ x1 + x2 + x3 + x4
        f2 =~ x5 + x6 + x7 + x8 + x9 '
fit2 <- cfa(m2, data = HolzingerSwineford1939)

(out1 <- compareFit(fit1, fit2, nested = FALSE))
summary(out1)


## nested model comparisons: measurement equivalence/invariance
fit.config <- cfa(HS.model, data = HolzingerSwineford1939, group = "school")
fit.metric <- cfa(HS.model, data = HolzingerSwineford1939, group = "school",
                  group.equal = "loadings")
fit.scalar <- cfa(HS.model, data = HolzingerSwineford1939, group = "school",
                  group.equal = c("loadings","intercepts"))
fit.strict <- cfa(HS.model, data = HolzingerSwineford1939, group = "school",
                  group.equal = c("loadings","intercepts","residuals"))

measEqOut <- compareFit(fit.config, fit.metric, fit.scalar, fit.strict,
                        moreIndices = TRUE) # include moreFitIndices()
summary(measEqOut)
summary(measEqOut, fit.measures = "all")
summary(measEqOut, fit.measures = c("aic", "bic", "sic", "ibic"))




semTools documentation built on April 3, 2025, 9:23 p.m.