不知道为什么很难找到有关此主题的信息。
我想简历我的 SEM 模型。N = 360。我已经将 70% 的数据提取到训练集中并构建了模型,首先是在理论上,然后使用修改索引。我还有一个测试数据框,其中有观察值(为了幸福),但我想使用模型来预测值。lavPredict 似乎只用于预测潜在变量的值。也许我遗漏了一些东西,但似乎不像 lmer 或基本线性回归那样简单。是否只使用测试数据集中的模型拟合指数?似乎应该能够比较 SEM 中的观察值和预测值。
我在这里包含了一些数据:https ://drive.google.com/file/d/1AX50DFNik30Qsyiyp6XnPMETNfVXK83r/view?usp=sharing
这是我通过训练数据集获得的最终模型。当我去测试它时,我得到了这个
Error in lavPredict(fit.latent.8, newdata = test) :
inherits(object, "lavaan") is not TRUE
非常感谢!
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)