Convert RAM Model to LISREL

Posted on
Picture of user. rabil Joined: 01/14/2010
I need to compute factor scores which only works in OpenMx if the model type is LISREL. I've attached the model code that includes creating a path diagram for the RAM version. The RAM model code works fine in estimating the parameters. When I convert it to "type="LISREL"", I get various error messages.

This shows the specification for the endogenous and exogenous variables in the LISREL version:

manifestVars=list(
endo=c("c_el","c_nc_el","c_or","c_nc_or",
"c_el_1","c_el_nc_1","c_or_1","c_or_nc_1"),
exo=c("t0s1","t0s2","t0s3","t0s4",
"t1s1","t1s2","t1s3","t1s4",
"t2s1","t2s2","t2s3","t2s4",
"t3s1","t3s2","t3s3","t3s4")
),

latentVars=list(endo=c("mu_e","mu_o"),exo=c("mu_e_1","mu_o_1")),

From the path diagram for the RAM version, it appears (at least to me) that manifest variables t0s1, t0s2, ... , t3s4 are all exogenous and latent variables mu_e_1 and mu_o_1 are exogenous. All the remaining variables are endogenous. Yet when I paste the LISREL model code into R:

Error: non-square MxMatrix attempted in 'nrow' and 'ncol' arguments to mxMatrix(matrixtype, values = values, free = free, labels = labels, name = matrixname)

Not sure where I am going wrong. I also tried to convert from RAM model to a LISREL model by changing the model type to LISREL after saving the RAM model, but this also did not work.

carbon.temp.ar.model.6.mat <- mxModel(carbon.temp.ar.model.6,type="default")
carbon.temp.ar.model.6.lisrel <- mxModel(carbon.temp.ar.model.6.mat,type="LISREL")

But this fails (after a few minutes) when I try to fit the lisrel model:

> mxRun(carbon.temp.ar.model.6.lisrel)
Running Carbon Temperature AR Model 6 with 91 parameters
Error in model@manifestVars$exogenous :
$ operator is invalid for atomic vectors

I was able to obtain a LISREL model version for a simpler related model (no t0s1, etc. variables and only two latent variables mu_e and mu_o) and then compute the factor scores. Although this worked only by specifying ALL of the manifest and latent variables as exogenous.

Obviously, there is something I am missing.

Replied on Wed, 10/28/2015 - 15:13
Picture of user. mhunter Joined: 07/31/2009

I'd love to figure out what's going wrong in your model. However, it will be quicker for you to update to OpenMx 2.3.1. RAM factor scores are implemented in that version with the same mxFactorScores function.

Let us know if that works or doesn't. Also, it would help me if you attached either the .dot file for the plot of the model or an image of its diagram.

Cheers!

Replied on Thu, 10/29/2015 - 10:59
Picture of user. rabil Joined: 01/14/2010

In reply to by mhunter

I had 2.3.1 installed. To be safe, I re-installed it. (There are some warnings and 1 error but it appears to install - see below).

But mxFactorScores does not work and says it only works with LISREL models:

> factor.scores.ml <- mxFactorScores(carbon.temp.ar.fit.6,type="ML")
Error in free[i, j] : subscript out of bounds
> factor.scores.ml <- mxFactorScores(carbon.temp.ar.fit.6,type="Regression")
Error in mxFactorScores(carbon.temp.ar.fit.6, type = "Regression") :
Regression factor scores are only possible for LISREL expectations.

Here are the messages I received when I installed OpenMx 2.3.1:

g++ -I/usr/share/R/include -DNDEBUG -I"/home/rick/R/x86_64-pc-linux-gnu-library/3.2/RcppEigen/include" -I"/home/rick/R/x86_64-pc-linux-gnu-library/3.2/StanHeaders/include" -I"/home/rick/R/x86_64-pc-linux-gnu-library/3.2/BH/include" -fopenmp -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-parameter -Wvla -Wno-unused-local-typedefs -fdiagnostics-color=auto -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c omxStateSpaceExpectation.cpp -o omxStateSpaceExpectation.o
omxStateSpaceExpectation.cpp: In function \u2018void omxPopulateSSMAttributes(omxExpectation*, SEXP)\u2019:
omxStateSpaceExpectation.cpp:179:7: warning: variable \u2018numVarsFilled\u2019 set but not used [-Wunused-but-set-variable]
int numVarsFilled = 0;
^
omxStateSpaceExpectation.cpp:274:7: warning: variable \u2018numVarsFilled\u2019 set but not used [-Wunused-but-set-variable]
int numVarsFilled = 0;
^
g++ -I/usr/share/R/include -DNDEBUG -I"/home/rick/R/x86_64-pc-linux-gnu-library/3.2/RcppEigen/include" -I"/home/rick/R/x86_64-pc-linux-gnu-library/3.2/StanHeaders/include" -I"/home/rick/R/x86_64-pc-linux-gnu-library/3.2/BH/include" -fopenmp -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-parameter -Wvla -Wno-unused-local-typedefs -fdiagnostics-color=auto -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c omxSymbolTable.cpp -o omxSymbolTable.o
g++ -I/usr/share/R/include -DNDEBUG -I"/home/rick/R/x86_64-pc-linux-gnu-library/3.2/Rcpp

