July 29, 2014
Using Mplus on Mac OS X
Mplus for Mac OS X runs from the command prompt. The command prompt in Mac OS X is accessed through the Terminal application. Mplus input and output files can be created and viewed using the TextEdit application.
The Terminal Application
The command prompt in Mac OS X is accessed through the Terminal application. The Terminal application is located in the /Applications/Utilities folder. Open a new Terminal window. The Terminal window opens in your home folder by default. The home folder is /Users/loginname where loginname is your login username. For example, /Users/thuy is my home folder.
Note: The term folder and directory will be used interchangeably throughout this tutorial. A folder is a type of file listed in Finder. In Unix and the command prompt, these folders are often referred to as directories.
Checking the Mplus Version
After opening a Terminal window, start by verifying that the Mplus directory is correctly set on the PATH environment variable. At the prompt, type
The output from the above.command should produce Mplus version and program information.
Mplus Version 6.11 (Mac) Base Program and Combination Add-On
If you get the message 'mplus: command not found', then the PATH environment variable was not set properly or needs to be set manually. Please see the information on Environment Variables. Do not continue with the tutorial until you are able to get the Mplus version and program information with the above command.
Running Mplus with an Mplus Example
Now that you have verified that Mplus runs in the Terminal window, let's start by running one of the Mplus examples. First, use Finder to go into the directory (or folder) where Mplus was installed. By default this is the Applications/mplus6.11 folder in the home folder. The Mplus examples are in the Examples folder. Go into the montecarlo folder in the Examples folder and copy the file 'mcex3.1.inp'. Paste this file into your home folder.
In the Terminal window, type
to verify that the file is there. The ls command lists the contents of the current folder.
If you get the message 'mcex3.1.inp: No such file or directory', then either you are not in the home directory in the Terminal window or you have not pasted the mcex3.1.inp into the home folder in Finder. To check the current directory in the Terminal window, type the command
Once you have successfully copied the mcex3.1.inp file into the home directory and is able to see the file with the ls command in the Terminal window, then type
You should see the following screen output:
Mplus VERSION 6.11 (Mac) MUTHEN & MUTHEN Running input file 'mcex3.1.inp'... Beginning Time: 01:37:38 Ending Time: 01:37:38 Elapsed Time: 00:00:00 Output saved in 'mcex3.1.out'.
This shows a successful Mplus run. As indicated, the output is stored in the file 'mcex3.1.out'. You can locate this file in Finder and view it in TextEdit. To open the file in TextEdit from the command prompt, type the following command
Running Mplus in a Different Folder
It is not necessary to run Mplus in the Terminal window only in the home directory. You can run Mplus anywhere. To start, go into Finder and create a new folder called 'MplusAnalyses'. Copy the Mplus example ex3.1.inp in the Applications/mplus6.11/Examples/usersguide folder into this folder. Be sure to also copy the data file ex3.1.dat.
Now open a new Terminal window. By default, the Terminal shell will start in the home folder. You can change the current directory in the shell window by using the cd command. Change the current directory to the MplusAnalyses directory.
Note: File and folder names on the Mac OS X are case-sensitive. So MplusAnalyses is different from mplusanalyses. Also, spaces in file and folder names must be considered specially. When a file or folder contains spaces, either put the entire file/folder name in quotes or preceed each space character with the character \. For example, if the folder name is Mplus Analyses, then we can type one of the following:
Tip: Most Unix shells including the one in the Terminal window have support for tab completion of file and folder names. When typing a filename, you can type the first few characters that are unique to that filename and then use the TAB key to have the shell complete the filename. For example, in the command above, we can type cd MplusA followed by the TAB key and the rest of the folder name will be filled in automatically.
When you have changed the current directory in the Terminal window to MplusAnalyses, use the pwd command to verify the current location.
Before running Mplus, verify that you have copied the file ex3.1.inp into this directory.
If you get the message 'ex3.1.inp: No such file or directory', then go back into Finder and make sure you have copied this file from the Applications/mplus6.11/Examples/usersguide folder.
Now run Mplus on ex3.1.inp.
You should see the following screen output:
Mplus VERSION 6.11 (Mac) MUTHEN & MUTHEN Running input file 'ex3.1.inp'... Beginning Time: 01:37:38 Ending Time: 01:37:38 Elapsed Time: 00:00:00 Output saved in 'ex3.1.out'.
In Finder, you can find the Mplus output file ex3.1.out in the folder MplusAnalyses.
Location of the Data Files
In the previous example, we copied both the input file ex3.1.inp and data file ex3.1.dat into the MplusAnalyses folder. It is not necessary to have the data file be in the same folder as the input file.
Go into Finder and copy the example ex3.2.inp from the Applications/mplus6.11/Examples/usersguide folder into the MplusAnalyses folder. But this time, do not copy the data file ex3.2.dat for this example. Now open the file ex3.2.inp in TextEdit. We will edit the FILE option to point to the location of the data file. Note that it is also possible to open ex3.2.inp in TextEdit from the command prompt in Terminal.
Change the FILE option from
FILE IS ex3.2.dat;
FILE IS /Users/thuy/Applications/mplus6.11/Examples/usersguide/ex3.2.dat;
remember to replace thuy with your own login name. You can also use ~ inplace of /Users/thuy. For example:
FILE IS ~/Applications/mplus6.11/Examples/usersguide/ex3.2.dat;
Now in the Terminal window, verify that you are in the MplusAnalysis folder by using the
Mplus VERSION 6.11 (Mac) MUTHEN & MUTHEN Running input file 'ex3.2.inp'... Beginning Time: 01:37:38 Ending Time: 01:37:38 Elapsed Time: 00:00:00 Output saved in 'ex3.2.out'.
Keeping Mplus Output Files in a Separate Folder
By default, Mplus creates the output files in the folder where Mplus is run. In previous examples, we have run Mplus in the folder where the input files resides. If you want to run Mplus and have the output files be created in a different folder than where the input file resides, then you can run Mplus in one of the following ways.
First, let's create an Output folder inside the MplusAnalyses folder in Finder. Then go into the Terminal window and change directory to the Output folder. If you have left opened the Terminal window from the previous run and the current directory is the MplusAnalyses folder, then first change the current folder to the Output folder:
Then run Mplus on ex3.3.inp which resides in the ~/Applications/mplus6.11/Examples/usersguide folder. Since ex3.3.inp is not in the current folder, we need to specify the full path of the input file on the command line.
Mplus VERSION 6.11 (Mac) MUTHEN & MUTHEN Running input file '/Users/thuy/Applications/mplus6.11/Examples/usersguide/ex3.3.inp'... Dimensions of integration: 0 Total number of integration points: 1 ITER LOGLIKELIHOOD ABS CHANGE REL CHANGE ALGO TIME TOTAL TIME 1 -0.79640717D+03 0.0000000 0.0000000 EM 0.01 0.0 2 -0.50152551D+03 294.8816580 0.3702649 EM 0.00 0.0 3 -0.50152543D+03 0.0000873 0.0000002 EM 0.00 0.0 Parameters 7 6 5 2 1 Derivatives 0.42D-06 -0.25D-06 -0.14D-06 0.51D-07 -0.49D-07 Beginning Time: 09:58:21 Ending Time: 09:58:21 Elapsed Time: 00:00:00 Output saved in 'ex3.3.out'.
On the line "Running input file", Mplus prints out the full path of the input file.
Another way to redirect the Mplus output to a file or folder different than the default is to specify a third argument on the command line. For example, we can run the above example but have the output be saved in a different file.
Mplus VERSION 6.11 (Mac) MUTHEN & MUTHEN Running input file '/Users/thuy/Applications/mplus6.11/Examples/usersguide/ex3.3.inp'... Dimensions of integration: 0 Total number of integration points: 1 ITER LOGLIKELIHOOD ABS CHANGE REL CHANGE ALGO TIME TOTAL TIME 1 -0.79640717D+03 0.0000000 0.0000000 EM 0.00 0.0 2 -0.50152551D+03 294.8816580 0.3702649 EM 0.00 0.0 3 -0.50152543D+03 0.0000873 0.0000002 EM 0.00 0.0 Parameters 7 6 5 2 1 Derivatives 0.42D-06 -0.25D-06 -0.14D-06 0.51D-07 -0.49D-07 Beginning Time: 10:13:28 Ending Time: 10:13:28 Elapsed Time: 00:00:00 Output saved in 'ex3.3new.out'.
Note the mention of ex3.3new.out on the command prompt. And Mplus states that the output is saved in this file. You can also specify a folder name and an output filename as the third argument on the command line. First, let's create a new folder in the Output folder called MonteCarlo in Finder. Now run Mplus on the Monte Carlo example mcex3.4.inp.
Mplus VERSION 6.11 (Mac) MUTHEN & MUTHEN Running input file '/Users/thuy/Applications/mplus6.11/Examples/montecarlo/mcex3.4.inp'... Beginning Time: 10:38:14 Ending Time: 10:38:14 Elapsed Time: 00:00:00 Output saved in 'MonteCarlo/mcex3.4.out'.
You will find the output mcex3.4.out in the MonteCarlo folder.
In general, if you want to have Mplus output files in a different folder than input files, it is better to run Mplus from the output folder and just specify the full path of the input file. That way, if the input setup contains any SAVEDATA requests or PLOT requests, all files produced from the Mplus run will be found in the same folder.