Hi all

As part of a bigger project we are working with applications of mixture models. And we have found that no R package provides all the functionality we need. The only programs so far with all the functionality is LatentGold, but this is a propietary and have working with the license has been complicated

For these reasons we decided to find a way to work as many of these models as possible in R, and found that the most promising way is to develop a package around OpenMx for the types of models we need. So, now we are the process of developing the models, and then have the user friendly functions around it

I wanted to start this thread to ask questions as I find go on this process

So far I have developed Latent Class Analysis (LCA) models for continuous, binary, ordered and nominal indicators. These results are close to the results from LatentGold

The first question I have is about the optimizers, so far I have worked with the **mxExpectationMixture()** function, which uses the quasi-newton optimization routines (if I understand properly). But in LatentGold they use EM with Newton-Raphson (page 56)

Could you help me with these?

- Do you think think this optmization methods would lead to substantial result differences?

- I saw in the **mxComputeEM()** example how to estimate a LCA with EM. But I cant figure out how to add the **mxComputeNewtonRaphson()** to it, in a similar way as it is done for IRT models **mxComputeEM('expectation', 'scores', mxComputeNewtonRaphson())**

Thank you

First off, let me say that I'm pleased to hear of your interest in developing a package around OpenMx. OpenMx has a lot of capabilities that rarely see use, since only a power user would know how to write a script to use them.

You probably know this already, but OpenMx's Newton-Raphson optimizer requires analytic first and second derivatives of the fitfunction being optimized. Presently, only two kinds of models are able to automatically provide such analytic derivatives to the optimizer: IRT models (as you saw), and models that use the GREML expectation and fitfunction. However,

`mxFitFunctionAlgebra()`

has support for user-provided analytic fitfunction derivatives. For perspective, let's take a look at a modification of the example syntax for`mxComputeEM()`

:The above should work, once the comments have been replaced with appropriate MxAlgebra expressions. However, I have never tried anything quite like this before.

As to whether or not it makes a difference to use Newton-Raphson versus quasi-Newton ("gradient descent")...? Well, since Newton-Raphson uses analytic first and second fitfunction derivatives, it will typically be faster (fewer major iterations, fewer fitfunction evaluations) and more numerically accurate. However, OpenMx's Newton-Raphson optimizer does not handle lower and upper bounds ("box constraints") on parameters very well, and is incompatible with explicit MxConstraints. In contrast, OpenMx's three quasi-Newton optimizers have full support for constrained optimization. Also, note that the quasi-Newton optimizers can all optionally use analytic first derivatives of the fitfunction.

I think the same, we want to make some of these complex models more accesible.

Thank you, I see how to make some examples from these models run with Newton-Raphson, but it would take me longer than I want for the first edition of the package. So that it works for all the models I want to make available. Will work on that addition for a future version.

On another issue that is higher priority in our models, is the addition of Hiddent Markov Models (HMM). I am working on applying HMM with multiple subjects in time series. The example from the

mxExpectationHiddenMarkov()function is applied with a single time seriesBut for most scenarios we have multiple subjects time series. My idea was to define the classes as random intercept models as multilevel models based on the time variables. Or should the HMM be define in another way with multiple subjects?

But when I define the model like this I get an error

Here is my model so far

Thanks for all the help!

One way to get this model working is to group all the observations that happen at the same time into a single row. This would remove the multilevel structure from the data. Each row would be independent. The way you coded it, the rows are not independent because there are multiple rows that happened at the same time.

Hi

I was able to make the random intefcept mode work with the wide data format

But this is still not the model I am looking to replicate from HMM. As the model I am looking to replicate is to have multiple subjects with multiple time points. From here the "initial" would be the proportions in each latent class at the first time point, and the "transition" would be the transition between latent classes over time.

So, as another option I attempted to use the long format data, and add the time variable as second level predictor to the initial and transition. But this didnt work as I could only add the time predictor to the initial states and from the data, instead of the second level structure model (similar to this post )

From the

schizophrenia_markov.sav, the results I am trying to rplicate areInitial states

Class[=0]

1 2

0.9919 0.0081

Transitions

Class

Class[-1] 1 2

1 0.8351 0.1649

2 0.0013 0.9987

Not sure how to set up the

mxExpectationHiddenMarkov()correctly hereAppreciate the help

The “this post” you refer to is just a test script. Can you please edit the link?

Sorry for the lack of clarity. Did menat to include that link, as the example code for multilevel regression. But use the wrong wording calling it a post

Trying to apply the multilevel structure in the HMM for estimation with multiple subjects and multiple time points

After talking with colleagues, I found that Caspar van Lissa has added some user friendly mixture modeling with OpenMx in his package tidySEM.

I am working with him on improving and adding more features to this package, including tutorial vignettes.

But I havent been able to work out a Hidden Markov Model when I have multiple items over time, and estimate the transitions between latent states.

Have try:

- random intercept model

- transpose the data

- CFA over time

- growth curve

But none of this have match the expected basic results for a HMM. Would anyone here have a new idea on how to implement this?

Once I have a working example we can translate this into the tidySEM package

Thank you

If I understand correctly what you're after, then there's an example script for that. It's https://github.com/OpenMx/OpenMx/blob/master/inst/models/passing/HMM-multigroup.R which is a multi-subject HMM test script. Essentially, each person has a tall format data set with different rows being different times, and different columns being different variables. Each person has a hidden Markov model that happens to be the same model. Then the people are combined into a multigroup model where each "group" is a person.

One thing to be careful about: free parameters with the same labels are constrained to be equal. If you leave the free parameters unlabeled, they will be different. If you leave your parameters unlabeled by accident, then you could end up estimating separate free parameters for everyone, and it could be quite a large number of parameters.

Good luck!