Structural Equation Modeling | Exercises 2

1 What we are going to cover

  1. Ex.1 – MIMIC model
  2. Ex.2 – 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

### 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")

4 Ex.1 - MIMIC model

  1. Fit the a measurement model with both welfare support and egalitarianism and review the fit statistics. Also review the parameter estimates. How close are they to the population values?
  2. Predict welfare support by adding the gender covariate and assess the changes in fit statistics and parameter estimates.
  3. Add in succession age, income, and education and again see if fit statistics or parameter estimates change.
  4. Is there a trend for the fit statistics to change (improve or deteriorate) when including covariates?
  5. Calculate the degrees of freedom for each of these models manually. Explain the changes in degrees of freedom.
  6. Create an R function for the degrees of freedom calculations (OPTIONAL)
ess_df <- haven::read_sav("https://github.com/albertostefanelli/SEM_labs/raw/master/data/ESS4_belgium.sav")

model_ws_eg <- '
## Welfare Support Factor ##
welf_supp =~ 

## Egalitarianism ##
egual =~  
'

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

Degrees of freedom calculation:

  1. pieces of information (observed variables) = \(p(p+1)/2=21\)
  2. measurement part = n factor loadings + n residual variances.
  3. structural part = n regressions + n residual factor variance.
  4. exogenous variables = n variances + n covariances.
  5. df = pieces of information - (measurement part + structural part + exogenous variables).

5 Ex.2 – Mediation Analysis

  1. Fit a model where egalitarianism (gincdif, dfincac, smdfslv) mediates the relationship between age (agea), education (eduyrs), gender (gndr), income (hinctnta) and welfare support (gvslvol, gvslvue, gvhlthc)
  2. Assess if the model fits the data well
  3. Inspect the regression parameters and the R-squared values of the latent variables.
  4. Manually calculate the indirect effect of age via egalitarianism \(a \times b\) and its standard error (\(\sigma_{a \times b}\)) using Sobel’s formula:
    • Indirect effect = \(a \times b\).
    • \(\sigma_{a \times b} = \sqrt{b^2 \times \sigma_{a}^2 + a^2 \times \sigma_{b}^2}\).
  5. Manually calculate the total effect of age \(c' + (a \times b)\) on welfare support
  6. Ask lavaan to calculate these indirect and total effects. Compare to your own solution
  7. Interpret the results. Does egalitarianism mediates age? Can you interpret this result causally ?
model_mediation <- '
## Welfare Support Factor ##
welf_supp =~ 

## Egalitarianism ##
egual =~ 

## Direct effect(s) ##
welf_supp ~ 

## Mediator ##
# Path A
egual ~

# Path B
welf_supp ~ 

## Indirect effect (a*b) ##
ab_age := a*b

## Total effect ##

'

Next, let’s calculate the direct and indirect effects manually

## Coefficients ## 

## Standard Errors ## 

## Manual calculation of indirect effect a x b ## 
a * b
## Manual calculation of the sigma a x b ## 

## Manual calculation of the total effect (a x b) + c' ## 
a * b +

Let’s use tidy SEM to extract the direct and indirect effects calculated by lavaan