Hi!

I have prepared a script to compute a linear growth model to estimate genetic and environmental influences (ACE) in an intake and a slope with ordinal twin data: 4 variables, 3 categories (2 thresholds) in each of them. The sample is is divided in 6 groups (and so is the script), according to zygosity and sex: MZ men, DZ men, MZ women, DZ women, DZ man-woman and DZ woman-man.

I get an error message indicating the following sentence:

> Error: The algebra 'ACE.expThre' in model 'lgcOrdACE' generated the error message: length of 'dimnames' [1] not equal to array extent

The matrix concerning the error message ("expThre") is specified in the script as follows:

> mxMatrix( type="Full", nrow=1, ncol=nv, free=F, labels="th1", values=0, name="t1" ),

> mxMatrix( type="Full", nrow=1, ncol=nv, free=T, labels="th2", values=.1, name="t2" ),

> mxAlgebra( expression=(rbind(t1,t2)), name="Th" ),

> mxMatrix( type="Lower", nrow=nth, ncol=nth, free=FALSE, values=1, name="Inc" ),

> mxMatrix( type="Full", nrow=nv, ncol=nf, free=F, values=c(1,1,1,1,0,1,2,3), name="fl" ),

> mxMatrix( type="Unit", nrow=2, ncol=1, name="UnitV1" ),

> mxMatrix( type="Unit", nrow=1, ncol=nv, name="UnitV2" ),

> mxAlgebra( expression= (UnitV1 %x% (Inc %*% Th)) - (UnitV2 %x% (fl %*% Mean)), name="ThInc"),

> mxAlgebra( expression= cbind(ThInc,ThInc), dimnames=list(thRows,selVars), name="expThre" ),

I am not very familiar with scripting in OpenMx for growth models, so I am not able to understand the error and how can I correct it. I would very much appreciate any help to interpret the meaning of this error message. I have attached the full script with the model if anybody wish to have a look.

Thanks a lot in advance!

Regards,

Alfredo

Attachment | Size |
---|---|

Script.R | 7.32 KB |

The error comes from your dimnames argument to the mxAlgebra expression: the number of dimnames you assign to rows (thRows) is not equal to the number of rows in the matrix that results from your algebra. If I've traced your algebra correctly, Th is a 2 x 4 matrix, Inc is a 2 x 2 and UnitV1 is a 2 x 1. The kronecker product of a 2 x 1 and a 2 x 4 (the first half of your ThInc algebra) is a (2*2) by (1*4) matrix, or a 4 x 4. You specified 2 row names for this matrix, and there are four rows.

I'll also add that OpenMx does not require the "lower matrix trick" to keep thresholds strictly increasing. If your model is just four variables in two twins where the four variables represent a single variable measured at four timepoints, the following matrix should give you exactly what you're looking for, which is a nth (2) by ntv (4*2=8) matrix of thresholds, where the first row is the first threshold, the second row is the second threshold, columns 1-4 are timepoints 1-4 for twin 1, and columns 5-8 are timepoints 1-4 for twin 2. The values and labels are repeated in a column-major fashion, such that they are repeated starting at matrix element 1,1 and work down each column before going on to the next row.

mxMatrix("Full", nth, ntv, free=TRUE,

values=c(0, .1), labels=c("th1", "th2"), name="expThre")

Unfortunately, it is quite difficult for ordinary human beings to parse this particularly badly written and uninformative R error message. At the very least it should say what the array length in question is, and what "array extent" it does not match. To be polite it might even explain WTF an array extent is...

It would be great if OpenMx would respond to this error with:

"OpenMx developers apologize that the above error message was written so poorly and is so incomprehensible to the uninitiated" The error was triggered because two things that were supposed to be the same size were not. In this case, the dimnames... and pretty much follow along the lines of Ryne's response. Saying what the lengths in question actually are is critical.

I added error checking for dimnames on MxMatrix and MxAlgebra objects into the svn repository. It will appear in the OpenMx 1.1 release, as well as any future OpenMx 1.1 beta releases that have a version number higher than "999.0.0-1661".

Sweeeet! Thank you, maestro.

Thanks Mike: That's sooo... much easier to understand, find, and debug: Excellent!

> # Run ACE model

> twinACEFit Running twinACE

Error: The expected covariance matrix associated with the FIML objective in model 'DZ' is not of the same length as the 'dimnames' argument provided by the objective function. The 'dimnames' argument is of length 3 and the expected covariance matrix has 2 rows and columns.

just got this error from a multi-group raw matrix twin model:

"Error: The job for model 'sexlim' exited abnormally with the error message: Expected covariance matrix is not positive-definite in data row 59 at iteration 0."

It would be helpful if the submodel containing the data (or the data variable name) was return. A hint as to what to do would also be helpful.

Thank you Ryne and Michael.

Your indication was very clear and extremely helpful. I modified the script following your suggestion, removing unnecessary lines and including the specification of the matrix "expThre" as follows:

> mxMatrix("Full", nth, ntv, free=TRUE, values=c(0, .5), labels=c("th1", "th2"), lbound=.001, ubound=1, dimnames=list(thRows,selVars), name="expThre"),

Right now, the script is running and it seems to work fine (it will be running for several hours, but hopefully everything will be fine).

As an aside note, I have seen a example script where thresholds are kept invariant by constraining them to be equal across observations, e.g.:

> mxMatrix( type="Full", nrow=1, ncol=nv, free=FALSE, values=0, name="t1" ),

> mxMatrix( type="Full", nrow=1, ncol=nv, free=FALSE, values=1, name="t2" ),

> mxMatrix( type="Full", nrow=1, ncol=nv, free=TRUE, labels="th3", values=.9, name="t3" ),

> mxAlgebra( expression=(rbind(t1,t2,t3)), name="Th" ),

> mxMatrix( type="Unit", nrow=1, ncol=nv, name="UnitV" ),

> mxMatrix( type="Zero", nrow=1, ncol=ntv, name="expMean"),

> mxAlgebra( expression= Inc %*% Th - (UnitV %x% (fl %*% Mean)), name="ThInc"),

> mxAlgebra( expression= cbind(ThInc,ThInc), dimnames=list(thRows,selVars), name="expTh" ),

I wonder whether I should also fix my "expThe" matrix in a similar manner e.g. "free=FALSE, values=c(0, 1)", in order to keep also the thresholds invariant. Do you have an opinion about it?

Once more, thank you so much for your help.

Best regards,

-Alfredo

See comment here for an example script and a note on how to ensure the thresholds are maintained in order using the effect of matrix multiplication to make the thresholds out of a base and additive increments

http://openmx.psyc.virginia.edu/thread/1091