You are here

error in biv model with definition variable

6 posts / 0 new
Last post
Nienke's picture
Joined: 01/22/2013 - 09:44
error in biv model with definition variable

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!


tbates's picture
Joined: 07/31/2009 - 14:25
definition variable declared in model that does not contain data

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:

	mxData(myData, type="raw")

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

randMean <- mxMatrix(type="Full", nrow=1, ncol=nphen, free = TRUE, values=c(2700, 19), label=c("mean1","mean2"), name="Mean")
B_Sex <- mxMatrix(type="Full", nrow=ndef, ncol=nvar, free=TRUE, values=c(900,2.7), label=(rep(c("bphen1","bphen2"), 2)), name="bSex" )
defSex <- mxMatrix(type="Full", nrow=ndef, ncol=nvar, free=FALSE, labels=(rep(c("data.Sex1","data.Sex2"),each=2)), name="Sex")
SexR <- mxAlgebra(bSex * Sex, name="SexR")
expMean <- mxAlgebra(name="expMean", expression= cbind(Mean, Mean) + SexR)

Nienke's picture
Joined: 01/22/2013 - 09:44
Sorry, you're right, think

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

James Sherlock's picture
Joined: 06/03/2014 - 01:45
definition in model that does not contain data

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$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',

defVars useVars

#Subset data for testing
mzdata dzdata describe(mzdata, skew=F)
describe(dzdata, skew=F)
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# 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" )


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 Cholesky Decomposition ACE model

RobK's picture
Joined: 04/19/2011 - 21:00
Should be simple to fix

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 )
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... :-/

James Sherlock's picture
Joined: 06/03/2014 - 01:45
Fantastic, thank you!

Fantastic, thank you!

Log in or register to post comments