# age&sex as covariates; ordinal data

4 posts / 0 new Offline
Joined: 06/26/2013 - 23:18
age&sex as covariates; ordinal data

This is the first time I use open Mx.
without such covariates, my script runs.

Now, I add age and sex as definition factors. results show :
'Unknown thresholds name 'expThreMZ1' detected in the objective function of model 'MZ'.

I dont know what is wrong. So if you could give me some help? Thanks.

=================================================
MeanL <-mxMatrix( type="Zero", nrow=1, ncol=ntv, name="M" )

Inc <-mxMatrix( type="Lower", nrow=nth, ncol=nth, free=FALSE, values=1, name="L" )
Tmz <-mxMatrix(type="Full", ........, name="ThMZ" )
ThreMZ<-mxAlgebra( expression= L %*% ThMZ, name="expThreMZ" )

Tdz <-mxMatrix(type="Full", ........., name="ThDZ" )
ThreDZ<-mxAlgebra( expression= L %*% ThDZ, name="expThreDZ" )

CorMZ <-mxMatrix(type="Stand", nrow=ntv, ncol=ntv, free=T, values=.6, lbound=-.99, ubound=.99, name="expCorMZ")
CorDZ <-mxMatrix(type="Stand", nrow=ntv, ncol=ntv, free=T, values=.3, lbound=-.99, ubound=.99, name="expCorDZ")

# Data objects for Multiple Groups

dataMZ <- mxData( observed=mzDataF, type="raw" )
dataDZ <- mxData( observed=dzDataF, type="raw" )

# defination var

ageT1MZ <- as.vector(subset(ukdata, zg==1, age1))
ageT2MZ <- as.vector(subset(ukdata, zg==1, age2))
ageT1DZ <- as.vector(subset(ukdata, zg==2, age1))
ageT2DZ <- as.vector(subset(ukdata, zg==2, age2))
sexT1MZ <- as.vector(subset(ukdata, zg==1, sex1))
sexT2MZ <- as.vector(subset(ukdata, zg==1, sex2))
sexT1DZ <- as.vector(subset(ukdata, zg==2, sex1))
sexT2DZ <- as.vector(subset(ukdata, zg==2, sex2))

Co <- mxMatrix( type="Full", nrow=2, ncol=2, free=TRUE, values= 0.1, label=c("betaAge","betaSex"), name="beta")

# Algebra for making the means a function of the definition variables age and sex

DefMZ <- mxMatrix( type="Full", nrow=2, ncol=2, free=F, label=c("data.ageT1MZ","data.sexT1MZ","data.ageT2MZ","data.sexT2MZ"), name="MZDefVars")
DefMZ1 <- mxAlgebra( expression=expThreMZ + beta %*% MZDefVars, name="expThreMZ1")

DefDZ <- mxMatrix( type="Full", nrow=2, ncol=2, free=F, label=c("data.ageT1DZ","data.sexT1DZ","data.ageT2DZ","data.sexT2DZ"), name="DZDefVars")
DefDZ1 <- mxAlgebra( expression=expThreDZ+ beta %*% DZDefVars, name="expThreDZ1")

objMZ <- mxFIMLObjective( covariance="expCorMZ", means="M", dimnames=selVars, thresholds="expThreMZ1" )
objDZ <- mxFIMLObjective( covariance="expCorDZ", means="M", dimnames=selVars, thresholds="expThreDZ1" )

# Combine Groups

modelMZ <- mxModel( MeanL, Inc, Tmz, ThreMZ, CorMZ, dataMZ,objMZ, name="MZ" )
modelDZ <- mxModel( MeanL, Inc, Tdz, ThreDZ, CorDZ, dataDZ,objDZ, name="DZ" )
minus2ll <- mxAlgebra( expression=MZ.objective + DZ.objective, name="m2LL" )
obj <- mxAlgebraObjective( "m2LL" )
Conf <- mxCI (c ('MZ.expCorMZ[2,1]', 'DZ.expCorDZ[2,1]') )
SatModel <- mxModel( "Sat", modelMZ, modelDZ, minus2ll, obj, Conf )

# 1) RUN Saturated Model

SatFit <- mxRun(SatModel, intervals=T) Offline
Joined: 07/31/2009 - 15:26

I think the issue is that modelMZ does not have DefMZ1 in it, so there is nothing named "expThreMZ1" in the model. If you replace

modelMZ  <- mxModel( MeanL, Inc, Tmz, ThreMZ, CorMZ, dataMZ,objMZ, name="MZ" )

with something like

modelMZ  <- mxModel( MeanL, Inc, Tmz, ThreMZ, CorMZ, DefMZ, DefMZ1, dataMZ,objMZ, name="MZ" )`

then should at least get a different error message, and it might even fix the issue. :)

You may need to add more objects into the model too, but hopefully this will get you started. The thing to remember is: declaring objects in R does NOT put them in your model. Offline
Joined: 06/26/2013 - 23:18
thank you

Thank you. This problem is solved.
I add all the objects into the model. and there occurred another error:
'The following error occurred while evaluating the subexpression 'MZ.expThreMZ + MZ.beta %*% MZ.MZDefVars' during the evaluation of 'MZ.expThreMZ1' in model 'Sat'

Co <- mxMatrix( type="Full", nrow=2, ncol=2, free=TRUE, values= 0.1, label=c("betaAge","betaSex"), name="beta")

# Algebra for making the means a function of the definition variables age and sex

DefMZ <- mxMatrix( type="Full", nrow=2, ncol=2, free=F, label=c("ageT1MZ","sexT1MZ","ageT2MZ","sexT2MZ"), name="MZDefVars")
DefMZ1 <- mxAlgebra( expression=expThreMZ + beta %*% MZDefVars, name="expThreMZ1")

DefDZ <- mxMatrix( type="Full", nrow=2, ncol=2, free=F, label=c("ageT1DZ","sexT1DZ","ageT2DZ","sexT2DZ"), name="DZDefVars")
DefDZ1 <- mxAlgebra( expression=expThreDZ+ beta %*% DZDefVars, name="expThreDZ1")

# Objective objects for Multiple Groups

objMZ <- mxFIMLObjective( covariance="expCorMZ", means="M", dimnames=selVars, thresholds="expThreMZ1" )
objDZ <- mxFIMLObjective( covariance="expCorDZ", means="M", dimnames=selVars, thresholds="expThreDZ1" )

# Combine Groups

modelMZ <- mxModel( MeanL, Inc, Tmz, ThreMZ, CorMZ, Co, DefMZ ,DefMZ1,dataMZ,objMZ, name="MZ" )
modelDZ <- mxModel( MeanL, Inc, Tdz, ThreDZ, CorDZ, Co, DefDZ ,DefDZ1,dataDZ,objDZ, name="DZ" )
minus2ll <- mxAlgebra( expression=MZ.objective + DZ.objective, name="m2LL" )
obj <- mxAlgebraObjective( "m2LL" )
Conf <- mxCI (c ('MZ.expCorMZ[2,1]', 'DZ.expCorDZ[2,1]') )
SatModel <- mxModel( "Sat", modelMZ, modelDZ, minus2ll, obj, Conf )
SatFit <- mxRun(SatModel, intervals=T) Offline
Joined: 07/31/2009 - 15:26
Non-conformable?

All of the error message did not copy over, so I don't know what error message you received. Guessing, I would think the error has something to do with non-conformable matrices. Am I right?