Error: "length of 'dimnames' [1] not equal to array extent"

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
The error comes from your
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")
Log in or register to post comments
In reply to The error comes from your by Ryne
R gobbledegeek
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.
Log in or register to post comments
In reply to R gobbledegeek by neale
I added error checking for
Log in or register to post comments
In reply to I added error checking for by mspiegel
Sweeeet! Thank you, maestro.
Log in or register to post comments
In reply to I added error checking for by mspiegel
excellent error message on dimname mis-match
> # Run ACE model
> twinACEFit <- mxRun(twinACEModel)
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.
Log in or register to post comments
In reply to I added error checking for by mspiegel
error for improvement: Expected covariance matrix is not positiv
"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.
Log in or register to post comments
In reply to The error comes from your by Ryne
Thank you Ryne and
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
Log in or register to post comments
In reply to The error comes from your by Ryne
multi by a lower try of 1s to ensure monotonicity
http://openmx.psyc.virginia.edu/thread/1091
Log in or register to post comments