Is there a way to add covariates in growth mixture model

Posted on
No user picture. Veronica_echo Joined: 02/23/2018
Hi,

I have a script for the 2-class growth mixture model (please see attached). I am wondering if I can add covariate (say x1) as a covariate of my model. I may want to see the effect of x1 on the latent classes only and also of it on both latent classes and the growth factors. As my understanding, in MPlus, the first scenario can be expressed as "c#1 on x1" and the second one can be written as "c#1 on x1" and "int on x1; slp on x1" of each class, but I have zero idea to translate to OpenMx. Any advice would be appreciated.

Replied on Sun, 11/18/2018 - 22:54
Picture of user. mhunter Joined: 07/31/2009

I would change


classP <- mxMatrix( type = "Full", nrow = 2, ncol = 1,
free=c(TRUE, FALSE), values=1,
labels = c("p1","p2"), name = "weights" )

to


classPM <- mxMatrix( type = "Full", nrow = 2, ncol = 2,
free=c(TRUE, FALSE,TRUE,TRUE), values=1,
labels = c("p11","p21", "p12", "p22"), name = "weightsM" ) #Edited from original which had a typo
classPV <- mxMatrix(nrow=2, ncol=1, labels=c(NA, "data.X1"), values=1, name="weightsV")
classP <- mxAlgebra(weightsM %*% weightsV, name="weights")

The R object `classPM` is a 2x2 matrix of the base weights: the first row is for the first class; the second row is for the second class. The first column of `weightsM` gets multiplied by 1; the second column gets multiplied by the variable `X1`. This results in the R object `classP` and the OpenMx object `weights`. Include `classPM`, `classV`, and `classP` in the `gmm2` model accordingly.

Replied on Mon, 11/26/2018 - 10:19
No user picture. Veronica_echo Joined: 02/23/2018

In reply to by mhunter

Hi Michael,

Thanks for your kind reply. I tried to update my codes but got an error: "In model 'GMM2Class' the name 'p21' is used as a free parameter in 'GMM2Class.weightsM' and as a fixed parameter in 'GMM2Class.weightsM'". I don't know why. I am attaching script and data I used, could you kindly help me to figure it out? Thank you very much!

File attachments
Replied on Mon, 11/26/2018 - 12:16
Picture of user. AdminRobK Joined: 01/24/2014

In reply to by Veronica_echo

This syntax appears to be the culprit:

classPM <- mxMatrix( type = "Full", nrow = 2, ncol = 2,
free=c(TRUE, FALSE,TRUE,TRUE), values=1,
labels = c("p11","p21", "p21", "p22"), name = "weightsM" )

Try changing one of the redundant "p21" labels to something else ("p12", perhaps?).
Replied on Thu, 11/29/2018 - 16:14
No user picture. Veronica_echo Joined: 02/23/2018

In reply to by mhunter

Hi Michael,

I also tried to write several lines to estimate $\beta$'s from above formula (please see the attached), which may have initial value or model specification issue. Do you have tips about it? Any advice would be appreciate.

File attachments
Replied on Sun, 12/02/2018 - 23:10
Picture of user. mhunter Joined: 07/31/2009

In reply to by Veronica_echo

It looks like your code is using an algebra fit function instead of the built-in mixture modeling. See relevant section from your code below.


classBeta <- mxMatrix(type = "Full", nrow = 2, ncol = 3,
free = c(F, T, F, T, F, T), values = c(0, 0, 0, 1.2, 0, 0.9),
labels = c("beta10", "beta20", "beta11", "beta21", "beta12", "beta22"),
name = "classbeta")
classPV <- mxMatrix(nrow = 3, ncol = 1, labels = c(NA, "data.x1", "data.x2"),
values = 1, name = "weightsV")
classP <- mxAlgebra(exp(classbeta %x% weightsV), name = "weights") # Note: MH thinks this should be %*% not %x%
classS <- mxAlgebra(weights %x% (1/sum(weights)), name = "classProbs")
algebraObjective <- mxAlgebra(-2 * sum(log(classProbs[1,1] %x% Class1.objective +
classProbs[2,1] %x% Class2.objective)),
name = "mixtureObjective")
objective <- mxFitFunctionAlgebra("mixtureObjective")

I would change this to


classBeta <- mxMatrix(type = "Full", nrow = 2, ncol = 3,
free = c(F, T, F, T, F, T), values = c(0, 0, 0, 1.2, 0, 0.9),
labels = c("beta10", "beta20", "beta11", "beta21", "beta12", "beta22"),
name = "classbeta")
classPV <- mxMatrix(nrow = 3, ncol = 1, labels = c(NA, "data.x1", "data.x2"),
values = 1, name = "weightsV")
classP <- mxAlgebra(classbeta %*% weightsV), name = "weights")
expec <- mxExpectationMixture(c('Class1', 'Class2'), weights='weights', scale='softmax')
objective <- mxFitFunctionML()