Mixed effects model - matrix specification

Posted on
No user picture. IvanVoronin Joined: 08/18/2013

Hello,

I am looking for advice with regard to the implementation of mixed effects model in OpenMx. 

I am starting with a simple model where one dependent variable Y is predicted by four correlated variables X1-X4. The participants in the sample are clustered in pairs (they are twins).

I have a working path specification of this model based on the code that found on the Internet, possibly on this forum. But I am struggling to translate it into the matrix form. Specifically, I cannot understand how the arguments joinKey and joinModel in mxMatrix and mxAlgebra connect the parameters related to the random intercept to the algebra or matrix within the main model.

The working example is in the attachment. It simulates the data and runs the path specification of the model. The script also has a 'draft' of the matrix specification of the same model, as well as the model implemented with lme4 for the reference.

Any advice or guidance on this problem is greatly appreciated!

Thank you!

Ivan

Replied on Fri, 01/17/2025 - 12:27
No user picture. IvanVoronin Joined: 08/18/2013

After researching this, I realized that the matrix specification of the model is possible when it uses mxExpectationRAM.

So the followup question is: Is it possible to implement the same with mxExpectationML? I have several models that I wish to extend to account for the twins' clustering in the sample, where the expected covariance matrix is not computed as RAM.

Replied on Mon, 01/20/2025 - 14:17
No user picture. IvanVoronin Joined: 08/18/2013

Turned out that the existing expected covariance matrix can be used in place of the S-matrix in the RAM implementation of the model. Thus, I attach a working example with two implementations of the model (path and matrix) that provide very similar estimates. This script was very helpful to make it work.

Still, I have only the approximate idea of how it all works inside, so any further insight or a relevant example are greatly appreciated.

Replied on Tue, 01/21/2025 - 15:05
Picture of user. AdminNeale Joined: 03/01/2013

Thank you for this helpful contribution, Ivan!  This paper by Mike Hunter may be useful: https://pubmed.ncbi.nlm.nih.gov/33609197/

The basic idea behind OpenMx's implementation of multilevel models is that it's analogous to what one does with a relational database.  A table with rows of data in it will typically have a primary key that is unique to the table.  To attach a different level's (say family) data to a subject-level record, a join must occur, and the join key is used to make that happen.  These are different so that one can build truly multilevel models rather than simply two-level as is the limit for some of the other software offerings.  I hope this helps to improve your understanding of how it all works!