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

jepq.txt | 131.38 KB |

Growth_models_jepq_raw_cont_v3.R | 4.96 KB |

Hi all,

I'm fitting a latent growth curve model to 3 measures of raw continuous personality data. The model includes means on the latent intercept and slope factors to which I'm adding each twin's sex as a definition variable. When running the model I get the following error:

Error in all.na(labels) : object 'data.sex_1' not found

+

>

> lgc2ACEFit <- mxRun(lgc2ACEModel) # Run Latent Growth Curive ACE model

Error in cat("Running", model@name, "\n") :

object 'lgc2ACEModel' not found

Any suggestions?

Cheers,

Nathan

There are two mxMatrix() statements that contain the argument labels=c(data.sex_1,data.sex_2). The labels argument expects character strings. Because data.sex_1 and data.sex_2 are not surrounded by quotes, R is assuming they are variable names. But they are variables that are never defined. Solution: make sure the input to the labels argument is a vector of characters.

Aha! In the labels bit of the mxMatrix() function, the labels need to be in quotes, so replace

with

and hopefully things will start running!

Thanks guys. I'll give that a whirl.

Hi all,

In the formula for the sex effects on the intercept and slope means, sex_t2 is being added to the left hand side of the equation i.e. it's being included in the estimation of the sex effects for twin 1 and it also produces a non-conformable matrix error. I'm therefore trying to estimate the sex effect of twin 1 on the interecept and slope and then 'columnbind' that with the sex effects of twin 2 on the interecept and slope.

In Classic Mx it would look something like...

(F * (M+(sex_t1@Betas)))' | (F * (M+(sex_t2@Betas)))'

So rather than use:

mxMatrix( type="Full", nrow=1, ncol=2, free=FALSE, labels=c("data.sex_1","data.sex_2"), name="defs"),

I have created:

# mxMatrix( type="Full", nrow=1, ncol=1, free=FALSE, labels=c("data.sex_1"), name="sex_t1"),

# mxMatrix( type="Full", nrow=1, ncol=1, free=FALSE, labels=c("data.sex_2"), name="sex_t2"),

Which I have then used in the formula for the means

With 3 variables and 2 twins R is expecting a 1X6 mean matrix. The formula appears to be correct but I still get the "Error: The algebra 'MZ.expMean' in model 'lgc2ACE' generated the error message: non-conformable arguments" error?

Do you have any suggestions?

Cheers,

Nathan

Yes... you're missing a couple of lgc2ACE's

mxAlgebra(expression=cbind( t(lgc2ACE.F%

%( lgc2ACE.M + (sex_t1 %x% lgc2ACE.Beta))), t(lgc2ACE.F%%( lgc2ACE.M + (sex_t2 %x% lgc2ACE.Beta))) ), name="expMean"),Yes, Mike Neale's comment is correct. The algebra expression in model MZ may use only named entities in model MZ without the "." notation. Because "F" is declared in the parent model, it must be used in the MZ model as "lgc2ACE.F".

There is a bug manifesting in this test case. The error message should report "unknown reference to F". I suspect that "F" is getting confused with the global variable 'F' in the user workspace for FALSE. We should only be using global variables that store numeric values from the user workspace, or character vectors (for dimnames in algebra expressions).

Update: that was relatively easy to correct in the source repository. The new error message is: "Error: Unknown reference 'F' detected in the entity 'expMean' in model 'MZ'". The full patch is here. This change will appear in OpenMx 0.2.6.

