Structural Equation Modeling | Exercise 3

1 What we are going to cover

  1. Ex.1 – Measurement equivalence
  2. Ex.2 – Multi-group mediation analysis

2 Data

The data set used throughout is the European Social Survey ESS4-2008 Edition 4.5 was released on 1 December 2018. We will restrict the analysis to the Belgian case. Each line in the data set represents a Belgian respondent. The full dataset an documentation can be found on the ESS website

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)

In addition, we will use some other variables

  • agea Respondent’s age

  • eduyrs Years of full-time education completed

  • gndr Gender (1 Male, 2 Female)

  • hinctnta Household’s total net income, all sources (Deciles of the actual household income range in Belgium)

  • gincdif Government should reduce differences in income levels (1 Agree strongly - 5 Disagree strongly)

  • dfincac Large differences in income acceptable to reward talents and efforts (1 Agree strongly - 5 Disagree strongly)

  • smdfslv For fair society, differences in standard of living should be small (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
# install.packages("purrr")                 # table manipulation 

### MODELING ###
# install.packages("lavaan")                # SEM modelling

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

# Load the packages 

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

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

### VISUALIZATION ###
library("tidySEM")
library("purrr")  

4 Ex.1 – Measurement equivalence

  1. Manually specify a configural invariance model for male and female
  2. Manually specify a configural invariance model where you estimate residual covariances for the manifest indicators
  3. Manually specify a metric invariance model for male and female
  4. Manually specify a scalar invariance model for male and female
  5. Explain differences in Degrees of Freedom for all the fitted models
  6. Add gvcldcr and see if the model reaches scalar invariance
  7. Request modification indices for the gvcldcr scalar model and interpret them (OPTIONAL)

Configural invariance model

ess_df <- haven::read_sav("https://github.com/albertostefanelli/SEM_labs/raw/master/data/ESS4_belgium.sav")

# lavaan requires the grouping variable to be a factor 
# gender is coded as 1 Male, 2 Female
ess_df$gndr <- factor(ess_df$gndr,
                      levels = c("1", "2"),         # levels 
                      labels = c("Male", "Female")) # labels 


model_ws_config <-'
# Factor loadings all freely estimated for each group (marker fixed to 1 by defult)
welf_supp =~ gvslvol + gvslvue + gvhlthc

# Item intercepts all freely estimated for each group
gvslvol ~ 1 
gvslvue ~ 1 
gvhlthc ~ 1 

# Residual variances all freely estimated for each group
gvslvol ~~ gvslvol 
gvslvue ~~ gvslvue 
gvhlthc ~~ gvhlthc

# Factor mean (intercept) fixed to zero in each group
welf_supp ~ 0

'


fit_configural <- cfa(model_ws_config, 
                      data = ess_df,
                      group = "gndr")


summary(fit_configural)

Configural invariance model with residual covariances

model_ws_config_cov <-'

'


fit_configural_cov <- cfa()

Metric invariance model

model_ws_metric <-'
'


fit_metric <- cfa()


summary(fit_metric)

Scalar invariance model

model_ws_scalar <-'


'


fit_scalar <- cfa()


summary(fit_scalar)

Scalar invariance model with the addition of gvcldcr

model_ws_gvcldcr <- '
welf_supp =~ gvslvol + gvslvue + gvhlthc + gvcldcr
'



# Let's compare the nested model using the anova function

table_anova <- list() %>%  
       reduce(rbind) %>% 
       .[-c(3),]

table_anova
lavTestScore()

5 Ex.2 – Multi-group mediation analysis

  1. Fit a model where egalitarianism (gincdif, dfincac, smdfslv) mediates the relationship between age (agea), education (eduyrs), income (hinctnta) and welfare support (gvslvol, gvslvue, gvhlthc) in a multigroup model where all paths coefficients are free to vary across group
    • Y is the dependent variable (Welfare support)
    • X is a vector of predictors (age, education, income)
    • M is a mediator (Egalitarianism)
    • G is a grouping variable (Gender)
  2. Assess if the model fits the data well
  3. Use lavaan syntax to calculate indirect and direct effects for each predictor in each group.
  4. Interpret the difference in the path coefficients between male and female
  5. Assess if the path from Education to Egalitarianism (Path A) can be set equal across the two groups
  6. Assess if the Indirect effect of Education on Welfare Support (a*b) can be set equal across the two groups (OPTIONAL)
  7. Think of a method to assess if path coefficients are statistically different using the := operator (OPTIONAL)

All free

model_mediation_mg <- '
## Welfare Support Factor ##
welf_supp =~ gvslvol + gvslvue + gvhlthc

## Egalitarianism ##
egual =~  gincdif + dfincac + smdfslv

## Direct effect ##
welf_supp ~ c("c_inc_1", "c_inc_2")*hinctnta
welf_supp ~ c("c_age_1", "c_age_2")*agea
welf_supp ~ c("c_edu_1", "c_edu_2")*eduyrs



'

fit_mediation_mg <- cfa(

  )

summary(fit_mediation_mg)

Path A education to Egalitarianism set equal across the two groups

model_mediation_mg_path_a <- '

'

fit_mediation_mg_path_a <- cfa(

  )

anova( , )

Path B Egalitarianism to Welfare Support set equal across the two groups

model_mediation_mg_path_ab <- '


'

fit_mediation_mg_path_ab <- cfa(

  )

anova( , )

Using the := for simple slope difference

model_mediation_mg_diff <- '




'

fit_mediation_mg_diff <- cfa(

  )

summary(fit_mediation_mg_diff)