Structural equation models: audit against lavaan — build 2026-11-28.115

Structural equation models: audit against lavaan — build 2026-11-28.115

Tests → Measurement & SEM fits factor models and paths between factors by maximum likelihood (ml), maximum likelihood with missing values (mlmv, full information) or asymptotic distribution free (adf, weighted least squares). An audit compared it with lavaan 0.7-3 on 15 simulated designs:

  • one-, two- and three-factor CFAs, 150–1,500 rows;
  • mediation chains, two exogenous factors with free or zero covariance, and a marker that is not the first item;
  • a badly fitting model and a Heywood case (N = 40, saturated);
  • missing data (8–12%) and skewed data for ADF.

What matches. For ML and MLMV, everything matched lavaan (information = "observed") to about 10⁻⁵: estimates, standard errors, standardized coefficients (std.all), χ², CFI, TLI, RMSEA, SRMR (without the means) and the log likelihood. In 1,500 simulated samples, the 95% intervals covered the true loading 94.8% of the time and the true path 93.9%. The χ² test rejected a true model 5.9% of the time at n = 300.

Fixed in this build.

  • Saturated models (df = 0).
    • Before: CFI could read 0, when the items were only weakly correlated and χ² was rounding noise rather than exactly 0, and TLI was blank.
    • Now: χ² is 0 and CFI = TLI = 1, as lavaan and Stata report. CFI and TLI also follow lavaan’s rule: a model that fits no worse than its df gets 1.
  • ADF is now lavaan’s estimator = "WLS" (Browne 1984). The covariances use divisor N − 1, the statistic is (N − 1)·F and the standard errors use N − 1. The intercepts are estimated together with the covariances (ν̂ = mean − Γ₃ W (s − σ̂), with standard errors from the full weight matrix of means and covariances); before, they were the sample means. Everything now matches lavaan to about 10⁻⁶, against 0.1% (and about 1% for intercepts with skewed data) before. RMSEA uses N − 1 as lavaan does for WLS.
  • The R code reproduces the page.
    • It now asks for information = "observed"; without it, R’s standard errors differed by 2–6%, and by 25% in a badly fitting model.
    • It prints srmr_bentler_nomean, the SRMR this page reports (lavaan’s default SRMR includes the means).
    • When the marker is not the first item, it writes NA* on the first item. Before, lavaan also fixed the first loading to 1, so R fitted a different model (F1 =~ x1 + 1*x2 + x3 fixes both x1 and x2).
    • The page’s own R code was run in lavaan for ML, MLMV and ADF: estimates agree to 3·10⁻⁶ and SEs to 10⁻⁵.
  • Console.
    • A typed sem (...) is logged once (it echoed the command twice).
    • It prints the full table: Stata’s sem output (structural and measurement coefficients, intercepts, variances with log-scale intervals, covariances, LR test) and estat gof. In the R dialect it prints lavaan’s summary() with Std.all.
  • Interpretation text. It gives CFI with three decimals, as the tile (it said “1.00” for 0.998).

Stata’s documentation could not be checked for ADF details (divisor and intercepts). The page follows lavaan, which is verifiable. tests/sem-text-audit.test.mjs checks ADF against stored lavaan values and the saturated case.