semTests semTests logo

CRAN_Status_Badge R-CMD-check Codecov test coverage Project Status: Active

semTests computes robust p-values for structural equation models fitted with lavaan: tests of overall fit, nested model comparisons, and score and criterion-difference tests of parameter restrictions. It implements penalized eigenvalue block averaging and penalized regression (Foldnes, Moss, and Grønneberg, 2025) and their extension to nested models (Foldnes, Grønneberg, and Moss, 2026). It supports ML, GLS, ULS, categorical DWLS and ULS, and FIML, with one or several groups.

Installation

install.packages("semTests")
# Development version:
# remotes::install_github("JonasMoss/semTests")

Example

library("semTests")
model <- "visual  =~ x1 + x2 + x3
          textual =~ x4 + x5 + x6
          speed   =~ x7 + x8 + x9"
fit <- lavaan::cfa(model, lavaan::HolzingerSwineford1939)
pvalues(fit)
#>    peba4_rls 
#> 5.165712e-07 
#> estimator: ML | data: continuous | information: expected | df: 24

To test a restriction, fit the restricted model and pass it first:

restricted <- "visual  =~ x1 + a*x2 + a*x3
               textual =~ x4 + x5 + x6
               speed   =~ x7 + x8 + x9"
fit0 <- lavaan::cfa(restricted, lavaan::HolzingerSwineford1939)
pvalues_nested(fit0, fit)
#> pall_ug_ml 
#> 0.06061142 
#> estimator: ML | data: continuous | information: expected | df: 1 | nested (method 2000, A.method delta)
semtest(fit0, fit)
#> score test: Common criterion pseudo-target satisfies the restricted model 
#>   type statistic df rank      reference    p_value
#>  score  2.770785  1    1 weighted_chisq 0.06131629
#>                                                     hypothesis
#>  Common criterion pseudo-target satisfies the restricted model

Learn more

?semTests-support lists every supported combination, and citation("semTests") shows how to cite the package. Bugs and ideas go to GitHub issues.