Title: | SEM Model Comparison with K-Fold Cross-Validation |
---|---|
Description: | The goal of 'cvsem' is to provide functions that allow for comparing Structural Equation Models (SEM) using cross-validation. Users can specify multiple SEMs using 'lavaan' syntax. 'cvsem' computes the Kullback Leibler (KL) Divergence between 1) the model implied covariance matrix estimated from the training data and 2) the sample covariance matrix estimated from the test data described in Cudeck, Robert & Browne (1983) <doi:10.18637/jss.v048.i02>. The KL Divergence is computed for each of the specified SEMs allowing for the models to be compared based on their prediction errors. |
Authors: | Anna Wysocki [aut, cre], Danielle Siegel [aut], Cameron allen [aut], Philippe Rast [aut] |
Maintainer: | Anna Wysocki <[email protected]> |
License: | GPL (>=3) |
Version: | 1.0.0 |
Built: | 2024-11-10 04:44:55 UTC |
Source: | https://github.com/annawysocki/cvsem |
Do model comparison on SEM models using cross-validation as described
in (Cudeck and Browne 1983) and (Browne and Cudeck 1992).
Cross-validation is based on the discrepancy between the sample covariance matrix and
the model implied matrix. Currently, cvsem
supports 'KL-Divergence', Frobenius Distance
and Generalized Least Squares 'GLS' as discrepancy metrics.
cvsem( data = NULL, Models, discrepancyMetric = "KL-Divergence", k = 5, lavaanFunction = "sem", echo = TRUE, ... )
cvsem( data = NULL, Models, discrepancyMetric = "KL-Divergence", k = 5, lavaanFunction = "sem", echo = TRUE, ... )
data |
Data |
Models |
A collection of models, specified in lavaan syntax. Provide Models with the |
discrepancyMetric |
Specify which discrepancy metric to use (one of 'KL-Divergence', 'FD', 'GLS'). Default is KL Divergence. |
k |
The number of folds. Default is 5. |
lavaanFunction |
Specify which lavaan function to use. Default is "sem". Other options are "lavaan" and "cfa" |
echo |
Provide feedback on progress to user, defaults to |
... |
Not used |
A list with the prediction error for each model.
Browne MW, Cudeck R (1992).
“Alternative Ways of Assessing Model Fit.”
Sociological Methods & Research, 21, 230–258.
Cudeck R, Browne MW (1983).
“Cross-Validation Of Covariance Structures.”
Multivariate Behavioral Research, 18, 147–167.
doi:10.1207/s15327906mbr1802_2, https://www.tandfonline.com/doi/abs/10.1207/s15327906mbr1802_2.()
example_data <- lavaan::HolzingerSwineford1939 colnames(example_data) <- c("id", "sex", "ageyr", "agemo", 'school', "grade", "visualPerception", "cubes", "lozenges", "comprehension", "sentenceCompletion", "wordMeaning", "speededAddition", "speededCounting", "speededDiscrimination") model1 <- 'comprehension ~ meaning ## Add some latent variables: meaning =~ wordMeaning + sentenceCompletion speed =~ speededAddition + speededDiscrimination + speededCounting speed ~~ meaning' model2 <- 'comprehension ~ wordMeaning + speededAddition' model3 <- 'comprehension ~ wordMeaning + speededAddition' models <- cvgather(model1, model2, model3) fit <- cvsem( data = example_data, Models = models, k = 10, discrepancyMetric = "KL-Divergence")
example_data <- lavaan::HolzingerSwineford1939 colnames(example_data) <- c("id", "sex", "ageyr", "agemo", 'school', "grade", "visualPerception", "cubes", "lozenges", "comprehension", "sentenceCompletion", "wordMeaning", "speededAddition", "speededCounting", "speededDiscrimination") model1 <- 'comprehension ~ meaning ## Add some latent variables: meaning =~ wordMeaning + sentenceCompletion speed =~ speededAddition + speededDiscrimination + speededCounting speed ~~ meaning' model2 <- 'comprehension ~ wordMeaning + speededAddition' model3 <- 'comprehension ~ wordMeaning + speededAddition' models <- cvgather(model1, model2, model3) fit <- cvsem( data = example_data, Models = models, k = 10, discrepancyMetric = "KL-Divergence")