Error message with mxConstraint

8 replies [Last post]
bverhulst's picture
Offline
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

mspiegel's picture
Offline
Joined: 07/31/2009
Just a heads up, I'm checking

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.

mspiegel's picture
Offline
Joined: 07/31/2009
Aha. I'm very sorry about

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.

bverhulst's picture
Offline
Joined: 03/08/2010
Thanks, that seems to have

Thanks, that seems to have worked.

bverhulst's picture
Offline
Joined: 03/08/2010
Sorry, just noticed that the

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

mspiegel's picture
Offline
Joined: 07/31/2009
Try using

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)

bverhulst's picture
Offline
Joined: 03/08/2010
When I use the command you

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

mspiegel's picture
Offline
Joined: 07/31/2009
That sounds like a bug. Can

That sounds like a bug. Can you attach a script that reproduces the behavior? Use the fakeData() function to generate synthetic data: http://openmx.psyc.virginia.edu/wiki/generating-simulated-data

bverhulst's picture
Offline
Joined: 03/08/2010
I am attaching a copy of two

I am attaching a copy of two fake data files (for each group) and the script with the "problematic" equality constraint.
Thanks for any help you may be able to supply.
Brad

AttachmentSize
mzmFake.txt 62.94 KB
dzmFake.txt 46.31 KB
eigen error.R 3.13 KB