You are here

Bivariate umxACE model data length error

11 posts / 0 new
Last post
gdash's picture
Offline
Joined: 11/29/2021 - 17:56
Bivariate umxACE model data length error

Hello,

I am new to using umx, so I apologize for asking what is perhaps a very simple question. I am trying to run a bivariate ACE model using binary variables (they are structured as ordered factors). When I run the model, I receive the warning message copied below alongside model output:

In matrix(labels, nrow, ncol, byrow = byrow) :
data length [3] is not a sub-multiple or multiple of the number of rows [2]

I saw a few threads describing this error, but they were all in the context of OpenMx code for which nrow and ncol were explicitly specified in the model. Might you be able to advise what the source of this error is and how to remedy, if necessary? Is the output of the bivariate model unreliable given the accompanying warning message?

Here is the code I am using (adapted from Boulder script):

selDVs = c("var1", "var2")
m1 = umxACE(selDVs = selDVs, dzData = dzData,
mzData = mzData, sep = "_T", tryHard = c("ordinal"))

Thank you very much for your time!

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
more info needed: traceback(); umxVersion();

Can you post what traceback() says immediately after?

Does the univariate model run for both var1 and var2?

Also, what does umxVersion() say?

umxACE is pretty bullet proof and user-input check complete functions so...

m1 = umxACE(selDVs = c("var1", "var2"), dzData = dzData, mzData = mzData, sep = "_T", tryHard = "ordinal")
gdash's picture
Offline
Joined: 11/29/2021 - 17:56
Additional Information

Thank you so much for your quick reply! Please find the requested information copied below:

"Can you post what traceback() says immediately after?"
Error: The argument to the '$' or '[' operator applied on a MxModel object must be a single character string

"Does the univariate model run for both var1 and var2?"
Yes, they both run normally and without errors.

"Also, what does umxVersion() say?"
umx version: 4.9.0
OpenMx version: 2.19.8 [GIT v2.19.8]
R version: R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32
Default optimizer: SLSQP
NPSOL-enabled?: No
OpenMP-enabled?: No

Thank you again! Please let me know if there is any other information I can provide.

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
here's a repro script: works fine here

I can't replicate this. Can you please run the following: It works perfectly for me, at a glance.

# Prep data
require(umx)
data(twinData)
# Cut BMI and ht to form ordinal variables
obLevels = c('normal', 'overweight', 'obese')
cuts = quantile(twinData[, "bmi1"], probs = c(.5, .2), na.rm = TRUE) # 21.6098 20.9519 
twinData$obese1=cut(twinData$bmi1, breaks=c(-Inf,cuts,Inf), labels=obLevels)
twinData$obese2=cut(twinData$bmi2, breaks=c(-Inf,cuts,Inf), labels=obLevels)
 
htLevels = c('short', 'tall')
cuts = quantile(twinData[, "ht1"], probs = c(.5), na.rm = TRUE) # 1.6499
twinData$high1=cut(twinData$ht1, breaks=c(-Inf,cuts,Inf), labels=htLevels)
twinData$high2=cut(twinData$ht2, breaks=c(-Inf,cuts,Inf), labels=htLevels)
 
ordDVs = c("obese1", "obese2", "high1", "high2")
twinData[, ordDVs] = umxFactor(twinData[, ordDVs])
 
mzData = twinData[twinData$zygosity %in% "MZFF", ]
dzData = twinData[twinData$zygosity %in% "DZFF", ]
 
# Run!
m1 = umxACE(selDVs = c("obese", "high"), dzData = dzData, mzData = mzData, sep = '')

with output:

Found 1 pairs of binary variables:'high1' and 'high2'
 
I am fixing the latent means and variances of these variables to 0 and 1
There were also 1 pair(s) of ordinal variables:'obese1' and 'obese2'
No continuous variables
Running ACE with 11 parameters
ACE -2 × log(Likelihood) = 11570.778                                       

Table: Standardized parameter estimates from a 2-factor Cholesky ACE model. A: additive genetic; C: common environment; E: unique environment.

a1 a2 c1 c2 e1 e2
obese 0.795 0.333 0.506
high 0.026 0.899 -0.348 . -0.062 0.258

Table: Means

obese1 high1 obese2 high2
intercept 0.006 0 0.006 0
gdash's picture
Offline
Joined: 11/29/2021 - 17:56
Perhaps a data issue?

Thank you again for your help with this! I ran the script you provided in the R twinData and it worked perfectly on my end, too. Unfortunately, I had less success when I applied the code to my data. I wasn't able to create ordinal factors using the umx code here...I kept getting a "node stack overflow" error after I ran this part:

ordDVs = c("var1_T1", "var1_T2", "var2_T1", "var2_T2")
myData[, ordDVs] = umxFactor(myData[, ordDVs])

For what it's worth, the variables are already categorical (0,1) but, from what I have gathered, they still need to be structured so that umx recognizes them as such? I ended up having success at this step with mxFactor, and ran the umxACE models in question on ordinal factors created that way. For example:

myData$var1_T1 <- mxFactor(myData$var1_T1, levels=c(0:1), ordered=TRUE)

Might that be relevant here? I may be grasping at straws...

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
"node stack overflow"

So the error is not the initial one, nor related to umxFactor, or even umxACE, but rather from specifically a run with your data which prints "node stack overflow" while running your model.

Sounds like an OpenMx error. If you can replicate this, I would immediately run traceback() and then create an issue either at or if you think it is from umx. Include the relevant chunk of console output from umxACE() to the end of traceback() so we can see what this error is and work from there.

