
mxModel
,
all in one line of script.
You can add paths, or other model elements, set paths or drop them.
As an example, this one-liner drops a path labelled "Cs", and returns the updated model:
umxModify(lastFit, update = NULL, regex = FALSE, free = FALSE, value = 0, freeToStart = NA, name = NULL, verbose = FALSE, intervals = FALSE, comparison = FALSE, dropList = "deprecated")
mxModel
you wish to update and run.mxRun
)mxModel
fit2 = umxModify(fit1, update = "Cs", name = "newModelName", comparison = TRUE)
Regular expressions are a powerful feature: they let you drop collections of paths by matching patterns fit2 = umxModify(fit1, regex = "C[sr]", name = "drop_Cs_andCr", comparison = TRUE)
If you are just starting out, you might find it easier to be more explicit. Like this:
fit2 = omxSetParameters(fit1, labels = "Cs", values = 0, free = FALSE, name = "newModelName") fit2 = mxRun(fit2) summary(fit2)
require(umx)
data(demoOneFactor)
latents = c("G")
manifests = names(demoOneFactor)
m1 <- mxModel("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)
)
m1 = umxRun(m1, setLabels = TRUE, setValues = TRUE)
m2 = umxModify(m1, update = "G_to_x1", name = "drop_X1")
umxSummary(m2); umxCompare(m1, m2)
# 1-line version including comparison
m2 = umxModify(m1, update = "G_to_x1", name = "drop_X1", comparison = TRUE)
m2 = umxModify(m1, update = "^G_to_x[3-5]", regex = TRUE, name = "no_G_to_x3_5", comp = TRUE)
m2 = umxModify(m1, regex = "^G_to_x[3-5]", name = "no_G_to_x3_5") # same, but shorter
m2 = umxModify(m1, update = "G_to_x1", value = .2, name = "fix_G_x1_at_point2", comp = TRUE)
m3 = umxModify(m2, update = "G_to_x1", free = TRUE, name = "free_G_x1_again", comparison = TRUE)
Run the code above in your browser using DataLab