multilevel.fit: Simultaneous and Level-Specific Multilevel Model Fit...

View source: R/multilevel.fit.R

multilevel.fitR Documentation

Simultaneous and Level-Specific Multilevel Model Fit Information

Description

This function provides simultaneous and level-specific model fit information using the partially saturated model method for multilevel models estimated with the lavaan package. Note that level-specific fit indices cannot be computed when the fitted model contains cross-level constraints, e.g., equal factor loadings across levels in line with the metric cross-level measurement invariance assumption.

Usage

multilevel.fit(model, print = c("all", "summary", "fit"), digits = 3, p.digits = 3,
               write = NULL, append = TRUE, check = TRUE, output = TRUE)

Arguments

model

a fitted multilevel model of class "lavaan" from the lavaan package.

print

a character string or character vector indicating which results to show on the console, i.e. "all" for all results, "summary" for a summary of the specification of the estimation method and missing data handling in lavaan and "fit" for model fit. By default, the function only prints simultaneous and level-specific multilevel model fit information.

digits

an integer value indicating the number of decimal places to be used for displaying results. Note that loglikelihood, information criteria and chi-square test statistic is printed with digits minus 1 decimal places.

p.digits

an integer value indicating the number of decimal places to be used for displaying the p-value.

write

a character string naming a file for writing the output into either a text file with file extension ".txt" (e.g., "Output.txt") or Excel file with file extension ".xlsx" (e.g., "Output.xlsx"). If the file name does not contain any file extension, an Excel file will be written.

append

logical: if TRUE (default), output will be appended to an existing text file with extension .txt specified in write, if FALSE existing text file will be overwritten.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown.

Value

Returns an object of class misty.object, which is a list with following entries:

call

function call

type

type of analysis

args

specification of function arguments

model.fit

a fitted model of class "lavaan"

result

list with result tables, i.e., summary for the summary of the specification of the estimation method and missing data handling in lavaan and fit for the model fit information.

Note

The function uses the functions fitmeasures, lavInspect, lavTech, and parTable provided in the R package lavaan by Yves Rosseel (2012).

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Rosseel, Y. (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48, 1-36. https://doi.org/10.18637/jss.v048.i02

See Also

multilevel.cfa, multilevel.invar, multilevel.omega, multilevel.cor, multilevel.descript

Examples

## Not run: 

# Load data set "Demo.twolevel" in the lavaan package
data("Demo.twolevel", package = "lavaan")

#————————————————————————————————————————————————————————————————————————————
# Model Specification and Model Estimation

# Load lavaan package
library(lavaan)

# Model specification
model <- 'level: 1
              fw =~ y1 + y2 + y3
              fw ~ x1 + x2 + x3
           level: 2
              fb =~ y1 + y2 + y3
              fb ~ w1 + w2'

# Model estimation with estimator = "ML"
fit1 <- sem(model = model, data = Demo.twolevel, cluster = "cluster", estimator = "ML")

# Model estimation with estimator = "MLR"
fit2 <- sem(model = model, data = Demo.twolevel, cluster = "cluster", estimator = "MLR")

#————————————————————————————————————————————————————————————————————————————
# Simultaneous and Level-Specific Multilevel Model Fit Information

# Example 1a: Standard fit indices
multilevel.fit(fit1)

# Example 1b: Standard, scaled, and robust fit indices
multilevel.fit(fit2)

#————————————————————————————————————————————————————————————————————————————
# Write Results

# Example 2a: Write results into a text file
multilevel.fit(fit1, write = "LS-Fit1.txt")

# Example 2b: Write results into an Excel file
multilevel.fit(fit2, write = "LS-Fit2.xlsx")

## End(Not run)

misty documentation built on Aug. 2, 2026, 9:06 a.m.

Related to multilevel.fit in misty...