Possibly will be helpful to either post the data or use mxGenerateData() to make an anonymised simulation. Honestly the error is not making much sense to me, as a bivariate binary umxACE model is bread-and-butter so we'd see it failing all over the place. I suspect something odd about the data or perhaps your install of R/OpenMx.

Might also be worth updating OpenMx as I see they have a new version on CRAN which fixed some memory leaks, which might be relevant to you.. Newest version:

umx_open_CRAN_page("OpenMx")
[1] ‘2.20.0’

gdash's picture
Offline
Joined: 11/29/2021 - 17:56
Output traceback()

Copied below is the traceback() output- I hope that this corresponds to the output requested!

Here is the output with traceback() from the node stack overflow error when trying use umx to create ordinal factors:

> ordDVs = c("var1_T1", "var1_T2", "var2_T1", "var2_T2")
> myData[, ordDVs] = umxFactor(myData[, ordDVs])
Error: node stack overflow
Error during wrapup: node stack overflow
Error: no more error handlers available (recursive errors?); invoking 'abort' restart
> traceback()
No traceback available

Here is the output with traceback() from using mxFactor to create ordinal factors for analysis:

> myData$var1_T1    <-mxFactor(myData$var1_T1, levels=c(0:1), ordered=TRUE )

> traceback()
1: str(myData)

And here is the output with traceback() from umxACE using factors created with mxFactor (in the step above)

?umxPlotACE options: std=T/F, means=T/F, digits=n, strip_zero=T/F, file=, min=, max =
> #BIVARIATE
> selDVs = c("var1", "var2")
> m1 = umxACE(selDVs = selDVs, dzData = dzData,
+ mzData = mzData, sep = "_T", tryHard = c("ordinal"))
Found 2 pairs of binary variables:'var1_T1', 'var2_T1', 'var1_T2', and 'var2_T2'

I am fixing the latent means and variances of these variables to 0 and 1
No continuous variables

Solution found! Final fit=4667.1459 (started at 4840.7541) (11 attempt(s): 11 valid, 0 errors)

ACE -2 × log(Likelihood) = 4667.146

Table: Standardized parameter estimates from a 2-factor Cholesky ACE model. A: additive genetic; C: common environment; E: unique environment.

| | a1|a2 | c1|c2 | e1|e2 |
|:------|-----:|:--|-----:|:-----|-----:|:-----|
|var1 | 0.596| | 0.315| | 0.738| |
|var2 | 0.799|. | 0.071|0.334 | 0.131|0.478 |

Table: Means (from model$top$expMean)

| |var1_T1 |var2_T1 |var1_T2 |var2_T2 |
|:---------|:-------|:---------|:-------|:---------|
|intercept |0 |0 |0 |0 |

?umxPlotACE options: std=T/F, means=T/F, digits=n, strip_zero=T/F, file=, min=, max =
Warning message:
In matrix(labels, nrow, ncol, byrow = byrow) :
data length [3] is not a sub-multiple or multiple of the number of rows [2]
> traceback(m1)
Error: The argument to the '$' or '[' operator applied on a MxModel object must be a single character string
>

Finally, here is the output from mxGenerateData from the bivariate model.

'max' / getOption("max.print"'max' / getOption("max.print") -- omitted 1631 rows ]

I also went ahead and updated OpenMx as recommended. Please let me know if there is any other information or output I can provide. Thank you for taking time to assist!

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
success and a bit more info

Glad mxFactor got you working. So your columns might not be what umxFactor is expecting - I like to have error checking that makes this always work or else clearly say why to the user.

Would you mind please post what this code returns so I can see what you are feeding in (before you pass it into mxFactor?

str(myData$var1_T1)
table(myData$var1_T1)
gdash's picture
Offline
Joined: 11/29/2021 - 17:56
Code output

Here is what I get when I run the code you kindly provided with each of the variables.

> str(myData$var1_T1)
 num [1:4146] NA 0 0 0 1 0 0 0 0 0 ...
> table(myData$var1_T1)
 
   0    1 
3331  253 
> str(myData$var1_T2)
 num [1:4146] 0 1 0 0 0 0 0 0 0 0 ...
> table(myData$var1_T2)
 
   0    1 
3270  304 
> str(myData$var2_T1)
 num [1:4146] NA 0 0 0 0 0 0 0 0 0 ...
> table(myData$var2_T1)
 
   0    1 
3540   44 
> str(myData$var2_T2)
 num [1:4146] 0 0 0 0 0 0 0 0 0 0 ...
> table(myData$var2_T2)
 
   0    1 
3524   50 

Thank you again for taking time to assist!

gdash's picture
Offline
Joined: 11/29/2021 - 17:56
Apologies for the multiple

Apologies for the multiple posts! I realized that my last post was a bit convoluted- I was able to structure my variables correctly using mxFactor, but still got the data length error when running the bivariate models on those variables within umxACE. I hope that makes sense! Thank you!

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
umxFactor works great

ah.. that makes sense as umxFactor is working just fine:

tmp = twinData[, c("ht1", "ht2")]
tmp$ht1 = 0; tmp$ht1[twinData$ht1 >1.66] = 1
tmp$ht2 = 0; tmp$ht2[twinData$ht2 >1.66] = 1
x = umxFactor(tmp[, c("ht1", "ht2")])
str(x)
 
'data.frame':    3808 obs. of  2 variables:
 $ ht1: Ord.factor w/ 2 levels "0"<"1": 2 1 1 1 1 1 2 1 2 2 ...
  ..- attr(*, "mxFactor")= logi TRUE
 $ ht2: Ord.factor w/ 2 levels "0"<"1": 2 1 2 1 1 1 2 1 2 2 ...
  ..- attr(*, "mxFactor")= logi TRUE