3

Not sure why it is difficult to find info on this topic.

I want to CV my SEM model. N = 360. I've pulled 70% of data into a train set and have built the model, first on theory then using modification indices. I also have a test data frame where I have the observed values (for well-being), but I want to use the model to predict the values. lavPredict only seems to be used to predict values of latent variables. Perhaps I'm missing something, but doesn't seem so straightforward as in lmer or basic linear regression. Does one just use the model fit indices from the test dataset? Seems like one should be able to compare observed and predicted values in SEM.

I've included some data here: https://drive.google.com/file/d/1AX50DFNik30Qsyiyp6XnPMETNfVXK83r/view?usp=sharing

Here is the final model I have through the train dataset. When I go to test it, I just get this

    Error in lavPredict(fit.latent.8, newdata = test) : 
    inherits(object, "lavaan") is not TRUE

Thanks much!

fit.latent.8 <- '#factor loadings; measurement model portion
pl =~ exercisescore + mindfulnessscore + promistscore
sl =~ family_support + friendshipcount + friendshipnet + sense_of_community
trauma =~ neglectscore + abusescore + exposure + family_support + age + sesscore

#regressions: structural model
  wellbeing ~ age + gender + ethnicity + sesscore + resiliencescore + pl + emotionalsupportscore + trauma
  resiliencescore ~ age + sesscore + emotionalsupportscore + pl
  emotionalsupportscore ~ sl + gender
  
#Covariances
friendshipnet~~age
friendshipnet ~~ abusescore
'

train.1 <- sem(fit.latent.8, data = train, meanstructure = TRUE, std.lv = TRUE)
summary(train.1, fit.measures = TRUE,standardized = TRUE, rsquare = TRUE, estimates = FALSE)
modindices(train.1, sort. = TRUE, minimum.value = 10)

test.1 <- sem(fit.latent.8, data = test, meanstructure = TRUE, std.lv = TRUE)
summary(test.1, fit.measures = TRUE,standardized = TRUE, rsquare = TRUE, estimates = FALSE)

John Conde
  • 217,595
  • 99
  • 455
  • 496
James
  • 459
  • 2
  • 14
  • this got me curious and I stumbled upon a discussion on [lavaan google groups forum](https://groups.google.com/g/lavaan/c/5WDS0gHE3qU) – Tom Dec 29 '20 at 06:05

0 Answers0