Labels to fix, drop, or equate paths.
“In the beginning was the
This power comes because those labels can be used to control the parameter.
There are two ways in which labels are valuable: two parameters with the same label are effectively just one parameter (i.e., labels implement constraints without all the hassle and time of constraints).
Second, we can change a model by addressing its parameters by label. That’s how, for instance,
using umxLabel to create systematic paths and matrices for you.
By default, OpenMx doesn’t label parameters. However, if you use umxRAM, then all your paths will be labelled. The labelling rule is
- one-headed: <from> + "to" <to>
- two-headed: <from> + "with" <to>
- means: "mean_" <to>
So a path from “E” to “days_off_school” will be labelled “E_to_days_off_school”
For matrix based models, the rule is simpler (and more general). All cells are labeled
<matrixName> + "_r" <rowNumber> + "_c" <cellNumber>
So a cell on row 2, column 3 of a matrix called “a” would be labelled “a_r2_c3”
require(OpenMx) 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), mxData(cov(demoOneFactor), type = "cov", numObs = 500) )
Using the parameters() function
umx implements a
parameters function to get these for you.
parameters(m1) # Default "matrix address" labels, i.e "One Factor.S[2,2]" m1 = umxLabel(m1) parameters(m1, free = TRUE) # Default "matrix address" labels, i.e "One Factor.S[2,2]" # an alias for the same thing umxGetParameters(m1, free = TRUE) # Informative labels: "G_to_x1", "x4_with_x4", etc.
Filtering the parameter list to show just the labels you’re looking for
Often there are many labels in a model.
parameters (or its alias
umxGetParameters) allows you to “filter” this list, i.e., view just the ones you want. You can even write filters using regular expressions!
So a simple filter might show only paths containin G_to
umxGetParameters(m1, "G_to", free = TRUE) # Just labels beginning "G_to"
A clever regular-expression version uses ^ to “anchor the expression” to the start of the label
umxGetParameters(m1, "^G_to", free = TRUE) # Just labels beginning "G_to"
Another feature we’ve used but not highlighted above is the
free option. Compare these two outputs:
parameters(m1) # All parameters parameters(m1, free = TRUE) # Just parameters that are free parameters(m1, free = FALSE) # Just parameters that are fixed
Labeling a matrix
a = umxLabel(mxMatrix(name = "a", "Full", 3, 3, values = 1:9)) a$labels [,1] [,2] [,3] [1,] "a_r1c1" "a_r1c2" "a_r1c3" [2,] "a_r2c1" "a_r2c2" "a_r2c3" [3,] "a_r3c1" "a_r3c2" "a_r3c3"
Equate parameters by label
A primary use for labels is to equate parameters. If parameters have the same label, they are forced to have identical values. They are especially powerful for allowing communication across groups, but also, as we will see here, within groups.
Core concept in OpenMx
Parameters know three things:
- Whether they are free.
- What their current value is.
- What their label is.
For all these examples, we will use our old friend,
m1, so if you haven’t made him, do so now:
latents = c("G") manifests = names(demoOneFactor) m1 <- mxModel("m1", type = "RAM", manifestVars = manifests, latentVars = latents, mxPath(from = latents, to = manifests), mxPath(from = manifests, arrows = 2), mxPath(from = latents , arrows = 2, free = F, values = 1), mxData(cov(demoOneFactor), type = "cov", numObs = nrow(demoOneFactor)) )
Getting (reading) existing labels
OpenMx has a built-in function for getting parameters from a model
Let’s have a look at the
A matrix, which contains our asymmetric paths
m1$matrices$A$labels # nb: By default, paths have no labels # we could also use # umx_show(m1)
Despite these parameters having no explicit labels, we can still address them in OpenMx using bracket labels.
omxGetParameters(m1) # nb: By default, paths have no labels, and starts of 0
Here you can see that OpenMx leaves labels blank by default
umxLabel, you can easily add informative and predictable labels to each free path (works with matrix style as well!)
umxStart, to set sensible guesses for start values…
m1 = umxLabel(m1) m1 = umxStart(m1)
umxRAM does this for you, writing systematic path-based labels to every matrix label cell in the form
var1_to_var2 for single-heaed arrows, and
var1_with_var2 for double headed arrows.
Let’s do that now
manifests = names(demoOneFactor) m1 <- umxRAM("m1", data = mxData(cov(demoOneFactor), type = "cov", numObs = nrow(demoOneFactor)), umxPath(from = "G", to = manifests), umxPath(var = manifests), umxPath(var = "G", fixedAt = 1) )
Setting a value by label
m1 = omxSetParameters(m1, labels="x1_to_x5", values = 0) umxGetParameters(m1, "^x1.*5$") # umxGetParameters can filter using regular expressions!
Equating two paths by setting their label
# force G_to_x5 to have the same estimated value as G_to_x4 m1 = omxSetParameters(m1, labels="G_to_x5", newlabels = "G_to_x4") umxSummary(mxRun(m1), show = "std")