Hi,

I am trying to fit a biv model (2 continuous phenotypes) with sex as definition variable to test for mean differences, however I get the same error over and over again:

Error: A definition variable has been declared in model 'Chol' that does not contain a data set

I cannot find where it goes wrong, I suspect it's somewhere in the matrices declared to store linear coefficients for covariate:

grandMean B_Sex defSex SexR expMean

Any help would be very much appreciated!

Regards,

Nienke

The error appears to be saying that it wants you to add a dataset to the model, so that it can find the variable?

Try adding something like this to your model:

PS, the tiny fragment of script you posted doesn't help, as it can't be generating the error

Sorry, you're right, think I've found the solution, however next time I'll post more of the script :)

I'm having a similar error with age as a covariate in a trivariate model but definitely have specified mxData

Error: A definition variable has been declared in model 'CholACE' that does not contain a data set

The full script is below

data

head(data)

describe(data)

data$twin1age data$twin2age data$sibage data$moral1 data$moral2 data$sibdm data$path1 data$path2 data$sibdp data$sexual1 data$sexual2 data$sibds data$zyg head(data)

# Select Variables for Analysis

Vars nv nsib ntv

selVars 'moral2','path2','sexual2',

'sibdm','sibdp','sibds')

defVars useVars

#Subset data for testing

mzdata dzdata describe(mzdata, skew=F)

describe(dzdata, skew=F)

dim(mzdata)

dim(dzdata)

cov(mzdata,use="complete")

cov(dzdata,use="complete")

cor(mzdata,use="complete")

cor(dzdata,use="complete")

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

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

# Cholesky Decomposition ACE Model

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

# Set Starting Values

svMe svPa lbPa

# Matrices declared to store a, c, and e Path Coefficients

pathA values=svPa, labels=labLower("a",nv), lbound=lbPa, name="a" )

pathC values=svPa, labels=labLower("c",nv), lbound=lbPa, name="c" )

pathE values=svPa, labels=labLower("e",nv), lbound=lbPa, name="e" )

# Matrices generated to hold A, C, and E computed Variance Components

covA covC covE

# Algebra to compute total variances and standard deviations (diagonal only)

covP matI invSD

# Algebra for expected Mean and Variance/Covariance Matrices in MZ & DZ twins

# Algebra for expected Mean Matrices in MZ & DZ twins

defAge labels=c('data.twin1age','data.twin2age','data.sibage'),name='Age')

pathB label="b11", name="b")

meanG values=svMe, labels=labFull("me",1,nv), name="meanG" )

expMean

covMZ cbind(A+C, V, .5%x%A+C),

cbind(.5%x%A+C, .5%x%A+C, V)),

name="expCovMZ" )

covDZ cbind(.5%x%A+C, V, .5%x%A+C),

cbind(.5%x%A+C, .5%x%A+C, V)),

name="expCovDZ" )

# Data objects for Multiple Groups

dataMZ dataDZ

# Objective objects for Multiple Groups

objMZ objDZ

# Combine Groups

pars modelMZ modelDZ minus2ll obj CholAceModel

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

# RUN GENETIC MODEL

# Run Cholesky Decomposition ACE model

CholAceFit

You are not the first user to run into this problem. Try moving the matrix for the definition variables,

`defAge`

, out of`pars`

and into the submodel being declared.That should fix the problem. Or, you could just remove

`pars`

from the supermodel. So, change`CholAceModel <- mxModel( "CholACE", pars, modelMZ, modelDZ, minus2ll, obj )`

to

`CholAceModel <- mxModel( "CholACE", modelMZ, modelDZ, minus2ll, obj )`

as well. The cause is the presence of

`defAge`

in the supermodel,`CholAceModel`

, which does not contain any data of its own.Sorry if my prior edits of this post were confusing... :-/

Fantastic, thank you!