LISREL Simulation

Posted on
No user picture. cjcook Joined: 05/22/2017
Hello,

I am trying to simulate data using the endogenous variables only LISREL model as seen on page 133 of the OpenMx.pdf help documentation. I was able to simulate data from a state space model using the example in the help documentation on page 174. Now I am modifying that piece of code for a LISREL model. However I am running into an error. Below is my code.


library(OpenMx)
nvar <- 6
varnames <- paste("x",1:nvar,sep="")
ssModelLisrel <- mxModel(model="lisrel",
mxMatrix("Full",6,6,TRUE,.2,name="BE"),
mxMatrix("Full",6,6,TRUE,.5,name="LY",dimnames=list(varnames,varnames)),
mxMatrix("Diag",6,6,FALSE,1,name="PS"),
mxMatrix("Diag",6,6,FALSE,1,name="TE"),
mxExpectationLISREL(BE="BE",LY="LY",PS="PS",TE="TE"),
mxFitFunctionML()
)

ssDataLisrel <- mxGenerateData(ssModelLisrel,200)

The error I get is:


Error in mxEvalByName(ALname, model, compute = TRUE, defvar.row = defvar.row) :
'name' argument must be a character argument

Below is my current system configuration:
OpenMx version: 2.5.2 [GIT v2.5.2]
R version: R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32
Default optimiser: SLSQP

Any assistance would be greatly appreciated! Thank you!

Replied on Mon, 05/22/2017 - 18:09
Picture of user. mhunter Joined: 07/31/2009

That's not a very friendly or informative error message. Sorry about that! I'll work on generating a better error message for the next release of OpenMx.

It looks like the problem is the model does not have latent means (alpha or AL) or observed intercepts (tau_y or TY). These are needed to generate data. If you're uninterested in these you could simply make them appropriately sized zero matrices.

Replied on Tue, 05/23/2017 - 10:10
No user picture. cjcook Joined: 05/22/2017

Thank you very much for your prompt reply! It is greatly appreciated. Unfortunately when I added both the AL and TY matrices, I still got the same error code. I tried giving them both nonzero values but that also didn't work. Here is the code that I was trying to use when I had zero matrices. I also tried using "Zero" instead of "Full" in the mxMatrix function call for these two matrices to no avail.

ssModelLisrel <- mxModel(model="lisrel",
mxMatrix("Full",6,6,TRUE,.2,name="BE"),
mxMatrix("Full",6,6,TRUE,.5,name="LY",dimnames=list(varnames,varnames)),
mxMatrix("Diag",6,6,FALSE,1,name="PS"),
mxMatrix("Diag",6,6,FALSE,1,name="TE"),
mxMatrix("Full",6,1,FALSE,2,name="AL"),
mxMatrix("Full",6,1,FALSE,2,name="TY"),
mxExpectationLISREL(BE="BE",LY="LY",PS="PS",TE="TE",AL="AL",TY="TY",LX=NA,GA=NA,PH=NA,TD=NA,TH=NA,TX=NA,KA=NA),
mxFitFunctionML()
)

ssDataLisrel <- mxGenerateData(ssModelLisrel,200)

Again, the error code was the same.


Error in mxEvalByName(ALname, model, compute = TRUE, defvar.row = defvar.row) :
'name' argument must be a character argument
<\rsplus>

Please let me know if you have other thoughts for things to try. Thank you very much for your assistance!

Replied on Tue, 05/23/2017 - 13:57
Picture of user. mhunter Joined: 07/31/2009

I got a slightly different error message when I added TY and AL matrices. Instead of complaining about a missing 'ALname', it complained about a missing 'KAname'. This led me to find and squash a couple of bugs.

The short story is there was a bug in the data generation for LISREL models. It only impacted endogenous-only models. I just fixed this bug with [this commit](https://github.com/OpenMx/OpenMx/commit/2acfe924c69f60f709837b86bf4a2696624b8892). Moreover, I added better error messages [with this](https://github.com/OpenMx/OpenMx/commit/f52bfc57a42f071a6db9631b6a8d34c5b3b97e9e) for your first case. Data generation for that case will now produce this:


> ssDataLisrel <- mxGenerateData(ssModelLisrel,200)
Error in mvtnorm::rmvnorm(nrows, theMeans, theCov) :
mean and sigma have non-conforming size
In addition: Warning message:
In genericGetExpected(model[[subname]]$expectation, model, component, :
Means requested, but model has no means.
Add appropriate TX, TY, KA, and/or KA matrices to get real means.

These changes will be part of the next OpenMx release. In the meantime, data generation for the full LISREL model with means would work. You could also specify the model in terms of mxPath statements instead of matrices. It's easy to go back and forth between LISREL and RAM specifications when they are in path form using either type='RAM' or type='LISREL' arguments to mxModel. [This example](https://github.com/OpenMx/OpenMx/blob/master/inst/models/nightly/FactorScores.R#L17:L34) shows a version of the factor model on the OpenMx frontpage specified as a LISREL path model.

Sorry about these bugs! Hopefully this is enough to help you get started.

Replied on Thu, 05/25/2017 - 14:47
No user picture. cjcook Joined: 05/22/2017

Again, thank you very much for your quick replies as well as your assistance! It is greatly appreciated!

I was able to get a RAM model working using the path formation of the model. Again, thank you very much for your assistance!