Error message with mxConstraint

Posted on
No user picture. bverhulst Joined: 03/08/2010

Hi All,

I am having an issue with the mxConstraint command.
I am getting an error when I try and constrain the sum of the squared real and imaginary eigenvalues to be less than a unit matrix.
The algebra and constraint commands are:

mxAlgebra( expression=(eigenval(ACE.bm)^2) + (ieigenval(ACE.bm)^2), name="eigen"),
mxMatrix( type="Full", nrow=2, ncol=1, free=FALSE, values= 1, name="unit"),
mxConstraint(eigen

Here are the matrices under question:

Real Eigenvalue Matrix
[,1]
[1,] 0
[2,] 0

Imaginary Eigenvalue Matrix
[,1]
[1,] 1.012369
[2,] -1.012369

Unit matrix
[,1]
[1,] 1
[2,] 1

Here is the error message

Error: The left hand side of constraint 'ACE.cons' in model 'bivHetACE' generated the error message: non-conformable arrays

Just to be sure, squaring the real and imaginary eigenvalue matrices give a 2 x 1 matrix, so I don’t know why it is not conformable.

Thanks for any insights you may have,
Brad

Replied on Tue, 11/16/2010 - 15:45
No user picture. bverhulst Joined: Mar 08, 2010

Sorry, just noticed that the commands didn't post properly
Here they are again,

mxAlgebra( expression=(eigenval(ACE.bm)^2) + (ieigenval(ACE.bm)^2), name="eigen"),
mxMatrix( type="Full", nrow=2, ncol=1, free=FALSE, values= 1, name="unit"),
mxConstraint(eigen "less than" unit, name="cons"),

Thanks

Replied on Tue, 11/16/2010 - 15:57
Picture of user. mspiegel Joined: Jul 31, 2009

In reply to by bverhulst

Try using mxEval(...,compute=TRUE) to confirm that the left-hand side of the constraint is a 2 x 1 matrix.

So for example, use something like:
mxEval(eigenval(ACE.bm)^2 + ieigenval(ACE.bm)^2, model, compute=TRUE)

Replied on Tue, 11/16/2010 - 16:29
No user picture. bverhulst Joined: Mar 08, 2010

In reply to by mspiegel

When I use the command you suggested I get a 2 x 1 matrix:

> mxEval(eigenval(ACE.bm)^2 + ieigenval(ACE.bm)^2, bivHetACEDualFit , compute=TRUE)
[,1]
[1,] 1.024890
[2,] 1.024890

Replied on Thu, 11/18/2010 - 11:15
Picture of user. mspiegel Joined: Jul 31, 2009

Aha. I'm very sorry about this bug. Here is the short explanation. Replace your 'eigen' algebra with the following and it will work:

mxAlgebra( expression=(eigenval(ACE.bm) %^% 2) +
    (ieigenval(ACE.bm) %^% 2), name="eigen")

Here is the long explanation. The OpenMx backend is a matrix processing language. We have two types of exponent operators '^' and '%^%'. The first operator performs element-wise exponentiation. Both arguments must be of the same dimensions. The second operator performs a kronecker-exponentiation. This is similar to kronecker multiplication, but with the exponent operator instead of the multiplication operator.

The OpenMx frontend performs all the error checking in R. The '^' operator in R does element-wise exponentiation when the two arguments are matrices of the same dimension, and kronecker exponentiation when the second argument is a scalar value. In the past, we have manually caught and reported meaningful errors when the R semantics and OpenMx backend semantics did not agree. This is one case that we forgot.

Replied on Sun, 11/21/2010 - 10:16
Picture of user. mspiegel Joined: Jul 31, 2009

Just a heads up, I'm checking in a patch to clean up one of the dark corners of error checking. This patch will eventually make itself into the OpenMx 1.1 release. The new error message for this script will be:

Error: The following error occurred while evaluating the subexpression 'eigenval(ACE.bm)^`2`' during the evaluation of 'ACE.eigen' in model 'bivHetACE' : non-conformable arrays.