Structural Equation Modeling | Exercises 1

1 What we are going to do

  1. Ex.1 – Local Model Fit
  2. Ex.2 – Calculate the model-implied covariance matrix
  3. Ex.3 – 1-factor- vs 2-factor-model
  4. Ex.4 – Fit a second-order CFA
  5. Ex.5 – Compare second-order with first-order CFA

2 Dataset

The data set used throughout is still the European Social Survey ESS4-2008 Edition 4.5. We will restrict the analysis to the Belgian case.

Codebook:

  • gvslvol Standard of living for the old, governments’ responsibility (0 Not governments’ responsibility at all - 10 Entirely governments’ responsibility)

  • gvslvue Standard of living for the unemployed, governments’ responsibility (0 Not governments’ responsibility at all - 10 Entirely governments’ responsibility)

  • gvhlthc Health care for the sick, governments’ responsibility (0 Not governments’ responsibility at all - 10 Entirely governments’ responsibility)

  • gvcldcr Child care services for working parents, governments’ responsibility (0 Not governments’ responsibility at all - 10 Entirely governments’ responsibility)

  • gvjbevn Job for everyone, governments’ responsibility (0 Not governments’ responsibility at all - 10 Entirely governments’ responsibility)

  • gvpdlwk Paid leave from work to care for sick family, governments’ responsibility (0 Not governments’ responsibility at all - 10 Entirely governments’ responsibility)

  • sbstrec Social benefits/services place too great strain on economy (1 Agree strongly - 5 Disagree strongly)

  • sbbsntx Social benefits/services cost businesses too much in taxes/charges (1 Agree strongly - 5 Disagree strongly)

  • sbprvpv Social benefits/services prevent widespread poverty (1 Agree strongly - 5 Disagree strongly)

  • sbeqsoc Social benefits/services lead to a more equal society (1 Agree strongly - 5 Disagree strongly)

  • sbcwkfm Social benefits/services make it easier to combine work and family (1 Agree strongly - 5 Disagree strongly)

  • sblazy Social benefits/services make people lazy (1 Agree strongly - 5 Disagree strongly)

  • sblwcoa Social benefits/services make people less willing care for one another (1 Agree strongly - 5 Disagree strongly)

  • sblwlka Social benefits/services make people less willing look after themselves/family (1 Agree strongly - 5 Disagree strongly)

3 Environment preparation

First, let’s load the necessary packages to load, manipulate, visualize and analyse the data.

# Uncomment this once if you need to install the packages on your system 

### DATA MANIPULATION ###
# install.packages("haven")                 # data import from spss
# install.packages("dplyr")                 # data manipulation
# install.packages("psych")                 # descriptives
# install.packages("stringr")               # string manipulation

# ### MODELING ###
# install.packages("lavaan")                # SEM modelling
# install.packages("lavaan.survey")         # Wrapper around packages lavaan and survey

# ### VISUALIZATION ###
# install.packages("tidySEM")               # plotting SEM models
# install.packages("corrplot")              # correlation plots


# Load the packages 

### DATA MANIPULATION ###
library("haven")        
library("dplyr")      
library("psych")
library('stringr')

### MODELING ###
library("lavaan")       

### VISUALIZATION ###
library("tidySEM")
library("corrplot")     

4 Ex.1 – Local Model Fit

  1. Fit the welfare support model with 6 items
  2. Modify the model by allowing error correlations and refit the model
  3. Review the parameter estimates and compare to the first model
  4. Review the fit statistics (global and local)
  5. Verify that the new model indeed fits the data better (perform a chi-squared difference test)
  6. Consider modifying the model even further based on the MIs, revise the model further. Describe its implications (OPTIONAL)
ess_df <- haven::read_sav("https://github.com/albertostefanelli/SEM_labs/raw/master/data/ESS4_belgium.sav")

model_ws_6_1 <-'welf_supp =~ gvslvol + gvslvue + gvhlthc + gvcldcr + gvjbevn + gvpdlwk'


fit_ws_6_1 <- cfa(,               # model formula
                 data=            # data frame
  )

5 Ex.2 – Calculate the model-implied covariance matrix

  1. For the previous models, request the model-implied covariance of the matrix using lavaan’s inspect function.
  2. Calculate the model-implied covariance matrix using the formula:
  3. Compare the two matrices
  4. Calculate the differences between the two matrices (OPTIONAL)
# model-implied var-covariance matrix for observed variables
inspect(, "cov.ov") 

6 Ex.3 – 1-factor- vs 3-factor-model

  1. Using the welfare criticism items, fit a 1-factor model.
  2. Using the welfare criticism items, fit a 3-factor model.
  3. Verify whether a 1-factor CFA model is appropriate.
    • Review the model parameters.
    • Compare the model fit statistics using a tabular form.
  4. Modify the 3-factor model by dropping items and/or allowing error correlations and compare it with the original model (OPTIONAL)
model_wc_1_factor <-'
wc_crit =~ 
'

7 Ex.4 – Second order model

  1. Fit a second-order model with the three dimensions of welfare criticism.
  2. Review the model output using the summary function. Does the model fit well?
  3. Review the \(R^2\) values of the first-order latent variables. Which first-order factor is explained best by the second-order factor?
  4. Request model modification indices and explore model modifications.
  5. Remove low loadings and see if the model improves (OPTIONAL)
model_wc_2_order <-'
## Economic criticism ##
wc_econo =~
## Social criticism ## 
wc_socia =~ 
##  Moral criticism ##
wc_moral =~
## Second Order Welfare Criticism ## 
wc_crit =~ 
'

8 Ex.5 – Compare first-order with second-order model

  1. How many degrees of freedom are lost between the two models? Why?
  2. Statistically compare model fit: does the second-order factor model fit significantly worse than the first-order factor model?
  3. Refit the first-order model without latent factor correlations and compare the fit (OPTIONAL)
anova(, )

9 References