DAPR3 - Week 8 - Path Mediation - Live R

Recap of last week programming

The goal for today is to specify, fit and evaluate a path model with mediation. First, let’s load our packages:

# Load tidyverse and lavaan packages

library(tidyverse)
library(lavaan)

Let’s load in the data:

# Load the data

leader <- read_csv("https://uoepsy.github.io/dapr3/2324/lectures/leader.csv")
## Rows: 550 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): ID
## dbl (5): leader, sleep, exercise, aggression, swb
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Preview the data
leader
## # A tibble: 550 × 6
##    ID            leader sleep exercise aggression   swb
##    <chr>          <dbl> <dbl>    <dbl>      <dbl> <dbl>
##  1 participant1    0.9    4.7        5       0.36  0.47
##  2 participant2   -0.13   4          2       0.5  -0.2 
##  3 participant3   -0.9    6          4      -0.61  0.3 
##  4 participant4    0.15   5          3       0.02  0.58
##  5 participant5    1.18   4.1        4       0.4   0.28
##  6 participant6    0.69   4.1        3      -0.47  0.25
##  7 participant7    0.78   5.8        3       1.26  0.51
##  8 participant8   -1.69   3.7        4      -1.05 -0.17
##  9 participant9    0.23   2.8        3       0.39 -0.28
## 10 participant10   0.27   6.1        4      -0.39 -0.24
## # ℹ 540 more rows
  1. Variable key
  • ID = Partiicpant ID
  • Leader = Abusive leadership behaviour
  • Sleep = Sleep
  • Exercise = Exercise
  • Aggression = Interpersonal aggression at work
  • swb = Sujective well-being

Let’s specify a model:

# Define the model
path1 = '
aggression ~ leader
swb ~ aggression
swb ~ leader
swb ~ exercise + sleep
'
  • Draw the model on the board here

What are we saying here? What are the relationships?

  1. Motivation predicts performance
  2. Size of organisation predicts motivation

Now let’s estimate and view:

# Fit the model
path1_out <- sem(path1, data = leader)

# Print the model
summary(path1_out, # Model
        fit.measures = T, # Fit indices
        std = T
        )
## lavaan 0.6.16 ended normally after 2 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         7
## 
##   Number of observations                           550
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 3.152
##   Degrees of freedom                                 2
##   P-value (Chi-square)                           0.207
## 
## Model Test Baseline Model:
## 
##   Test statistic                               574.763
##   Degrees of freedom                                 7
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.998
##   Tucker-Lewis Index (TLI)                       0.993
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -629.036
##   Loglikelihood unrestricted model (H1)       -627.460
##                                                       
##   Akaike (AIC)                                1272.073
##   Bayesian (BIC)                              1302.242
##   Sample-size adjusted Bayesian (SABIC)       1280.021
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.032
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.097
##   P-value H_0: RMSEA <= 0.050                    0.578
##   P-value H_0: RMSEA >= 0.080                    0.132
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.017
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   aggression ~                                                          
##     leader            0.380    0.018   21.134    0.000    0.380    0.669
##   swb ~                                                                 
##     aggression        0.416    0.047    8.772    0.000    0.416    0.401
##     leader           -0.028    0.027   -1.053    0.293   -0.028   -0.048
##     exercise          0.182    0.018    9.912    0.000    0.182    0.337
##     sleep             0.200    0.019   10.472    0.000    0.200    0.356
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .aggression        0.165    0.010   16.583    0.000    0.165    0.552
##    .swb               0.204    0.012   16.583    0.000    0.204    0.633

Week 8 - Mediation

Now let’s add the mediation effects:

path1 = '
# Direct effects
aggression ~ a*leader # aggression (M) predicted by abusive leader behaviour (X)
swb ~ b*aggression # well-being (Y) predicted by aggression (M)
swb ~ c*leader # well-being (Y) predicted by leader abusive behaviour (X): direct effect
swb ~ exercise + sleep # covariates

# Mediation effects
indirect := a*b
total := (a*b)+c
'

Estimate the model:

# Estimate the model
model1.est <- sem(path1, data = leader)

# Report the model
summary(model1.est,
        fit.measures = T, 
        std = T,
        modindices = T)
