compare_models: Compare Multiple Nested or Non-Nested Structural Equation...

View source: R/compare_models.R

compare_modelsR Documentation

Compare Multiple Nested or Non-Nested Structural Equation Models

Description

This is the core function of the modelscompete4 package. It automatically fits a list of SEM models, determines their nesting relationship, and performs the appropriate statistical comparison (chi-square difference test for nested models, Vuong test for non-nested models).

Usage

compare_models(
  model_list,
  data,
  estimator = "ML",
  se = "standard",
  bootstrap = 1000,
  parallel = "no",
  verbose = TRUE,
  ...
)

Arguments

model_list

A named list. Each element is a character string specifying the model syntax in lavaan format.

data

A data.frame containing the observed variables used in the models.

estimator

The estimator to be used (e.g., "ML"). Passed to sem.

se

Type of standard errors. Default is "standard". Use "bootstrap" for bootstrapped standard errors and confidence intervals.

bootstrap

Number of bootstrap draws if se="bootstrap". Default is 1000.

parallel

Method for parallel processing for bootstrapping ("multicore", "snow", or "no"). Recommended for large samples.

verbose

Logical; if TRUE, progress messages are printed.

...

Additional arguments passed to sem.

Value

An object of class modelscompete4. This is a list containing:

  • fit_list: The list of fitted lavaan objects.

  • fit_table: A data.frame of key fit indices for all models.

  • comparison_matrix: A matrix showing pairwise nesting relationships and test results.

  • test_results: Detailed results of the statistical tests performed.

  • bootstrap_summary: Summary of bootstrapped results if requested.


modelscompete4 documentation built on April 25, 2026, 1:07 a.m.