## Mplus user guide SEM example:
outfile <- tempfile(fileext=".out")
tryres <- try({
download.file("http://www.statmodel.com/usersguide/chap5/ex5.11.html",outfile)
})
if (!is(tryres,"try-error")){
# Plot model:
semPaths(outfile,intercepts=FALSE)
# Obtain latent regressions (mplus)
semMatrixAlgebra(outfile, Beta)
# mplus model implied covariance:
mat1 <- semMatrixAlgebra(outfile,
Lambda %*% Imin(Beta, TRUE) %*% Psi %*% t(Imin(Beta, TRUE)) %*% t(Lambda) + Theta)
# Lisrel model implied covariance:
mat2 <- semMatrixAlgebra(outfile,
LY %*% Imin(BE, TRUE) %*% PS %*% t(Imin(BE, TRUE)) %*% t(LY) + TE, endoOnly = TRUE)
# RAM model implied covariance:
mat3 <- semMatrixAlgebra(outfile,
F %*% Imin(A,TRUE) %*% S %*% t(Imin(A, TRUE)) %*% t(F))
if (FALSE) {
# Plot:
library("qgraph")
pdf("Models.pdf",width=15,height=5)
layout(t(1:3))
qgraph(round(cov2cor(mat1),5), maximum=1, edge.labels=TRUE, layout = "spring",
cut = 0.4, minimum = 0.1)
title("Mplus model")
qgraph(round(cov2cor(mat2),5), maximum=1, edge.labels=TRUE, layout = "spring",
cut = 0.4, minimum = 0.1)
title("LISREL model")
qgraph(round(cov2cor(mat3),5), maximum=1, edge.labels=TRUE, layout = "spring",
cut = 0.4, minimum = 0.1)
title("RAM model")
dev.off()
}
# They are the same.
}
Run the code above in your browser using DataLab