Structural Equation Modeling | Exercise 3
1 What we are going to cover
- Ex.1 – Measurement equivalence
- 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
- Manually specify a configural invariance model for male and female
- Manually specify a configural invariance model where you estimate residual covariances for the manifest indicators
- Manually specify a metric invariance model for male and female
- Manually specify a scalar invariance model for male and female
- Explain differences in Degrees of Freedom for all the fitted models
- Add gvcldcr and see if the model reaches scalar invariance
- Request modification indices for the gvcldcr scalar model and interpret them (OPTIONAL)
Configural invariance model
<- haven::read_sav("https://github.com/albertostefanelli/SEM_labs/raw/master/data/ESS4_belgium.sav")
ess_df
# lavaan requires the grouping variable to be a factor
# gender is coded as 1 Male, 2 Female
$gndr <- factor(ess_df$gndr,
ess_dflevels = 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
'
<- cfa(model_ws_config,
fit_configural data = ess_df,
group = "gndr")
summary(fit_configural)
Configural invariance model with residual covariances
<-'
model_ws_config_cov
'
<- cfa() fit_configural_cov
Metric invariance model
<-'
model_ws_metric '
<- cfa()
fit_metric
summary(fit_metric)
Scalar invariance model
<-'
model_ws_scalar
'
<- cfa()
fit_scalar
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
<- list() %>%
table_anova reduce(rbind) %>%
-c(3),]
.[
table_anova
lavTestScore()
5 Ex.2 – Multi-group mediation analysis
- 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)
- Assess if the model fits the data well
- Use lavaan syntax to calculate indirect and direct effects for each predictor in each group.
- Interpret the difference in the path coefficients between male and female
- Assess if the path from Education to Egalitarianism (Path A) can be set equal across the two groups
- Assess if the Indirect effect of Education on Welfare Support (a*b) can be set equal across the two groups (OPTIONAL)
- 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
'
<- cfa(
fit_mediation_mg
)
summary(fit_mediation_mg)
Path A education to Egalitarianism set equal across the two groups
<- '
model_mediation_mg_path_a
'
<- cfa(
fit_mediation_mg_path_a
)
anova( , )
Path B Egalitarianism to Welfare Support set equal across the two groups
<- '
model_mediation_mg_path_ab
'
<- cfa(
fit_mediation_mg_path_ab
)
anova( , )
Using the := for simple slope difference
<- '
model_mediation_mg_diff
'
<- cfa(
fit_mediation_mg_diff
)
summary(fit_mediation_mg_diff)