You are here

Error message with mxConstraint

9 posts / 0 new
Last post
bverhulst's picture
Offline
Joined: 03/08/2010 - 17:14
Error message with mxConstraint

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
bverhulst's picture
Offline
Joined: 03/08/2010 - 17:14
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 - 15:24
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 - 17:14
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 - 15:24
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 - 17:14
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

mspiegel's picture
Offline
Joined: 07/31/2009 - 15:24
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 - 17:14
Thanks, that seems to have

Thanks, that seems to have worked.

mspiegel's picture
Offline
Joined: 07/31/2009 - 15:24
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.