remove = TRUE issue

3 replies [Last post]
carey's picture
Offline
Joined: 10/19/2009

try the following code

VA <- mxMatrix(name="VA", type="Symm", nrow=5, ncol=5)
DZ <- mxAlgebra(.5 %x% VA, name="covDZA")
test <- mxModel(model="test", VA, DZ )
test
names(test)
rm1 <- mxModel(test, test@matrices$VA, remove=TRUE)
rm2 <- mxModel(test, test@algebras$covDZA, remove=TRUE)
rm3 <- mxModel(test, test@algebras$DZ, remove=TRUE)

why doesn't remove=TRUE work with rm1 and rm2 while it fails to throw an error or warning with rm3?

thought that this was sorted out. see http://openmx.psyc.virginia.edu/thread/269

mspiegel's picture
Offline
Joined: 07/31/2009
OK I've checked in a patch to

OK I've checked in a patch to fix the more significant issue. The original behavior of the argument remove = TRUE was for the function mxModel() to accept character strings instead of the objects themselves. I've added an example on the wiki that explains why it is less error-prone to use the name of an object instead of the object itself.

At some point, a bug was introduced and remove = TRUE stopped working for character vectors. And since we never checked for the objects themselves when remove = TRUE, the thing was hopelessly broken. In the patch, some sensible error messages are printed when someone uses objects with remove = TRUE, or when someone uses character vectors when remove = FALSE. I've also added some test cases to the test suite to make sure this doesn't happen again.

So in OpenMx 1.0.4, the following will work:

VA <- mxMatrix(name="VA", type="Symm", nrow=5, ncol=5)
DZ <- mxAlgebra(.5 %x% VA, name="covDZA")
test <- mxModel(model="test", VA, DZ )
rm1 <- mxModel(test, "VA", remove=TRUE)
rm2 <- mxModel(test, "covDZA", remove=TRUE)

mspiegel's picture
Offline
Joined: 07/31/2009
This looks like one big bug

This looks like one big bug and one small bug. The remove=TRUE should work on rm1 and rm2. I'm getting an internal error message when I try it, which is bad. I'll fix it. We'll release OpenMx 1.0.4 in a few days with this patch. In the construction of rm3, the expression test@algebras$DZ yields NULL. This is the small bug. It's unclear whether adding or removing NULL from a model should either (a) return the original model, the current behavior, or (b) throw an error. I'm in favor of throwing an error.

mspiegel's picture
Offline
Joined: 07/31/2009
In the meantime, you can

In the meantime, you can use:

rm1 <- test
rm1$VA <- NULL

But I'll fix it shortly.