cvsem {cvsem}R Documentation

Cross-Validation of Structural Equation Models

Description

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.

Usage

cvsem(
  data = NULL,
  Models,
  discrepancyMetric = "KL-Divergence",
  k = 5,
  lavaanFunction = "sem",
  echo = TRUE,
  ...
)

Arguments

data

Data

Models

A collection of models, specified in lavaan syntax. Provide Models with the cvgather() function.

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 TRUE. Set to FALSE to suppress.

...

Not used

Value

A list with the prediction error for each model.

References

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.()

Examples


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")


[Package cvsem version 1.0.0 Index]