You are here

Adding new algebras in submodels and constraining them

3 posts / 0 new
Last post
Julia's picture
Offline
Joined: 03/29/2012 - 09:40
Adding new algebras in submodels and constraining them

Hi.
I am running a bivariate moderation model and would like to set some constraints in order to test for some nonlinear effects. I am struggling though with adding new algebras into submodels (with subsequent equating them). Let's say that I specify

pathAm <- mxMatrix(name = "am", type = "Lower", nrow = nv, ncol = nv, free=T, labels = c("amM","amC","amU"), values=pathVal)
pathCm <- mxMatrix(name = "cm", type = "Lower", nrow = nv, ncol = nv, free=T, labels = c("cmM","cmC","cmU"), values=pathVal)
pathEm <- mxMatrix(name = "em", type = "Lower", nrow = nv, ncol = nv, free=T, labels = c("emM","emC","emU"), values=pathVal)
 
pathAf <- mxMatrix(name = "af", type = "Lower", nrow = nv, ncol = nv, free=T, labels = c("afM","afC","afU"), values=pathVal)
pathCf <- mxMatrix(name = "cf", type = "Lower", nrow = nv, ncol = nv, free=T, labels = c("cfM","cfC","cfU"), values=pathVal)
pathEf <- mxMatrix(name = "ef", type = "Lower", nrow = nv, ncol = nv, free=T, labels = c("efM","efC","efU"), values=pathVal)

and so on in the model CholACEModel (with MZM, DZM, MZF and DZF as submodels).

I would like to introduce certain constraints and test the submodels against CholACEModel:
amC/amM=cmC/cmM=emC/emM=betaM
afC/afM=cfC/cfM=efC/efM=betaF
but am not sure how I should proceed. Let's say I specify

NonlinearEfModel = mxModel (CholACEModel, name='NonlinearEf')
bM = mxAlgebra(amC/amM, name='betaM')
bM = mxAlgebra(cmC/cmM, name='betaM')
bM = mxAlgebra(emC/emM, name='betaM')
 
bF = mxAlgebra(afC/afM, name='betaF')
bF = mxAlgebra(cfC/cfM, name='betaF')
bF = mxAlgebra(efC/efM, name='betaF')

but how should I put all these new algebras into the model? Should I specify MZM, DZM, MZF and DZF models again?

And is it a right way to equate the algebras by giving them the same name? Would that work?

Thank you beforehand!
Julia

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
mxConstraint

Hi Julia,

My understanding is if you want two algebras to be equal, then you use mxConstraint.

bMA = mxAlgebra(amC/amM, name='betaMA')
bMC = mxAlgebra(cmC/cmM, name='betaMC')
bME = mxAlgebra(emC/emM, name='betaME')
bMCon1 <- mxConstraint(betaMA == betaMC, name='Con1MAC')
bMCon2 <- mxConstraint(betaMC == betaME, name='Con2MEC')
 
bFA = mxAlgebra(afC/afM, name='betaFA')
bFC = mxAlgebra(cfC/cfM, name='betaFC')
bFE = mxAlgebra(efC/efM, name='betaFE')
bFCon1 <- mxConstraint(betaFA == betaFC, name='Con1FAC')
bFCon2 <- mxConstraint(betaFC == betaFE, name='Con2FEC')
 
# Add necessary algebras and constraints to model
#...
# Option 1
NonlinearEfModel = mxModel (CholACEModel, name='NonlinearEf',
    bMA, bMC, bME, bMCon1, bMCon2,
    fMA, fMC, fME, fMCon2, fMCon2
)

By constraining betaMA==betaMC and betaMC==betaME, this implies that betaMA==betaME.

With regard to your questions about how to add these, I'd like some clarification. Are you trying to set up a model 'NonlinearEfModel' that is identical to 'CholACEModel', but with these added constraints? That would be Option 1 in the code above. Option 1 does not create a submodel in the OpenMx sense. It creates a new model by adding things to a model that already existed. This is a nested model is the statistical sense: 'NonlinearEfModel' nested as a special case of 'CholACEModel'.

If Option 1 is not what you intended, please let me know so I can help.

Julia's picture
Offline
Joined: 03/29/2012 - 09:40
Hey!Sorry, completely missed

Hey!

Sorry, completely missed your answer! Thanks a lot, this is exactly what I needed!