MyNixOS website logo
Description

Compare Nested and Non-Nested Structural Equation Models.

A comprehensive package for comparing multiple Structural Equation Models (SEM). Supports both nested and non-nested model comparisons, chi-square difference tests, and extraction of multiple fit indices including AIC (Akaike Information Criterion), BIC (Bayesian Information Criterion), CFI (Comparative Fit Index), TLI (Tucker-Lewis Index), RMSEA (Root Mean Square Error of Approximation), and SRMR (Standardized Root Mean Square Residual). Built on top of the 'lavaan' package for seamless SEM model comparison workflows. The Vuong test (Vuong, 1989) for non-nested models is used as the statistical test.

R-CMD-check License: GPLv3

modelscompete4

Compare Nested and Non‑Nested Structural Equation Models
Built on lavaan – automatic nesting detection, chi‑square difference tests, Vuong tests, and comprehensive fit indices.


Installation

# install.packages("remotes")
remotes::install_github("ssjerf-stack/modelscompete4")

Quick Start

library(modelscompete4)
library(lavaan)

# Example data
data(HolzingerSwineford1939)

# Define models as named list of lavaan syntax strings
model_list <- list(
  "OneFactor" = "g =~ x1 + x2 + x3 + x4 + x5 + x6",
  "TwoFactor" = "
    visual  =~ x1 + x2 + x3
    textual =~ x4 + x5 + x6
  "
)

# Compare them – the function fits the models automatically
result <- compare_models(model_list, data = HolzingerSwineford1939)

# Print summary
print(result)

# Access detailed results
result$fit_table          # fit indices for all models
result$comparison_matrix  # pairwise test results

Features

  • [x] Nested models → chi‑square difference test (lavTestLRT)
  • [x] Non‑nested models → Vuong test (nonnest2::vuongtest)
  • [x] Fit indices: AIC, BIC, CFI, TLI, RMSEA, SRMR, χ², df, p‑value
  • [x] Automatic model naming – use your own names
  • [x] Bootstrap support – standard errors and confidence intervals
  • [x] S3 methodsprint(), summary()

Advanced Example

# Three non‑nested models with different factor structures
models <- list(
  "M1" = "F1 =~ x1 + x2 + x3",
  "M2" = "F1 =~ x1 + x2 + x3 + x4",
  "M3" = "
    F1 =~ x1 + x2 + x3
    F2 =~ x4 + x5 + x6
  "
)

result <- compare_models(models, data = HolzingerSwineford1939)
print(result)

Output Structure

The returned object of class modelscompete4 contains:

ComponentDescription
$fit_listList of fitted lavaan objects
$fit_tableData frame with fit indices for all models
$comparison_matrixMatrix with pairwise test results
$test_resultsDetailed statistical tests (LRT / Vuong)
$bootstrap_summaryBootstrapped estimates (if requested)

License

See https://www.gnu.org/licenses/gpl-3.0 for the full license.

Metadata

Version

0.2.6

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows