LISREL Simulation

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!
Add alpha and tau_y
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.
Log in or register to post comments
Added alpha and tau_y - same error code
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!
Log in or register to post comments
Bugs fixed in next release
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 eithertype='RAM'
ortype='LISREL'
arguments tomxModel
. [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.
Log in or register to post comments
RAM Using Path Works
I was able to get a RAM model working using the path formation of the model. Again, thank you very much for your assistance!
Log in or register to post comments