## lavaan 0.6.16 ended normally after 2 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         7
## 
##   Number of observations                           550
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 3.152
##   Degrees of freedom                                 2
##   P-value (Chi-square)                           0.207
## 
## Model Test Baseline Model:
## 
##   Test statistic                               574.763
##   Degrees of freedom                                 7
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.998
##   Tucker-Lewis Index (TLI)                       0.993
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -629.036
##   Loglikelihood unrestricted model (H1)       -627.460
##                                                       
##   Akaike (AIC)                                1272.073
##   Bayesian (BIC)                              1302.242
##   Sample-size adjusted Bayesian (SABIC)       1280.021
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.032
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.097
##   P-value H_0: RMSEA <= 0.050                    0.578
##   P-value H_0: RMSEA >= 0.080                    0.132
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.017
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   aggression ~                                                          
##     leader     (a)    0.380    0.018   21.134    0.000    0.380    0.669
##   swb ~                                                                 
##     aggression (b)    0.416    0.047    8.772    0.000    0.416    0.401
##     leader     (c)   -0.028    0.027   -1.053    0.293   -0.028   -0.048
##     exercise          0.182    0.018    9.912    0.000    0.182    0.337
##     sleep             0.200    0.019   10.472    0.000    0.200    0.356
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .aggression        0.165    0.010   16.583    0.000    0.165    0.552
##    .swb               0.204    0.012   16.583    0.000    0.204    0.633
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     indirect          0.158    0.020    8.102    0.000    0.158    0.268
##     total             0.130    0.021    6.072    0.000    0.130    0.220
## 
## Modification Indices:
## 
##           lhs op        rhs    mi    epc sepc.lv sepc.all sepc.nox
## 1      leader ~~     leader 0.000  0.000   0.000    0.000    0.000
## 2      leader ~~   exercise 0.000  0.000   0.000       NA    0.000
## 3      leader ~~      sleep 0.000  0.000   0.000       NA    0.000
## 4  aggression  ~        swb 1.075 -0.066  -0.066   -0.069   -0.069
## 5  aggression  ~   exercise 0.145  0.006   0.006    0.012    0.012
## 6  aggression  ~      sleep 3.061 -0.030  -0.030   -0.055   -0.055
## 7      leader  ~ aggression 0.898  1.313   1.313    0.745    0.745
## 8      leader  ~        swb 0.002  0.008   0.008    0.005    0.005
## 9      leader  ~   exercise 0.000  0.000   0.000    0.000    0.000
## 10     leader  ~      sleep 0.000  0.000   0.000    0.000    0.000
## 11   exercise  ~ aggression 0.025  0.010   0.010    0.005    0.005
## 12   exercise  ~        swb 0.029  0.027   0.027    0.014    0.014
## 13   exercise  ~     leader 0.000  0.000   0.000    0.000    0.000
## 14   exercise  ~      sleep 0.000  0.000   0.000    0.000    0.000
## 15      sleep  ~ aggression 0.913 -0.056  -0.056   -0.030   -0.030
## 16      sleep  ~        swb 1.052 -0.155  -0.155   -0.087   -0.087
## 17      sleep  ~     leader 0.000  0.000   0.000    0.000    0.000
## 18      sleep  ~   exercise 0.000  0.000   0.000    0.000    0.000

Now we want to compute some confidence intervals for the indirect effects:

# Estimate the model
model2.est <- sem(path1, data = leader, se = 'bootstrap')

# Report the model
summary(model1.est,
        fit.measures = T,
        ci = T,
        std = T,
        modindices = T)
## lavaan 0.6.16 ended normally after 2 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         7
## 
##   Number of observations                           550
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 3.152
##   Degrees of freedom                                 2
##   P-value (Chi-square)                           0.207
## 
## Model Test Baseline Model:
## 
##   Test statistic                               574.763
##   Degrees of freedom                                 7
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.998
##   Tucker-Lewis Index (TLI)                       0.993
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -629.036
##   Loglikelihood unrestricted model (H1)       -627.460
##                                                       
##   Akaike (AIC)                                1272.073
##   Bayesian (BIC)                              1302.242
##   Sample-size adjusted Bayesian (SABIC)       1280.021
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.032
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.097
##   P-value H_0: RMSEA <= 0.050                    0.578
##   P-value H_0: RMSEA >= 0.080                    0.132
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.017
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   aggression ~                                                          
##     leader     (a)    0.380    0.018   21.134    0.000    0.345    0.415
##   swb ~                                                                 
##     aggression (b)    0.416    0.047    8.772    0.000    0.323    0.509
##     leader     (c)   -0.028    0.027   -1.053    0.293   -0.081    0.024
##     exercise          0.182    0.018    9.912    0.000    0.146    0.219
##     sleep             0.200    0.019   10.472    0.000    0.162    0.237
##    Std.lv  Std.all
##                   
##     0.380    0.669
##                   
##     0.416    0.401
##    -0.028   -0.048
##     0.182    0.337
##     0.200    0.356
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .aggression        0.165    0.010   16.583    0.000    0.146    0.185
##    .swb               0.204    0.012   16.583    0.000    0.180    0.229
##    Std.lv  Std.all
##     0.165    0.552
##     0.204    0.633
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     indirect          0.158    0.020    8.102    0.000    0.120    0.196
##     total             0.130    0.021    6.072    0.000    0.088    0.172
##    Std.lv  Std.all
##     0.158    0.268
##     0.130    0.220
## 
## Modification Indices:
## 
##           lhs op        rhs    mi    epc sepc.lv sepc.all sepc.nox
## 1      leader ~~     leader 0.000  0.000   0.000    0.000    0.000
## 2      leader ~~   exercise 0.000  0.000   0.000       NA    0.000
## 3      leader ~~      sleep 0.000  0.000   0.000       NA    0.000
## 4  aggression  ~        swb 1.075 -0.066  -0.066   -0.069   -0.069
## 5  aggression  ~   exercise 0.145  0.006   0.006    0.012    0.012
## 6  aggression  ~      sleep 3.061 -0.030  -0.030   -0.055   -0.055
## 7      leader  ~ aggression 0.898  1.313   1.313    0.745    0.745
## 8      leader  ~        swb 0.002  0.008   0.008    0.005    0.005
## 9      leader  ~   exercise 0.000  0.000   0.000    0.000    0.000
## 10     leader  ~      sleep 0.000  0.000   0.000    0.000    0.000
## 11   exercise  ~ aggression 0.025  0.010   0.010    0.005    0.005
## 12   exercise  ~        swb 0.029  0.027   0.027    0.014    0.014
## 13   exercise  ~     leader 0.000  0.000   0.000    0.000    0.000
## 14   exercise  ~      sleep 0.000  0.000   0.000    0.000    0.000
## 15      sleep  ~ aggression 0.913 -0.056  -0.056   -0.030   -0.030
## 16      sleep  ~        swb 1.052 -0.155  -0.155   -0.087   -0.087
## 17      sleep  ~     leader 0.000  0.000   0.000    0.000    0.000
## 18      sleep  ~   exercise 0.000  0.000   0.000    0.000    0.000