MPlus Basics

Doug Hemken

January 2015

Mplus is software devoted to fitting a broad variety of structural equations models. The variety of these models is enormous.

The software is designed to make fairly easy fitting many specialized models within the SEM world: by understanding a few key commands and understanding the defaults for options left unspecified, many models can be fit with just a few lines of code.

In the examples that follow, we will look at simple examples that illustrate the use of the MPlus programming language. Although the commands are specified completely here, much of the output is skipped. To get the most out of the following discussion, run each example yourself using MPlus, and be sure you understand which part of the output illustrates any points that are made.

The Bare Bones

MPlus takes your data from a text file, plus your analysis commands from an input (inp) text file, and produces output in the form of a text file (out) and sometimes a diagram (dgm).

The text file containing your data can come in a few different forms, but at a minimum your input file needs to tell MPlus the name of the file with your data, and the names of the variables it contains.

In addition to pointing to the data, your input file will also typically have a command specifying the model you want to estimate. You will have one model per input file. It is common style to also include a title for each model/file.

Descriptive Stats

Analysis Type Basic

Perhaps the simplest analysis you can do using MPlus is to ask for descriptive statistics for your data. For example, using the ex3.1.dat data file (copy this from C:\Program Files\Mplus\Mplus Examples\User's Guide Examples) (note example 3.1 as written in the User's Guide does not work with the example file)

title: Basic stats
data:  file=ex3.1.dat;
variable: names= x1 x2 x3
analysis:  type=basic

A note on syntax: MPlus commands begin with a keyword and colon, and may include one or more subcommands, or options. These options are terminated with the semi- colon. Although we did not do this above, it is perhaps easiest to just habitually end every command and option with a semi-colon.

Comments are preceeded by an exclamation point.

Output can include a lot of information. Here is just part of the output from the commands above.



              X1            X2            X3
              ________      ________      ________
      1         0.485         0.001        -0.042

              X1            X2            X3
              ________      ________      ________
 X1             2.408
 X2             1.078         1.094
 X3             0.648         0.028         0.957

              X1            X2            X3
              ________      ________      ________
 X1             1.000
 X2             0.665         1.000
 X3             0.427         0.028         1.000


         Variable/         Mean/     Skewness/   Minimum/ % with                Percentiles
        Sample Size      Variance    Kurtosis    Maximum  Min/Max      20%/60%    40%/80%    Median
     X1                    0.485      -0.012      -4.116    0.20%      -0.768      0.070      0.429
             500.000       2.408      -0.136       5.111    0.20%       0.777      1.894
     X2                    0.001      -0.133      -3.145    0.20%      -0.922     -0.235      0.023
             500.000       1.094      -0.162       2.920    0.20%       0.304      0.876
     X3                   -0.042      -0.057      -3.139    0.20%      -0.921     -0.353     -0.040
             500.000       0.957      -0.357       2.875    0.20%       0.274      0.859

Means and Variances Model

Remarkably, there is an even simpler set of commands you could submit. You do not need a title: command, and there is actually a default analysis:. Try

! The simplest MPlus command file
data:  file=ex3.1.dat;
variable: names= x1 x2 x3

Looking at the output below, you should recognize that this is a structural equations model in which all the variables are observed (sometimes called a path model), and in which there are no regression relations or correlations among the observed variables. Therefore this model has fit statistics, and standard errors of each estimated parameter.

A portion of the output is:

                    Estimate       S.E.  Est./S.E.    P-Value
    X1                 0.485      0.069      6.987      0.000
    X2                 0.001      0.047      0.028      0.978
    X3                -0.042      0.044     -0.964      0.335
    X1                 2.408      0.152     15.811      0.000
    X2                 1.094      0.069     15.811      0.000
    X3                 0.957      0.061     15.811      0.000

and MPlus produces an accompanying diagram. Immediately after obtaining output, you can use <Alt-D> to see the model diagram, including many of the estimated parameters.

Descriptive Statistics with Models

Since we are on the topic of descriptive sample statistics, it is worth pointing out that you can obtain them with any modeling command, just by specifying the sampstat option on the output: command.

title: Sample stat output
data:  file=ex3.1.dat;
variable: names= x1 x2 x3;
    x1 on x2 x3;
output: sampstat

produces results from the type=basic analysis, as well as the model results.