# Feature reduction: Square brackets inside MxMatrix labels

2 posts / 0 new
Offline
Joined: 07/31/2009 - 15:24
Feature reduction: Square brackets inside MxMatrix labels

In OpenMx 1.0, it will be possible to use square brackets inside MxMatrix labels only when the row and column arguments of the square brackets are numeric literal values. Specifically, if you wish to use a definition variable in either the row or column argument, then you must place that reference in an algebra and then reference the algebra from the MxMatrix label.

The motivation for this feature reduction begins with a bug report from the forums: http://openmx.psyc.virginia.edu/thread/678. The cause of this bug is due to the interaction of several features in OpenMx, as many of our bugs arise nowadays. The explanation is a little complication, so please bear with me. The OpenMx backend only accepts numeric literal values inside square bracket expressions that appear in MxMatrix objects. Which is a good design choice, we want the backend to be simple and fast. So in order to accommodate definition variables inside square bracket labels, the square bracket label is magically transformed into a MxAlgebra expression, and then a reference is made to the newly created MxAlgebra expression. However, if there is an error in the script, we want to hide the secretly created algebra from the user. So the secret algebra has an identical name to the square bracket label. In this way, the MxAlgebra is "hidden" from the user when an error message is reported. Because of this transformation, in some places of the front-end it is acceptable to use the mxEval() function, and in other places another hidden function must be used instead. If mxEval() is used instead of the hidden function, then an infinite loop occurs (see original bug report).

A design that requires secret hidden functions in some portions of the front-end is a bad design. So for now, the OpenMx library will accept only what is accepted by the back-end. In our test suite, exactly one script had to be altered to accommodate this change. I've included the script so the users can see what is affected. I added the algebra randrow.

multilevelModel2 <- mxModel("Multilevel_2",
mxMatrix("Full", nrow=numSubjects, ncol=2,
values=c(.2,0), free=c(TRUE, TRUE),
name="Rand", byrow=TRUE),
mxMatrix("Full", 2, 2,
labels=c(NA,  NA, "randrow[1,1]", NA),
free=FALSE, name="A",
byrow=TRUE),
mxMatrix("Symm", 2, 2,
values=c(.9,0,.9), free=c(T, F, T),
labels=c("varX", NA, "varY"),
name="S", byrow=TRUE),
mxMatrix("Full", 2, 2,
values=c(1,0,0,1),
free=FALSE, byrow=TRUE, name="F"),
mxMatrix("Iden", 2, name="I"),
mxAlgebra(F %*% solve(I-A) %*% S %*% t(solve(I-A)) %*% t(F),
name="R",  dimnames = list(manifestVars, manifestVars)),
mxMatrix("Full", nrow=1, ncol=length(manifestVars),
values=0, free=FALSE, labels=c(NA,"randrow[1,2]"),
dimnames=list(NULL, manifestVars),
name="M"),
mxAlgebra(Rand[data.ID,], name="randrow"),
mxFIMLObjective(covariance="R", means="M"),
mxData(tDataFrame, type="raw"))

Offline
Joined: 07/31/2009 - 15:24