Convert RAM Model to LISREL

Attachment | Size |
---|---|
openmx_forum_lisrel_example.r | 19.84 KB |
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.
Update to 2.3.1
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!
Log in or register to post comments
In reply to Update to 2.3.1 by mhunter
Thanks - I will definitely
I've tried to upload a file but so far no luck.
Log in or register to post comments
In reply to Update to 2.3.1 by mhunter
I had 2.3.1 installed. To be
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
Log in or register to post comments
In reply to I had 2.3.1 installed. To be by rabil
what is the output of mxVersion()?
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.
Log in or register to post comments
In reply to what is the output of mxVersion()? by tbates
> mxVersion() OpenMx version:
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.
Log in or register to post comments
In reply to I had 2.3.1 installed. To be by rabil
It looks like it installed
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.
Log in or register to post comments
In reply to It looks like it installed by mhunter
Thanks for the clarification.
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.
Log in or register to post comments
Here is a pdf version of the
Log in or register to post comments
In reply to Here is a pdf version of the by rabil
upload files by adding ".txt" extension
Log in or register to post comments