Skip to content
Mehul Gajwani edited this page Mar 14, 2024 · 3 revisions

Mplus

The purpose of this document is to give a basic rundown of how to use Mplus on MASSIVE. I will write about:

  • Why it is used over other Structural Equation Modelling (SEM) software
  • Basic demo – Confirmatory Factor Analysis
  • Where to get help when stuck

This document is not intended to showcase all of Mplus’ capabilities, or to help you with writing out code for your specific analysis type per se; Mplus can handle MANY different analysis types, for which there is extensive documentation available elsewhere (which I will discuss in this document).

Introduction to Mplus – and why I use it over other SEM packages

So - you want to learn how to do structural equation modelling (SEM) in Mplus. Great! I have put together some basics on how to use it on MASSIVE M3.

Firstly, I would like to note that there are alternative software packages that can also run SEMs. However, in software packages such as Jasp and SPSS, there seems to be a limit to the level of model complexity and flexibility you can achieve – something some of the students in BrainPark seem to have struggled with. There is also R – which is free to use, and for which there are many, many packages, but in my experience, it can be a bit of a headache to work out how to use them – especially if your model or technique is quite complicated. The documentation for Mplus is much more user friendly than the documentation for the various packages available on CRAN for the same analyses you may be wanting to run – so you will generally spend less time trying to figure out how to run things, and more time running actual analyses. Often, it may be easier to prep your data on software such as R, then move to Mplus when you are ready to run your SEMs.

You need to request that your profile on MASSIVE has access to the Mplus software. Email Chao to request that this access is granted to you.

Mplus Demo on MASSIVE

You can run analyses such as confirmatory factor analyses, correlations, and regressions.

Let’s run through a Confirmatory Factor Analysis example. For example, maybe you have 10 items measuring depression, and they converge on a single factor (a unidimensional model of depression). You have also taken participant age, participant sex, family of origin socioeconomic status, and current socioeconomic status. Let’s assume you have just finished cleaning your data (i.e. imputed missing data when appropriate, etc). Let’s have a look at how this .csv datafile should then be structured for subsequent Mplus analyses:

Notice how the dataset has every single cell filled, and there are no column headers in this file (i.e., mone of the columns head with column titles). This is intentional. Mplus does not like empty cells (cells with NaN values), and it does not like it if your datafile contains cells that contain text (including for column names). I have filled all empty cells here with -999 – and will tell Mplus later that -999 represents missingness. I will also specify column names later on in the .inp file – the file that will execute the analyses using this .csv file as input.

Let’s now make the accompanying .inp file (i.e. touch mplus_demo.inp from terminal). Open up the file and start writing. Follow the example structure below.

Lines cannot exceed 90 characters (you can break up extensive sections of writing in the same section by just hitting enter and finishing the section with a semicolon)

The file location is wrapped in “”

Many of the lines end with a semicolon (;) – this is important for correct syntax.

The names of each of the columns are specified using NAMES ARE in your .inp file – for example, in the .inp file above, ‘age’ is the name for the first column, ‘sex’ is the name for the second column, ‘ses_f’ is the name for the third column, etc.

In this demo, we will not include the demographic variables in the analysis. We have told Mplus to only use the variables between depr1 and depr10 in NAMES ARE by invoking USEVARIABLES ARE.

  • We have told Mplus that missingness is represented by -999.
  • We have told Mplus we want to use a maximum likelihood estimator.
  • We have created a factor by specifying that the factor depr_f is created “by” all of the depression variables.

Once you have the .csv file and the .inp file ready, you can load Mplus in terminal by typing module load mplus.

You can then run your .inp file from terminal (there is NO GUI for this program on MASSIVE) by navigating to the relevant directory and typing mplus x.inp, where x stands for your .inp file. For example, mplus mplus_demo.inp.

You will get an .out file in that directory containing your model results (or errors).

You must check your output to ensure that your model has terminated normally. It may not have terminated normally if you get a warning. If you get output saying that the model estimates “may not be trustworthy” – they are probably not trustworthy. The model must terminate normally – or you will need to seek advice/look at different ways of modelling your data.

This concludes the example for a CFA. Let’s say you instead want to correlate two variables - this would be achieved by using the “with” command in the analysis section (i.e. a variable goes “with” another; they are co - related): e.g. depr1 with depr2.

Let’s say you want to regress two variables – this would be achieved by using the “on” command (i.e. a variable y depends “on” variable x): e.g. depr1 on depr2.

One annoying thing about Mplus on MASSIVE is that you cannot visualise plots there (Mplus has this issue with Linux based systems). You can get the output file which contains the plot you requested, but you will have to move to R to visualise it; see here: https://www.statmodel.com/mplus-R/

Where to get help when stuck

The documentation for the various types of analyses you can run on Mplus is extensive. If there is a model you have heard about that you believe would be appropriate for your circumstances, but you’re unsure on how to implement it, I strongly recommend consulting the Mplus users guide; available at https://www.statmodel.com/html_ug.shtml

The code is explained pretty well below each of the examples in the users guide (e.g. how to specify if a variable is zero-inflated, how to set factor variance to 0, how to test k-1 classes in latent class analyses, etc).

There are also a few forums on the statmodel website you can review in case you are having a particular problem with your model. Just type your problem into Google and see what comes up; for example, I had a problem with Bootstrap Convergence, and found the following forum helpful;

Pages like this may also be useful to you if you get stuck on some of the language in Mplus: https://www.statmodel.com/language.html

There are also a few freely available tutorials on the statmodel website: https://www.statmodel.com/course_materials.shtml

Clone this wiki locally