# Convert RAM Model to LISREL

10 posts / 0 new
Offline
Joined: 01/14/2010 - 16:47
Convert RAM Model to LISREL
AttachmentSize
19.84 KB

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.

Offline
Joined: 07/31/2009 - 15:26
Update to 2.3.1

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!

Offline
Joined: 01/14/2010 - 16:47
Thanks - I will definitely

Thanks - I will definitely update.

I've tried to upload a file but so far no luck.

Offline
Joined: 01/14/2010 - 16:47
I had 2.3.1 installed. To be

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

.
.
.

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
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)

Offline
Joined: 07/31/2009 - 14:25
what is the output of mxVersion()?

For me,
mxVersion()
OpenMx version: 2.3.1 [GIT v2.3.1]
R version: R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin13.4.0
MacOS: 10.11
Default optimiser: SLSQP

Which supports RAM in factor scoring.

Offline
Joined: 01/14/2010 - 16:47
> mxVersion() OpenMx version:

> 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.

Offline
Joined: 07/31/2009 - 15:26
It looks like it installed

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.

Offline
Joined: 01/14/2010 - 16:47
Thanks for the clarification.

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.

Offline
Joined: 01/14/2010 - 16:47