Type: | Package |
Title: | Goodness-of-Fit Testing for Structural Equation Models |
Description: | Supports eigenvalue block-averaging p-values (Foldnes, Grønneberg, 2018) <doi:10.1080/10705511.2017.1373021>, penalized eigenvalue block-averaging p-values (Foldnes, Moss, Grønneberg, 2024) <doi:10.1080/10705511.2024.2372028>, penalized regression p-values (Foldnes, Moss, Grønneberg, 2024) <doi:10.1080/10705511.2024.2372028>, as well as traditional p-values such as Satorra-Bentler. All p-values can be calculated using unbiased or biased gamma estimates (Du, Bentler, 2022) <doi:10.1080/10705511.2022.2063870> and two choices of chi square statistics. |
Version: | 0.7.1 |
License: | GPL (≥ 3) |
Encoding: | UTF-8 |
URL: | https://github.com/JonasMoss/semTests |
Depends: | R (≥ 3.5.0) |
Imports: | lavaan (≥ 0.6-16), CompQuadForm, RSpectra, MASS, Matrix, methods |
Suggests: | covr, testthat (≥ 3.0.0), psych |
Config/testthat/edition: | 3 |
RoxygenNote: | 7.3.3 |
NeedsCompilation: | no |
Packaged: | 2025-10-06 11:58:43 UTC; A2010578 |
Author: | Jonas Moss |
Maintainer: | Jonas Moss <jonas.moss.statistics@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-10-09 12:00:02 UTC |
Common default value of 2.
Description
Common default value of 2.
Usage
default(x)
Calculate the jth eba pvalue.
Description
Calculate the jth eba pvalue.
Usage
eba_pvalue(chisq, lambdas, j)
Get gamma from a model.
Description
Get gamma from a model.
Usage
gamma(m1, unbiased = 1, m0 = NULL)
Arguments
m1 |
Model to extract gamma from. |
unbiased |
Biased (1), unbiased (2), or both (3). |
m0 |
Optional second model, used if |
Value
List of (un)biased gammas.
Calculate unbiased gamma from gamma and object.
Description
Calculate unbiased gamma from gamma and object.
Usage
gamma_to_gamma_unbiased(gammas, object)
Arguments
gammas |
List of gammas for each group. |
object |
|
Value
List of unbiased gammas.
Calculate the scaled and shifted / the mean-variance adjusted p-value
Description
Calculate the scaled and shifted / the mean-variance adjusted p-value
Usage
scaled_and_shifted(chisq, lambdas)
Arguments
chisq |
Chi-square fit value from a lavaan object. |
lambdas |
Eigenvalues of UG matrix. |
Value
The scaled and shifted p-value or the mean-variance adjusted p-value.
Calculate nested ugamma.
Description
This can also be used with restrictions.
Usage
lav_ugamma_nested_2000(m0, m1, gamma, a = NULL, method = "delta")
Arguments
m0 , m1 |
Two nested |
gamma |
Gamma weighted by groups. |
a |
The |
method |
Method passed to |
Value
Ugamma for nested object.
Returns if not NA; else converts NA to NULL.
Description
Returns if not NA; else converts NA to NULL.
Usage
nanull(x)
Calculate the jth pall pvalue.
Description
Calculate the jth pall pvalue.
Usage
pall(chisq, lambdas)
Calculate the jth eba pvalue.
Description
Calculate the jth eba pvalue.
Usage
peba_pvalue(chisq, lambdas, j)
Calculate penalized OLS pvalue.
Description
Calculate penalized OLS pvalue.
Usage
pols_pvalue(chisq, lambdas, gamma)
Calculate the jth all pvalue.
Description
Calculate the jth all pvalue.
Usage
pvalue_all(chisq, lambdas)
P value function for one and two arguments.
Description
P value function for one and two arguments.
Usage
pvalues_(
m0,
m1,
unbiased,
trad,
eba,
peba,
pols,
chisq = c("ml", "rls"),
extras = FALSE,
method
)
Value
pvalues.
Calculate p-values for one or two lavaan
objects.
Description
Calculate p-values for a lavaan
object using several methods,
including penalized eigenvalue block-averaging and penalized regression
estimators. The recommended choices of p-values are included as default
values. Multiple p-values can be returned simultaneously.
Usage
pvalues(object, tests = c("pEBA4_RLS"))
pvalues_nested(m0, m1, method = c("2000", "2001"), tests = c("PALL_UG_ML"))
Arguments
object , m0 , m1 |
One or two |
tests |
A list of tests to evaluate on the
form |
method |
For nested models, choose between |
Details
The test argument is a list of character strings on the form
(test)(ug?)(ml?), for instance, SB_UG_RLS
.
The first part of the string specifies the desired test. The supported tests are listed below.
If
UG
is included in the string the unbiased estimator of the fourth order moment matrix (Du, Bentler, 2022) is used. If not, the standard biased matrix is used. There is no simple relationship between p-value performance and the choice ofunbiased
.The final part of specifies the chi square statistic. The
ML
choice uses the chi square based on the normal discrepancy function (Bollen, 2014). TheRLS
choice (default) uses the reweighted least squares statistic of Browne (1974).
The eba
method partitions the eigenvalues into j
equally sized sets
(if not possible, the smallest set is incomplete), and takes the mean
eigenvalue of these sets. Provide a list of integers j
to partition
with respect to. The method was proposed by Foldnes & Grønneberg (2018).
eba
with j=2
– j=4
appear to work best.
The peba
method is a penalized variant of eba
, described in
(Foldnes, Moss, Grønneberg, 2024). It typically outperforms eba
, and
the best choice of j
are typically about 2
–6
.
pols
is a penalized regression method with a penalization term from ranging
from 0 to infinity. Foldnes, Moss, Grønneberg (2024) studied pols=2
, which
has good performance in a variety of contexts.
pall
uses all eigenvalues in ugamma, but penalizes them.
This is the recommended option for nested models. all
uses all eigenvalues.
In addition, you may specify a
-
std
the standard p-value where the choice ofchisq
is approximated by a chi square distribution. -
sb
Satorra-Bentler p-value. The p-value proposed by Satorra and Bentler (1994). -
ss
The scaled and shifted p-value proposed by Asparouhov & Muthén (2010). -
sf
The scaled F p-value proposed by Wu and Lin (2016).
The unbiased
argument is TRUE
if the the unbiased estimator of the
fourth order moment matrix (Du, Bentler, 2022) is used. If FALSE
, the
standard biased matrix is used. There is no simple relationship between
p-value performance and the choice of unbiased
.
The chisq
argument controls which basic test statistic is used. The ml
choice uses the chi square based on the normal discrepancy function (Bollen, 2014).
The rls
choice uses the reweighted least squares statistic of Browne (1974).
Value
A named vector of p-values.
References
Foldnes, N., Moss, J., & Grønneberg, S. (2024). Improved goodness of fit procedures for structural equation models. Structural Equation Modeling: A Multidisciplinary Journal, 1-13. https://doi.org/10.1080/10705511.2024.2372028
Satorra, A., & Bentler, P. M. (1994). Corrections to test statistics and standard errors in covariance structure analysis. https://psycnet.apa.org/record/1996-97111-016
Asparouhov, & Muthén. (2010). Simple second order chi-square correction. Mplus Technical Appendix. https://www.statmodel.com/download/WLSMV_new_chi21.pdf
Wu, H., & Lin, J. (2016). A Scaled F Distribution as an Approximation to the Distribution of Test Statistics in Covariance Structure Analysis. Structural Equation Modeling. https://doi.org/10.1080/10705511.2015.1057733
Foldnes, N., & Grønneberg, S. (2018). Approximating Test Statistics Using Eigenvalue Block Averaging. Structural Equation Modeling, 25(1), 101-114. https://doi.org/10.1080/10705511.2017.1373021
Du, H., & Bentler, P. M. (2022). 40-Year Old Unbiased Distribution Free Estimator Reliably Improves SEM Statistics for Nonnormal Data. Structural Equation Modeling: A Multidisciplinary Journal, 29(6), 872-887. https://doi.org/10.1080/10705511.2022.2063870
Bollen, K. A. (2014). Structural Equations with Latent Variables (Vol. 210). John Wiley & Sons. https://doi.org/10.1002/9781118619179
Browne. (1974). Generalized least squares estimators in the analysis of covariance structures. South African Statistical Journal. https://doi.org/10.10520/aja0038271x_175
Examples
library("semTests")
library("lavaan")
model <- "A =~ A1+A2+A3+A4+A5;
C =~ C1+C2+C3+C4+C5"
n <- 200
object <- sem(model, psych::bfi[1:n, 1:10], estimator = "MLM")
pvalues(object)
# For the pEBA6 method with biased gamma and ML chisq statistic:
pvalues(object, "pEBA6_ML")
Calculate the scaled_f p-value.
Description
Calculate the scaled_f p-value.
Usage
scaled_f(chisq, eig)
Arguments
chisq |
Chi-square fit value from a lavaan object. |
eig |
eig of UG matrix. |
Value
scaled f p-value.
Create sparse matrix
Description
Create sparse matrix
Usage
sparsify(mat, lim = 1e-09)
Arguments
mat |
Matrix input. |
lim |
Elements with absolute value less than |
Value
Object of dgCMatrix
.
Split string into options.
Description
Split string into options.
Usage
split_input(string)
Arguments
string |
Input string |
Calculate traditional pvalues.
Description
Calculate traditional pvalues.
Usage
trad_pvalue(
df,
chisq,
lambdas,
type = c("std", "sf", "ss", "sb", "pall", "all")
)
Arguments
df , chisq , lambdas , type |
Parameters needed to calculate the p-values. |
Value
Traditional p-values.
Calculate non-nested gamma
Description
Calculate non-nested gamma
Usage
ugamma(object, unbiased = 1)
Calculate nested gamma
Description
Calculate nested gamma
Usage
ugamma_nested(m0, m1, method = c("2000", "2001"), unbiased = 1)