The model is now working (:)) but unfortunately it is unable to converge reliably (:(). I've tried all sorts of starting values including many restarts (TRYHARD). I even thought that by running a model in which I set the sex betas to zero would converge but no. Only when I strip out all references to the sex effects did converge e.g. a model in which I

(1) removed the code for the Beta matrix

(2) turned off reading in the sex definition variables

## mxMatrix( type="Full", nrow=1, ncol=1, free=FALSE, labels=c("data.sex_1"), name="sex_t1"),

and

(3) wrote the mean formula simply as

e.g. t(lgc2ACE.F%*%( lgc2ACE.M )),

I would have thought that setting the sex Betas to zero would do the same. I'm wondering if there's a glitch somewhere when reading in the definition variables....?

I agree that there seems to be a bug. Values are inconsistent between the reported values of definition variables for the MZ group (via the matrix into which they are supposed to be inserted) and the actual values in that part of the dataframe.

> lgc2ACEFixedBeta$MZ@matrices$defs

FullMatrix 'defs'

@labels

[,1] [,2]

[1,] "data.sex_1" "data.sex_2"

@values

[,1] [,2]

[1,] 1 0

@free: No free parameters.

@lbound: No lower bounds assigned.

@ubound: No upper bounds assigned.

> mzDefs

sex_1 sex_2

1 1 1

2 1 1

3 1 1

etc

281 1 1

282 1 1

283 0 0

284 0 0

etc

564 0 0

565 0 0

The mismatch of definition variables at output appears to be predominantly cosmetic--it doesn't seem to have changed calculation results. There's a fix checked into the svn repository.

More about the problem and fix are at http://openmx.psyc.virginia.edu/issue/2010/02/model-two-definition-variables-wont-run-and-has-funky-values-matrix#comment-1359

On the current problem, the instability in convergence seems to still be there even after the fix. It seems primarily associated with the DZ definition variables.

We now filter the definition variables for each objective function, such that the objective function receives only the definition variables that belong to its data source. And for now, we're throwing a hard error in the back-end if this condition is violated. The credit goes to Tim Brick for locating the bug.

This issue has been bumped to high priority because it's for the workshop. I have another selfish reason for getting it to work - there is no test with multiple definition variables in the test suite.

The final line in version 3 of the script should read (assuming the intent is to turn off the Beta free parameters):

The slot "free" must always store a matrix type. Without the subscripts

`[1:2,1]`

, the assignment operator tries to put a logical vector of length 1 into the "free" slot.Hi all,

As a check I ran the same latent growth curve model in ClassicMx with sex on the latent intercept and slope means. The model runs without problems. I have attached a copy of the Mx script (neuro_lgc_classicMx_Beta.mx), output (neuro_lgc_classicMx_Beta.mxo_.txt) plus the identical script for OpenMx (Growth_models_jepq_raw_cont_v6.R). The jepq data set remains the same.

Cheers,

Nathan

Phew panic over... as per thread http://openmx.psyc.virginia.edu/issue/2010/02/model-two-definition-variables-wont-run-and-has-funky-values-matrix#comment-1359

Thanks everyone for taking a good look at this; I'm glad to find the error was only cosmetic (though they are sometimes the hardest to debug).

Filtering of Definition variables...

related material over here...

http://openmx.psyc.virginia.edu/thread/203#comment-1373

I don't believe the error was cosmetic. I've just installed the latest version of R (older version was 2.9.something which kept returning "Running lgcACE

Error: The job for model 'lgcACE' exited abnormally with the error message: Objective function returned an infinite value."). Latest version works like a charm on the script above. Robust to crappy starting values too. Cheers, N

Yes, we've been working on it all afternoon... Some insights and hypotheses around garbage collection, and the lack of decimal points in the data; we'll see if they pan out.

Hi All, I now seem to be having trouble defining the definition variables. Previously I ran

require(OpenMx)

source("GenEpiHelperFunctions.R")

## Prepare Data

## -----------------------------------------------------------------------

allVars <- c('zyg',' sex_1','sex_2',

'psych12_1','extra12_1','neuro12_1','lie12_1',

'psych14_1','extra14_1','neuro14_1','lie14_1',

'psych16_1','extra16_1','neuro16_1','lie16_1',

'psych12_2','extra12_2','neuro12_2','lie12_2',

'psych14_2','extra14_2','neuro14_2','lie14_2',

'psych16_2','extra16_2','neuro16_2','lie16_2')

jepq <- read.table("jepq.txt", header=F, na.strings="-1", col.names=allVars)

selVars <- c('neuro12_1','neuro14_1','neuro16_1','neuro12_2','neuro14_2','neuro16_2')

selVars2 <- c('sex_1','sex_2')

## Extract MZ and DZ data sets

mzData <- subset(jepq, zyg<3, c(selVars))

dzData <- subset(jepq, zyg>2, c(selVars))

mzDefs <- subset(jepq, zyg<3, selVars2)

dzDefs <- subset(jepq, zyg>2, selVars2)

but now after reading the mzDefs line I get the following error...

> mzDefs <- subset(jepq, zyg<3, c(selVars2))

Error in

`[.data.frame`

(x, r, vars, drop = drop) :undefined columns selected

You have a blank space at the beginning of the ' sex_1' declaration in the allVars vector. I don't know why R does this, but the leading blank space is disallowed in column names and that column name is showing up as "X.sex_1". Eliminate the blank space and the problem will go away.