.
.
.

gfortran -lm -lquadmath -L/usr/lib/R/lib -lR
mkdir -p ../inst/debug
cp *.gcno ../inst/debug/
cp: cannot stat \u2018*.gcno\u2019: No such file or directory
Makevars:40: recipe for target 'save-gcno' failed
make: [save-gcno] Error 1 (ignored)
installing to /home/rick/R/x86_64-pc-linux-gnu-library/3.2/OpenMx/libs
** R
** data
*** moving datasets to lazyload DB
** demo
** inst
** preparing package for lazy loading
Creating a generic function for \u2018print\u2019 from package \u2018base\u2019 in package \u2018OpenMx\u2019
Creating a generic function for \u2018nrow\u2019 from package \u2018base\u2019 in package \u2018OpenMx\u2019
Creating a generic function for \u2018ncol\u2019 from package \u2018base\u2019 in package \u2018OpenMx\u2019
Creating a generic function for \u2018summary\u2019 from package \u2018base\u2019 in package \u2018OpenMx\u2019
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (OpenMx)

The downloaded source packages are in
\u2018/tmp/RtmpVyt23Y/downloaded_packages\u2019

Replied on Thu, 10/29/2015 - 12:05
Picture of user. rabil Joined: 01/14/2010

In reply to by tbates

> mxVersion()
OpenMx version: 2.3.1 [GIT v2.3.1]
R version: R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu
Default optimiser: SLSQP

?mxFactorScores
mxFactorScores package:OpenMx R Documentation

Estimate factor scores and standard errors

Description:

This function creates the factor scores and their standard errors
under different methods for an MxModel object that has either a
RAM or LISREL expectation.

Replied on Thu, 10/29/2015 - 14:04
Picture of user. mhunter Joined: 07/31/2009

In reply to by rabil

It looks like it installed fine. That warning shouldn't matter for you.

I'm not sure why you're getting the


> factor.scores.ml <- mxFactorScores(carbon.temp.ar.fit.6,type="ML")
Error in free[i, j] : subscript out of bounds

I haven't been able to replicate this error. One thing you could try is to use mxGenerateData() to generate data from your model. Then attach those data so I can run your model and see what the problem may be.

For the other error, Regression Factor Scores are not implemented for RAM models, only ML and WeightedML. Similarly, LISREL factor scores are only implemented for exogenous-only LISREL models; that is, factor models.

Lastly, the diagram you attached is not possible in LISREL. The LISREL path spec in OpenMx should be giving you an intelligent error message about this. It looks like this may be a possibility I missed in my error handling. The path diagram is not possible in LISREL because it has paths from manifest variables to latent variables. LISREL does not allow this ever. This seems to be a widespread misunderstanding about LISREL. MPlus allows this; LISREL does not. To do this in LISREL, you must create dummy exogenous latent variables for each of these manifest variables.

If you attach some fake data (via mxGenerateData), I'll track down the bug I'm missing.

Replied on Thu, 10/29/2015 - 15:21
Picture of user. rabil Joined: 01/14/2010

In reply to by mhunter

Thanks for the clarification. Now I understand why I couldn't get the LISREL model to work (but it worked for my other model where none of the latent factors depended on observed variables).

I've uploaded the model and 500 rows of generated data. I tweaked some of the starting values in the model. It runs without any errors or warnings.

Thanks for you help.

Replied on Thu, 10/29/2015 - 11:28
Picture of user. rabil Joined: 01/14/2010

Here is a pdf version of the dot file. (The forum doesn't allow uploading .dot files and pasting the dot file code into the post causes a spam alert and prevents posting the message.)