cvsem | R Documentation |
Do model comparison on SEM models using cross-validation as described
in \insertCiteCudeck1983cvsem and \insertCiteBrowneCudeck1992cvsem.
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, ... )
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.
()
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.