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 <- 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)
Any help would be very much appreciated!
Regards,
Nienke
definition variable declared in model that does not contain data
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)
Log in or register to post comments
In reply to definition variable declared in model that does not contain data by tbates
Sorry, you're right, think
Log in or register to post comments
In reply to definition variable declared in model that does not contain data by tbates
definition in model that does not contain data
Error: A definition variable has been declared in model 'CholACE' that does not contain a data set
The full script is below
data <- read.csv('Standardized Disgust Data.csv', na.strings='-99')
head(data)
describe(data)
data$twin1age <- data$age_NEW.1
data$twin2age <- data$age_NEW.2
data$sibage <- data$sib1age
data$moral1 <- data$ZDisgustMoral.1
data$moral2 <- data$ZDisgustMoral.2
data$sibdm <- data$Zsib1dm
data$path1 <- data$ZDisgustPathogen.1
data$path2 <- data$ZDisgustPathogen.2
data$sibdp <- data$Zsib1dp
data$sexual1 <- data$ZDisgustSexual.1
data$sexual2 <- data$ZDisgustSexual.2
data$sibds <- data$Zsib1ds
data$zyg <- data$Corrected_zygosity
head(data)
# Select Variables for Analysis
Vars <- c('moral','path','sexual')
nv <- 3 # number of variables
nsib <- 3
ntv <- nv*nsib # number of total variables
selVars <- c('moral1','path1','sexual1',
'moral2','path2','sexual2',
'sibdm','sibdp','sibds')
defVars <-c('twin1age','twin2age','sibage')
useVars <- c(selVars,defVars)
#Subset data for testing
mzdata <- subset(data, zyg==3, useVars)
dzdata <- subset(data, zyg==4, useVars)
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 <- c(.01,.01, .01) # start value for means
svPa <- valDiag(nv,.6) # start values for parameters on diagonal
lbPa <- valLUDiag(nv,.0001,-10,NA) # lower bounds for parameters on diagonal
# Matrices declared to store a, c, and e Path Coefficients
pathA <- mxMatrix( type="Lower", nrow=nv, ncol=nv, free=TRUE,
values=svPa, labels=labLower("a",nv), lbound=lbPa, name="a" )
pathC <- mxMatrix( type="Lower", nrow=nv, ncol=nv, free=TRUE,
values=svPa, labels=labLower("c",nv), lbound=lbPa, name="c" )
pathE <- mxMatrix( type="Lower", nrow=nv, ncol=nv, free=TRUE,
values=svPa, labels=labLower("e",nv), lbound=lbPa, name="e" )
# Matrices generated to hold A, C, and E computed Variance Components
covA <- mxAlgebra( expression=a %*% t(a), name="A" )
covC <- mxAlgebra( expression=c %*% t(c), name="C" )
covE <- mxAlgebra( expression=e %*% t(e), name="E" )
# Algebra to compute total variances and standard deviations (diagonal only)
covP <- mxAlgebra( expression=A+C+E, name="V" )
matI <- mxMatrix( type="Iden", nrow=nv, ncol=nv, name="I")
invSD <- mxAlgebra( expression=solve(sqrt(I*V)), name="iSD")
# Algebra for expected Mean and Variance/Covariance Matrices in MZ & DZ twins
# Algebra for expected Mean Matrices in MZ & DZ twins
defAge <- mxMatrix(type="Full", nrow=1,ncol=ntv,free=FALSE,
labels=c('data.twin1age','data.twin2age','data.sibage'),name='Age')
pathB <- mxMatrix( type="Full", nrow=1, ncol=1, free=TRUE, values= .01,
label="b11", name="b")
meanG <- mxMatrix( type="Full", nrow=1, ncol=ntv, free=TRUE,
values=svMe, labels=labFull("me",1,nv), name="meanG" )
expMean <- mxAlgebra( meanG + (b%x%Age), name="expMean" )
covMZ <- mxAlgebra( expression= rbind( cbind(V , A+C, .5%x%A+C),
cbind(A+C, V, .5%x%A+C),
cbind(.5%x%A+C, .5%x%A+C, V)),
name="expCovMZ" )
covDZ <- mxAlgebra( expression= rbind( cbind(V , .5%x%A+C, .5%x%A+C),
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 <- mxData( observed=mzdata, type="raw" )
dataDZ <- mxData( observed=dzdata, type="raw" )
# Objective objects for Multiple Groups
objMZ <- mxFIMLObjective( covariance="expCovMZ", means="expMean", dimnames=useVars )
objDZ <- mxFIMLObjective( covariance="expCovDZ", means="expMean", dimnames=useVars )
# Combine Groups
pars <- list( pathA, pathC, pathE, covA, covC, covE, covP, matI, invSD, defAge, pathB, meanG, expMean )
modelMZ <- mxModel( pars, covMZ, dataMZ, objMZ, name="MZ" )
modelDZ <- mxModel( pars, covDZ, dataDZ, objDZ, name="DZ" )
minus2ll <- mxAlgebra( expression=MZ.objective + DZ.objective, name="m2LL" )
obj <- mxAlgebraObjective( "m2LL" )
CholAceModel <- mxModel( "CholACE", pars, modelMZ, modelDZ, minus2ll, obj )
# ------------------------------------------------------------------------------
# RUN GENETIC MODEL
# Run Cholesky Decomposition ACE model
CholAceFit <- mxRun(CholAceModel)
Log in or register to post comments
In reply to definition in model that does not contain data by James Sherlock
Should be simple to fix
defAge
, out ofpars
and into the submodel being declared.That should fix the problem. Or, you could just remove
pars
from the supermodel. So, changeCholAceModel <- 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... :-/
Log in or register to post comments
In reply to Should be simple to fix by RobK
Fantastic, thank you!
Log in or register to post comments