|
INFO:
This function (runmx) allows users to run MX structural equation program from within the R environment, and to have access to all the matrices and fit functions created by Mx. To run it:
- Start R and run the entire script (runmx.R), below. This places the runmx function in your R workspace. Another way to do this is to paste the entire function into your “Rprofile.site” file, which runs everytime you start up R. You can find “Rprofile.site” in the “etc” folder of your R program folder. You should not have to modify your runmx script or the mx scripts in any way.
- Have the mx file you want to run in your working directory. To change your working directory, so that it is where your mx scripts are, type something like:
> setwd(“C:/Matts Folder/mxr”)
- When you want to run mx, type something like:
> mymatrices <- runmx(“MyFavoriteScript.mx”, “C:/Program Files/MX/bin/MXE.EXE”) OR > mymatrices <- runmx(mx.script=”MyScript.mx”,mx.location=”/usr/local/bin/mxt161i”) (The first argument is your script - if it isn’t in the working directory, you’ll need to supply the full path. The second argument is the location of your MX executable.)
- Mx will now run, and “mymatrices” (in this case) will now be a list that contains all the matrices created during the run. The naming convention is letter then group# then job#. So, for example, C3.2 would be Matrix C from Group 3 in the second run (if you have multiple runs). Also attached to the list will be all fit function values created by Mx (where the number after the period is, once again, the job#).
- If you want easy access to all the matrices & fit functions in the list (“mymatrices” in this case), simply “attach” the list to your environment:
> attach(mymatrices)
TO DO (please send me an email if you have suggestions about additional suggestions, how to do any of these, or if you know how to do the first one):
- Figure out how to automatically find the MXE.EXE executable
- Include Mean, Threshold, and Covariance matrices in the list
- Capture additional output from Mx (e.g., individual likelihoods)
- Capture the Mx algebra for matrices and place these in the list as functions
- Include an option that allows users to only take the matrices from the final job & therefore to not postpend the matrices with “.x” where x is the job #. The options would be FALSE (grab matrices from all jobs), TRUE (grab matrices from final job only), or a vector (grab matrices from only certain jobs, as described by the vector).
- Write another function, perhaps “writemx”, which has a lot of options for changing the Mx script.
- From Mike: Data. It would be good to do better than just write.table for communicating datasets in R to Mx. We could generate the necessary ".dat" file - data line, labels, missing value, and rectangular/ordinal commands for Mx to read in. Plus a few #define's to declare relevant matrix sizes etc. This would make scripts much more model-only and data general. Obviously in the long run we're going to want to do it all with R functions but pro-tem it would be handy
- Have an option that allows you to specify which datafile(s) to run
- Attach the p-values from multiple jobs onto the end
Please let me know: HOW DID THE RUNMX FUNCTION WORK? (I’ve only tried it on a few mx scripts - it may very well crash on yours!).
Downloads:
runmx.R (the function)
R statistical program (http://cran.r-project.org)
Mx statistical program (http://www.vcu.edui/mx) - Apparently runmx crashes on MX version 1.55. You might try downloading the most recent Mx if you have problems.
|