###Lavaan help with predict
data <- data.frame(synchrony = rnorm(70), x1 = rnorm(70), x2 = rnorm(70), x3 = rnorm(70), x4 = rnorm(70), x5 = rnorm(70), x6 = rnorm(70), x7 = rnorm(70), x8 = rnorm(70))
model <- '
synchrony ~ x1 + x2 + x3 + x4 + x5 + x6 + x7
x7 ~ x1 + x2 + x6
x4 ~ x2 + x5
x5 ~ x1
x8 ~ synchrony'
fit.model <- sem(model, data=data, std.ov=F, fixed.x=F)
summary(fit.model, standardized=T, rsq=T, fit.measures=T, modindices=T)
###Can I use lavPredict to get predicted values for synchrony?
predict.model <- lavPredict(fit.model, type="ov", label=T, se.fit=T)
Can I acquire partial correlations in lavaan?
A + B ~ X + Y + ZA ~~ B
Can I use lavPredict to get predicted values for synchrony?
(PT <- parTable(fit.model))(Beta <- PT$est[PT$lhs == "synchrony" & PT$op == "~"])(xNames <- PT$rhs[PT$lhs == "synchrony" & PT$op == "~"])data$pred.sync <- as.matrix(data[xNames]) %*% Beta # predicted valuesdata$resid.sync <- data$synchrony - data$pred.sync # residuals
Thank you very much for the help. This seemed to work.
Beta <- PT$est[PT$lhs == "synchrony" & PT$op == "~"]
Beta <- c(PT$est[PT$lhs == "synchrony" & PT$op == "~1"], Beta)data$pred.sync <- cbind(1, as.matrix(data[xNames])) %*% Beta # predicted values