In this post I am going to walk through the steps of fitting a structural equation model (SEM) in Q. The post assumes that you already know what a SEM is and how to interpret it.

Case study

In the post I am going to analyze Bollen's famous Political Democracy data set (Kenneth Bollen (1989), Structural Equations with Latent Variables, Wiley.)

Step 1: Load the data

Typically data sets are loaded into Q from raw data files. But, in this case we will load some data that is stored in an R package.

  • File > Data Sets > Add to Project > From R
  • Name: BollenPoliticalDemocracy
  • Paste in the code below into the R CODE box
  • Press the blue play button (the triangle at the top of the code)
  • Press Add Dataset
  • Choose the Automatically detect data file structure option and click OK.

Step 2: Fit the model

The hard step is fitting the model, as this requires you to specify the measurement model, the relationships to be tested (i.e., the regressions), and the correlation structure of the model. For more information about this, please check out the lavaan website.

To do this:

  • Create > R Output
  • Paste in the code below
  • Press Calculate

Step 3: Review the path diagram

In order to check that the model has been correctly specified it's a good idea to review the path diagram.

  • Create > R Output
  • Paste in the code below
  • Press Calculate

Step 4: Extract the summary statistics

  • Create > R Output
  • Paste in the code below
  • Press Calculate
  • In the Object inspector, on the right of your screen, click Inputs > APPEARANCE and set the font to Courier New, so that the text aligns neatly.