data(demoOneFactor)
manifests <- names(demoOneFactor)
latents <- c("G1")
model1 <- mxModel(model="One Factor", type="RAM",
manifestVars = manifests,
latentVars = latents,
mxPath(from = latents, to=manifests),
mxPath(from = manifests, arrows = 2),
mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),
mxData(cov(demoOneFactor), type = "cov", numObs = 500)
)
fit1 <- mxRun(model1)
latents <- c("G1", "G2")
model2 <- mxModel(model="Two Factor", type="RAM",
manifestVars = manifests,
latentVars = latents,
mxPath(from = latents[1], to=manifests[1:3]),
mxPath(from = latents[2], to=manifests[4:5]),
mxPath(from = manifests, arrows = 2),
mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0),
mxData(cov(demoOneFactor), type = "cov", numObs=500)
)
fit2 <- mxRun(model2)
mxCompare(fit1, fit2)
# vary precision of the output
oldPrecision = as.numeric(options('digits'))
options('digits' = 1)
mxCompare(fit1, fit2)
options('digits' = oldPrecision)
Run the code above in your browser using DataLab