You are here

ERROR for missing value where TRUE/FALSE needed

5 posts / 0 new
Last post
lingsuer87's picture
Offline
Joined: 05/03/2013 - 09:10
ERROR for missing value where TRUE/FALSE needed

Dear all.

I am trying to add age as covariant into my liability threshold model. the script runs well before I add age covariant, However, after I add age covariate into the model, OpenMx always give me this error message:
Error in if (label %in% fixedVars && startVals[[label]] != value) { :
missing value where TRUE/FALSE needed.

I googled this error message, it seem to be too many missing values in age variables. But I still can not get the answer which how to fix this issue. I am wondering is any body has experience to fix that? If so, could you give me some suggestion about that?

Thank you very much in advance!
The codes as below:

mean

meanG <-mxMatrix( type="Zero", nrow=1, ncol=8, name="expMean" )

slope

beta1 <- mxMatrix( type="Full", nrow=1, ncol=1, free=TRUE,
values=0, labels='betage', name="b1" )

age matrix

ObsAge<-mxMatrix( type="Full", nrow=1,ncol=8, free=F, values=c(all$age7,all$age8,all$age1,all$age2,all$age3,all$age4,all$age5,all$age6),label=c('age7','age8','age1','age2','age3','age4','age5','age6'), name="Age")

Matrices to calculate effect on mean (beta * definition variable)

Defage <- mxAlgebra(expression= b1 %*% Age,name="Defage")

interception

intercep <- mxMatrix( type="Full", nrow=1, ncol=8, free=TRUE, values=-0.25, lbound=-.99, ubound=.99,
labels="thresh", name="intercept" )

threshold

expThresh <- mxAlgebra( intercept + Defage, name="expThre")

correlations

corMZM <-mxMatrix(type="Stand", nrow=8, ncol=8, free=T, values=corValsMZ, lbound=-.99, ubound=.99, labels=c(
'rFM','rFS','rFS','rFS','rFS','rFD','rFD','rMS','rMS',"rMS",'rMS','rMD','rMD',
'rMZM','rBB','rBB','rBS','rBS','rBB','rBB','rBS','rBS',
'rBB','rBS','rBS','rBS','rBS','rSS'), name="expCorMZM")

corMZF <-mxMatrix(type="Stand", nrow=8, ncol=8, free=T, values=corValsMZ, lbound=-.99, ubound=.99, labels=c(
'rFM','rFD','rFD','rFS','rFS','rFD','rFD','rMD','rMD',"rMS",'rMS','rMD','rMD',
'rMZF','rBS','rBS','rSS','rSS','rBS','rBS','rSS','rSS',
'rBB','rSS','rBS','rBS','rBS','rSS'), name="expCorMZF")

corDZM <-mxMatrix(type="Stand", nrow=8, ncol=8, free=T, values=corValsDZ, lbound=-.99, ubound=.99, labels=c(
'rFM','rFS','rFS','rFS','rFS','rFD','rFD','rMS','rMS',"rMS",'rMS','rMD','rMD',
'rDZM','rBB','rBB','rBS','rBS','rBB','rBB','rBS','rBS',
'rBB','rBS','rBS','rBS','rBS','rSS'), name="expCorDZM")

corDZF <-mxMatrix(type="Stand", nrow=8, ncol=8, free=T, values=corValsDZ, lbound=-.99, ubound=.99, labels=c(
'rFM','rFD','rFD','rFS','rFS','rFD','rFD','rMD','rMD',"rMS",'rMS','rMD','rMD',
'rDZF','rBS','rBS','rSS','rSS','rBS','rBS','rSS','rSS',
'rBB','rSS','rBS','rBS','rBS','rSS'), name="expCorDZF")

corDZMF <-mxMatrix(type="Stand", nrow=8, ncol=8, free=T, values=corValsDZ, lbound=-.99, ubound=.99, labels=c(
'rFM','rFS','rFD','rFS','rFS','rFD','rFD','rMS','rMD',"rMS",'rMS','rMD','rMD',
'rDZMF','rBB','rBB','rBS','rBS','rBS','rBS','rSS','rSS',
'rBB','rBS','rBS','rBS','rBS','rSS'), name="expCorDZMF")
corDZFM <-mxMatrix(type="Stand", nrow=8, ncol=8, free=T, values=corValsDZ, lbound=-.99, ubound=.99, labels=c(
'rFM','rFD','rFS','rFS','rFS','rFD','rFD','rMD','rMS',"rMS",'rMS','rMD','rMD',
'rDZFM','rBS','rBS','rSS','rSS','rBB','rBB','rBS','rBS',
'rBB','rSS','rBS','rBS','rBS','rSS'), name="expCorDZFM")

Data objects for Multiple Groups

dataMZM <-mxData(mzmData, type="raw")
dataDZM <-mxData(dzmData, type="raw")
dataMZF <-mxData(mzfData, type="raw")
dataDZF <-mxData(dzfData, type="raw")
dataDZMF <-mxData(dzmfData, type="raw")
dataDZFM <-mxData(dzfmData, type="raw")

Objective objects for Multiple Groups

objMZM <-mxFIMLObjective( covariance="expCorMZM", means="expMean", dimnames=selVars, thresholds="expThre" )
objDZM <-mxFIMLObjective( covariance="expCorDZM", means="expMean", dimnames=selVars, thresholds="expThre" )
objMZF <-mxFIMLObjective( covariance="expCorMZF", means="expMean", dimnames=selVars, thresholds="expThre" )
objDZF <-mxFIMLObjective( covariance="expCorDZF", means="expMean", dimnames=selVars, thresholds="expThre" )
objDZMF <-mxFIMLObjective( covariance="expCorDZMF", means="expMean", dimnames=selVars, thresholds="expThre" )
objDZFM <-mxFIMLObjective( covariance="expCorDZFM", means="expMean", dimnames=selVars, thresholds="expThre" )

Combine Groups

pars<- list(meanG,beta1,ObsAge,Defage)
groupMZM <-mxModel("MZM", pars,corMZM, dataMZM, objMZM,intercep,expThresh)
groupDZM <-mxModel("DZM", pars,corDZM, dataDZM, objDZM,intercep,expThresh )
groupMZF <-mxModel("MZF", pars,corMZF, dataMZF, objMZF,intercep,expThresh )
groupDZF <-mxModel("DZF", pars,corDZF, dataDZF, objDZF,intercep,expThresh )
groupDZMF <-mxModel("DZMF", pars,corDZMF, dataDZMF, objDZMF,intercep,expThresh )
groupDZFM <-mxModel("DZFM", pars,corDZFM, dataDZFM, objDZFM,intercep,expThresh)

minus2ll<-mxAlgebra( MZM.objective + DZM.objective+ MZF.objective + DZF.objective + DZMF.objective+DZFM.objective, name="minus2sumloglikelihood" )
obj <-mxAlgebraObjective("minus2sumloglikelihood")

twinSatModel <-mxModel( "twin", minus2ll, obj, groupMZM, groupDZM,groupMZF, groupDZF, groupDZMF, groupDZFM)

------------------------------------------------------------------------

RUN SATURATED MODEL (Tetrachoric correlations)

-----------------------------------------------------------------------

twinSatFit <- mxRun(twinSatModel, intervals=F)
Running twin
Error in if (label %in% fixedVars && startVals[[label]] != value) { :
missing value where TRUE/FALSE needed

Ryne's picture
Offline
Joined: 07/31/2009 - 15:12
Hi there, Missing values in

Hi there,

Missing values in the fitted data are OK, but OpenMx cannot handle missing values on definition variables. When there are missing values in the data to be fitted (i.e., the variables in mzmData whose tetrachoric correlations you're modeling), our FIML procedure can select the parts of the model for any given row. Definition variables change the model that is fit to the data for each row, so we don't know how you want the model changed when the definition variable is missing. You have to tell us how you want those cases handled by manipulating your data or model so that NA definition variables don't happen. If you think that the mean of each variable changes as a function of age, how should people who don't have a listed age change?

That said, we should probably improve the error message as well.

tbrick's picture
Offline
Joined: 07/31/2009 - 15:10
Corner case error

Agreed.

For the benefit of anyone who runs into this error later, the error is specifically caused because a named parameter shows up more than once in the model and at least one of those times the value is set to NA.

Probably, here, it's 'age7' or one of the other age labels. Because there's missingness in the age variable, it's given an NA value, and it shows up several times in the model because the ObsAge matrix is added to each of the group models, which are then all combined into the final model.

We'll work on making sure there's a better error message for this in the future. Thanks for reporting it, lingsuer87!

For reference by the developers, here's a miniature example that replicates the error:

model <- mxModel("errorModel", mxMatrix("Full", nrow=1, ncol=2, values=c(1, NA), labels="Badness"))
mxRun(model)
lingsuer87's picture
Offline
Joined: 05/03/2013 - 09:10
Yes, as you told me OpenMx

Yes, as you told me OpenMx cannot handle missing values on definition variables. afther I recode missing values on definition variables as a different number. My problem is solved. Thank you very much!

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
I think the issue might be

I think the issue might be your use of things like all$age7. I suspect that 'all' is the name of a data frame and you intend the mxMatrix named 'Age' to be a matrix full of definition variables.

That would be written as follows

# definition variable
mxMatrix(
    type="Full",
    nrow=1,
    ncol=8,
    free=FALSE,
    labels=paste("data.age", c(7, 8, 1:6), sep=""),
    name="Age"
)

Does that help?