Chapter 6 Week6_1: Lavaan Lab 4 Mediated Moderation & Moderated Mediation

In this lab, we will learn how to:

  • Estimate the mediated moderation model
  • Estimate the moderated mediation model
  • Bootstrap the effects
  • Conduct simple slope analyses

6.1 PART 1: Mediated Moderation (Indirect Conditional effect)

6.1.1 Step 1: Read-in Data

Imagine that we extended our CBT study by adding a mediator: the average number of daily negative thoughts reported at the end of six weeks.

The hypothesis we will test is that NegThoughts mediates the CBT*NeedCog -> Depression path

Let’s read this dataset in:

cbtData <- read.csv(file = "dataInClass.csv", header = T, sep = ',')

This time we work with the continuous version of the moderator: NeedCogCont.

Let’s examine their means and standard deviations:

apply(cbtData[,-c(1,2)], 2, mean)
##     CBTDummy      NeedCog  NegThoughts   Depression  NeedCogCont 
##  0.500000000  0.309000000 -1.944249996 -1.589356290  0.005925852
apply(cbtData[,-c(1,2)], 2, sd)
##    CBTDummy     NeedCog NegThoughts  Depression NeedCogCont 
##   0.5002502   0.4623124   3.1877174   5.6506763   0.9974319

Why dropping the first two variables?

  • The first two variables ID and CBT are not numerical and have no means.

NeedCogCont has been standardized already, which is helpful.

  • If not, don’t forget to use scale() function to center the continuous variables.

6.1.2 Step 2: Create the interaction term for Moderation Analysis

To test the moderation effect, we have to manually create a product term in the dataset before running our model:

cbtData$CBTxNeedCogCont <- cbtData$CBTDummy * cbtData$NeedCogCont

Let’s look at cbtData again:

head(cbtData)
##   ID              CBT CBTDummy NeedCog NegThoughts Depression NeedCogCont CBTxNeedCogCont
## 1  1    CBT Treatment        1       0  -4.1453029  -5.802172   0.0182802       0.0182802
## 2  2 Information Only        0       1   2.1775218   5.496665   1.4238703       0.0000000
## 3  3    CBT Treatment        1       0  -1.5551349  -1.950566  -1.0151726      -1.0151726
## 4  4 Information Only        0       0   0.1679286   2.655801  -0.8547152       0.0000000
## 5  5 Information Only        0       1   2.5103192   6.855488   0.6759705       0.0000000
## 6  6    CBT Treatment        1       0  -3.1626670  -2.968198  -0.9123426      -0.9123426

6.1.3 Step 3: Write the syntax and Fit the model

load the package:

library(lavaan)

Follow the two equations to write the model syntax:

ex1MedModerationBasic <- " 
  # label the coefficients:
  
  NegThoughts ~ a_m1*CBTxNeedCogCont + a_m2*NeedCogCont + a_m3*CBTDummy
    Depression ~ b1*CBTDummy + b2*NeedCogCont + b3*CBTxNeedCogCont + bM*NegThoughts

  #Define New Parameter Using :=
  
  #Mediated Moderation effect  
  MedMod_ab := a_m1*bM
  TotalMod := MedMod_ab + b3
    "  

Since we included the intercept term, we need to ask sem() to include the meanstructure:

ex1fit <- lavaan::sem(model = ex1MedModerationBasic, 
              data = cbtData, 
              fixed.x = FALSE,
              meanstructure = TRUE)
summary(ex1fit, ci = T)
## lavaan 0.6-12 ended normally after 40 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                          1000
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   NegThoughts ~                                                         
##     CBTxNCC (a_m1)   -3.071    0.064  -48.104    0.000   -3.196   -2.945
##     NdCgCnt (a_m2)    2.000    0.044   45.075    0.000    1.913    2.087
##     CBTDmmy (a_m3)   -5.060    0.064  -79.562    0.000   -5.185   -4.936
##   Depression ~                                                          
##     CBTDmmy   (b1)   -1.240    0.137   -9.055    0.000   -1.509   -0.972
##     NdCgCnt   (b2)    0.141    0.061    2.292    0.022    0.020    0.261
##     CBTxNCC   (b3)   -0.109    0.092   -1.180    0.238   -0.290    0.072
##     NgThght   (bM)    1.582    0.025   62.899    0.000    1.533    1.631
## 
## Covariances:
##                      Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   CBTxNeedCogCont ~~                                                      
##     NeedCogCont         0.480    0.027   18.055    0.000    0.428    0.532
##     CBTDummy           -0.008    0.011   -0.764    0.445   -0.030    0.013
##   NeedCogCont ~~                                                          
##     CBTDummy           -0.020    0.016   -1.249    0.212   -0.051    0.011
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .NegThoughts       0.523    0.045   11.618    0.000    0.434    0.611
##    .Depression        2.104    0.038   55.199    0.000    2.029    2.179
##     CBTxNeedCogCnt   -0.017    0.022   -0.764    0.445   -0.060    0.026
##     NeedCogCont       0.006    0.032    0.188    0.851   -0.056    0.068
##     CBTDummy          0.500    0.016   31.623    0.000    0.469    0.531
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .NegThoughts       1.010    0.045   22.361    0.000    0.921    1.098
##    .Depression        0.639    0.029   22.361    0.000    0.583    0.695
##     CBTxNeedCogCnt    0.480    0.021   22.361    0.000    0.438    0.522
##     NeedCogCont       0.994    0.044   22.361    0.000    0.907    1.081
##     CBTDummy          0.250    0.011   22.361    0.000    0.228    0.272
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     MedMod_ab        -4.858    0.127  -38.211    0.000   -5.107   -4.609
##     TotalMod         -4.967    0.113  -43.943    0.000   -5.188   -4.745

Are we done?

6.1.4 Step 4: Bootstrap Version

We need to request Bootstrap because this involves testing a mediation effect MedMod_ab.

Remember to set a seed:

set.seed(2022)
ex1Boot <- lavaan::sem(model = ex1MedModerationBasic, 
               data = cbtData, 
               fixed.x = FALSE,
               meanstructure = TRUE,
               se = "bootstrap", 
               bootstrap = 1000) 
  • This requires the full dataset - need more than the covariance matrix.
  • se = “bootstrap” requests bootstrap standard errors.
  • bootstrap = 1000 requests 1000 bootstrap samples.

Request BC confidence interval:

parameterEstimates(ex1Boot, 
                   level = 0.95, 
                   boot.ci.type="bca.simple",
                   standardized = TRUE)
## Warning in norm.inter(t, adj.alpha): extreme order statistics used as endpoints
##                lhs op             rhs     label    est    se       z pvalue ci.lower ci.upper std.lv std.all std.nox
## 1      NegThoughts  ~ CBTxNeedCogCont      a_m1 -3.071 0.067 -45.675  0.000   -3.195   -2.922 -3.071  -0.668  -0.964
## 2      NegThoughts  ~     NeedCogCont      a_m2  2.000 0.048  42.047  0.000    1.902    2.093  2.000   0.626   0.628
## 3      NegThoughts  ~        CBTDummy      a_m3 -5.060 0.064 -78.764  0.000   -5.183   -4.930 -5.060  -0.794  -1.588
## 4       Depression  ~        CBTDummy        b1 -1.240 0.133  -9.337  0.000   -1.493   -0.979 -1.240  -0.110  -0.220
## 5       Depression  ~     NeedCogCont        b2  0.141 0.059   2.379  0.017    0.020    0.256  0.141   0.025   0.025
## 6       Depression  ~ CBTxNeedCogCont        b3 -0.109 0.088  -1.232  0.218   -0.270    0.071 -0.109  -0.013  -0.019
## 7       Depression  ~     NegThoughts        bM  1.582 0.024  65.833  0.000    1.539    1.632  1.582   0.892   0.892
## 8      NegThoughts ~~     NegThoughts            1.010 0.042  23.885  0.000    0.937    1.109  1.010   0.099   0.099
## 9       Depression ~~      Depression            0.639 0.030  21.077  0.000    0.585    0.708  0.639   0.020   0.020
## 10 CBTxNeedCogCont ~~ CBTxNeedCogCont            0.480 0.034  14.292  0.000    0.411    0.545  0.480   1.000   0.480
## 11 CBTxNeedCogCont ~~     NeedCogCont            0.480 0.034  14.314  0.000    0.412    0.545  0.480   0.695   0.480
## 12 CBTxNeedCogCont ~~        CBTDummy           -0.008 0.011  -0.781  0.435   -0.030    0.013 -0.008  -0.024  -0.008
## 13     NeedCogCont ~~     NeedCogCont            0.994 0.044  22.749  0.000    0.909    1.078  0.994   1.000   0.994
## 14     NeedCogCont ~~        CBTDummy           -0.020 0.016  -1.258  0.208   -0.051    0.013 -0.020  -0.040  -0.020
## 15        CBTDummy ~~        CBTDummy            0.250 0.000 619.384  0.000    0.250    0.250  0.250   1.000   0.250
## 16     NegThoughts ~1                            0.523 0.046  11.401  0.000    0.436    0.616  0.523   0.164   0.164
## 17      Depression ~1                            2.104 0.038  54.754  0.000    2.029    2.177  2.104   0.373   0.373
## 18 CBTxNeedCogCont ~1                           -0.017 0.021  -0.781  0.435   -0.059    0.026 -0.017  -0.024  -0.017
## 19     NeedCogCont ~1                            0.006 0.031   0.190  0.849   -0.062    0.063  0.006   0.006   0.006
## 20        CBTDummy ~1                            0.500 0.016  30.669  0.000    0.466    0.528  0.500   1.000   0.500
## 21       MedMod_ab :=         a_m1*bM MedMod_ab -4.858 0.125 -38.863  0.000   -5.089   -4.602 -4.858  -0.596  -0.860
## 22        TotalMod :=    MedMod_ab+b3  TotalMod -4.967 0.118 -42.112  0.000   -5.195   -4.720 -4.967  -0.609  -0.879

Warning message:

In norm.inter(t, adj.alpha) : extreme order statistics used as endpoints

https://rcompanion.org/handbook/E_04.html

The BCa (bias corrected, accelerated) is often cited as the best for theoretical reasons. The percentile method is also cited as typically good. However, if you get the “extreme order statistics used as endpoints” warning message, use a different test. For small data sets, the interval from BCa may be wider than for some other methods.

6.1.5 Step 5: Effect size measures

Measure 1: Completely Standardized Indirect Effect (CSIE)

beta_a_m1 = -0.668
beta_bM = 0.892
es1 = beta_a_m1*beta_bM
es1
## [1] -0.595856
  • According to Cohen, .01-.09 is small, .10-.25 is medium, and .25 + is large
  • This is a large mediation effect

Measure 2:

  • Use unstandardized parameter estimates:
TotalMod = -4.967
MedMod_ab = -4.858
prop = MedMod_ab/TotalMod #97.8%
prop
## [1] 0.9780552
b3 = -0.109 # pvalue=0.218 # nonsig
  • Mediated% = indirect effect / total effect = ab / c
  • Consistent mediation
  • Complete mediation as the remaining direct effect is nonsig and prop > 80%

6.2 PART 2: Moderated Mediation (Conditional Indirect effect)

In this lab, we’ll test this first-stage moderated mediation model in which NeedCog moderates the CBT -> NegThoughts path

6.2.1 Step 1: Product Term

We already have the product term in the dataset:

cbtData$CBTxNeedCogCont <- cbtData$CBTDummy * cbtData$NeedCogCont

If NeedCog moderates the NegThoughts -> Depression path, then we center NegThoughts and create a product term between centered NegThoughts*NeedCogCont (making sense?)

6.2.2 Step 2: Write the syntax and Fit the model

ex2ModMediationBasic <- " 
  NegThoughts ~ a1*CBTDummy + a2*NeedCogCont + a3*CBTxNeedCogCont 
    Depression ~ b*NegThoughts + cprime*CBTDummy
    "

We’ll need to define the Index of Moderated Mediation in the syntax:

ex2ModMediation <- " 
    #Regressions
  NegThoughts ~ a1*CBTDummy + a2*NeedCogCont + a3*CBTxNeedCogCont 
    Depression ~ b*NegThoughts + cprime*CBTDummy

  #Index of Moderated Mediation
  IndexOfModMed := a3*b
    "  

6.2.3 Step 3: Bootstrap Version

Since this model involves tests of indirect effects

let’s jump to the bootstrap test:

set.seed(2022)
ex2Boot <- lavaan::sem(model = ex2ModMediation, 
               data = cbtData, 
               fixed.x = FALSE,
               meanstructure = TRUE,
               se = "bootstrap", 
               bootstrap = 1000) 

You can further request a BC (bias-corrected) by adding an argument boot.ci.type = “bca.simple” to parameterEstimates():

parameterEstimates(ex2Boot, 
                   level = 0.95, 
                   boot.ci.type="bca.simple",
                   standardized = TRUE)
## Warning in norm.inter(t, adj.alpha): extreme order statistics used as endpoints
##                lhs op             rhs         label    est    se       z pvalue ci.lower ci.upper std.lv std.all std.nox
## 1      NegThoughts  ~        CBTDummy            a1 -5.060 0.064 -78.764  0.000   -5.183   -4.930 -5.060  -0.794  -1.588
## 2      NegThoughts  ~     NeedCogCont            a2  2.000 0.048  42.047  0.000    1.902    2.093  2.000   0.626   0.628
## 3      NegThoughts  ~ CBTxNeedCogCont            a3 -3.071 0.067 -45.675  0.000   -3.195   -2.922 -3.071  -0.668  -0.964
## 4       Depression  ~     NegThoughts             b  1.617 0.013 124.544  0.000    1.592    1.642  1.617   0.912   0.912
## 5       Depression  ~        CBTDummy        cprime -1.066 0.084 -12.758  0.000   -1.216   -0.899 -1.066  -0.094  -0.189
## 6      NegThoughts ~~     NegThoughts                1.010 0.042  23.885  0.000    0.937    1.109  1.010   0.099   0.099
## 7       Depression ~~      Depression                0.645 0.031  21.047  0.000    0.592    0.714  0.645   0.020   0.020
## 8         CBTDummy ~~        CBTDummy                0.250 0.000 619.383  0.000    0.250    0.250  0.250   1.000   0.250
## 9         CBTDummy ~~     NeedCogCont               -0.020 0.016  -1.258  0.208   -0.051    0.013 -0.020  -0.040  -0.020
## 10        CBTDummy ~~ CBTxNeedCogCont               -0.008 0.011  -0.781  0.435   -0.030    0.013 -0.008  -0.024  -0.008
## 11     NeedCogCont ~~     NeedCogCont                0.994 0.044  22.749  0.000    0.909    1.078  0.994   1.000   0.994
## 12     NeedCogCont ~~ CBTxNeedCogCont                0.480 0.034  14.314  0.000    0.412    0.545  0.480   0.695   0.480
## 13 CBTxNeedCogCont ~~ CBTxNeedCogCont                0.480 0.034  14.292  0.000    0.411    0.545  0.480   1.000   0.480
## 14     NegThoughts ~1                                0.523 0.046  11.401  0.000    0.436    0.616  0.523   0.164   0.164
## 15      Depression ~1                                2.089 0.037  56.930  0.000    2.021    2.160  2.089   0.370   0.370
## 16        CBTDummy ~1                                0.500 0.016  30.669  0.000    0.467    0.529  0.500   1.000   0.500
## 17     NeedCogCont ~1                                0.006 0.031   0.190  0.849   -0.062    0.063  0.006   0.006   0.006
## 18 CBTxNeedCogCont ~1                               -0.017 0.021  -0.781  0.435   -0.059    0.026 -0.017  -0.024  -0.017
## 19   IndexOfModMed :=            a3*b IndexOfModMed -4.967 0.114 -43.431  0.000   -5.180   -4.727 -4.967  -0.609  -0.879

Defined Parameters:

               Estimate  Std.Err  ci.lower  ci.upper   std.all

IndexOfModMed    -4.967    0.114    -5.180    -4.727    -0.609

NeedCogCont significantly moderates CBT -> NegThoughts -> Depression indirect effect through moderating the first stage of the indirect effect

  • Since we expect the effect of CBT on Depression to be negative (CBT reduces Depression)
  • And IndexOfModMed is also negative
  • We’ll say NeedCogCont strengthens the indirect effect of CBT on Depression through NegThoughts
  • The higher need for cognition, the stronger the indirect effect, and the more effect mediated by NegThoughts

6.2.4 Step 4: Simple Slopes

As a follow-up analysis to a significant moderation effect, we conduct simple slope anlaysis:

Let’s use pick-a-point (Rogosa, 1980) and plot the indirect effects at designated levels of NeedCogCont:

mean(cbtData$NeedCogCont) #0
## [1] 0.005925852
sd(cbtData$NeedCogCont) # 1
## [1] 0.9974319

Three representative levels:

mean(cbtData$NeedCogCont) - sd(cbtData$NeedCogCont) # -1
## [1] -0.991506
mean(cbtData$NeedCogCont)  #0
## [1] 0.005925852
mean(cbtData$NeedCogCont) + sd(cbtData$NeedCogCont) # 1
## [1] 1.003358

let’s define the Conditional Indirect Effects in the syntax:

ex3ModMediation <- " 
    #Regressions
  NegThoughts ~ a1*CBTDummy + a2*NeedCogCont + a3*CBTxNeedCogCont 
    Depression ~ b*NegThoughts + cprime*CBTDummy

  #Index of Moderated Mediation
  IndexOfModMed := a3*b

  #Simple Slopes
    aSSLow := a1+a3*(-1)    
    aSSMean := a1+a3*0      
    aSSHigh := a1+a3*1      

    #Conditional Indirect Effects
    abLow := aSSLow*b
    abMean := aSSMean*b
    abHigh := aSSHigh*b
    "  
set.seed(2022)
ex3Boot <- lavaan::sem(model = ex3ModMediation, 
               data = cbtData, 
               se = "bootstrap", 
               bootstrap = 1000, 
               fixed.x=FALSE,
               meanstructure = TRUE) 
parameterEstimates(ex3Boot, 
                   level = 0.95, 
                   boot.ci.type="bca.simple",
                   standardized = TRUE)
## Warning in norm.inter(t, adj.alpha): extreme order statistics used as endpoints
##                lhs op             rhs         label     est    se       z pvalue ci.lower ci.upper  std.lv std.all std.nox
## 1      NegThoughts  ~        CBTDummy            a1  -5.060 0.064 -78.764  0.000   -5.183   -4.930  -5.060  -0.794  -1.588
## 2      NegThoughts  ~     NeedCogCont            a2   2.000 0.048  42.047  0.000    1.902    2.093   2.000   0.626   0.628
## 3      NegThoughts  ~ CBTxNeedCogCont            a3  -3.071 0.067 -45.675  0.000   -3.195   -2.922  -3.071  -0.668  -0.964
## 4       Depression  ~     NegThoughts             b   1.617 0.013 124.544  0.000    1.592    1.642   1.617   0.912   0.912
## 5       Depression  ~        CBTDummy        cprime  -1.066 0.084 -12.758  0.000   -1.216   -0.899  -1.066  -0.094  -0.189
## 6      NegThoughts ~~     NegThoughts                 1.010 0.042  23.885  0.000    0.937    1.109   1.010   0.099   0.099
## 7       Depression ~~      Depression                 0.645 0.031  21.047  0.000    0.592    0.714   0.645   0.020   0.020
## 8         CBTDummy ~~        CBTDummy                 0.250 0.000 619.383  0.000    0.250    0.250   0.250   1.000   0.250
## 9         CBTDummy ~~     NeedCogCont                -0.020 0.016  -1.258  0.208   -0.051    0.013  -0.020  -0.040  -0.020
## 10        CBTDummy ~~ CBTxNeedCogCont                -0.008 0.011  -0.781  0.435   -0.030    0.013  -0.008  -0.024  -0.008
## 11     NeedCogCont ~~     NeedCogCont                 0.994 0.044  22.749  0.000    0.909    1.078   0.994   1.000   0.994
## 12     NeedCogCont ~~ CBTxNeedCogCont                 0.480 0.034  14.314  0.000    0.412    0.545   0.480   0.695   0.480
## 13 CBTxNeedCogCont ~~ CBTxNeedCogCont                 0.480 0.034  14.292  0.000    0.411    0.545   0.480   1.000   0.480
## 14     NegThoughts ~1                                 0.523 0.046  11.401  0.000    0.436    0.616   0.523   0.164   0.164
## 15      Depression ~1                                 2.089 0.037  56.930  0.000    2.021    2.160   2.089   0.370   0.370
## 16        CBTDummy ~1                                 0.500 0.016  30.669  0.000    0.467    0.529   0.500   1.000   0.500
## 17     NeedCogCont ~1                                 0.006 0.031   0.190  0.849   -0.062    0.063   0.006   0.006   0.006
## 18 CBTxNeedCogCont ~1                                -0.017 0.021  -0.781  0.435   -0.059    0.026  -0.017  -0.024  -0.017
## 19   IndexOfModMed :=            a3*b IndexOfModMed  -4.967 0.114 -43.431  0.000   -5.180   -4.727  -4.967  -0.609  -0.879
## 20          aSSLow :=      a1+a3*(-1)        aSSLow  -1.990 0.092 -21.679  0.000   -2.176   -1.813  -1.990  -0.126  -0.624
## 21         aSSMean :=         a1+a3*0       aSSMean  -5.060 0.064 -78.724  0.000   -5.183   -4.930  -5.060  -0.794  -1.588
## 22         aSSHigh :=         a1+a3*1       aSSHigh  -8.131 0.094 -86.243  0.000   -8.313   -7.942  -8.131  -1.462  -2.552
## 23           abLow :=        aSSLow*b         abLow  -3.218 0.151 -21.338  0.000   -3.532   -2.941  -3.218  -0.115  -0.570
## 24          abMean :=       aSSMean*b        abMean  -8.185 0.121 -67.625  0.000   -8.433   -7.944  -8.185  -0.725  -1.449
## 25          abHigh :=       aSSHigh*b        abHigh -13.152 0.181 -72.721  0.000  -13.513  -12.779 -13.152  -1.334  -2.329
Defined Parameters: 
                   Estimate  Std.Err  z-value  P(>|z|)    ci.lower  ci.upper    std.all
    IndexOfModMed    -4.967    0.114  -43.431    0.000      -5.180    -4.727     -0.609      
    aSSLow           -1.990    0.092  -21.679    0.000      -2.176    -1.813     -0.126  
    aSSMean          -5.060    0.064  -78.724    0.000      -5.183    -4.930     -0.794                                 
    aSSHigh          -8.131    0.094  -86.243    0.000      -8.313    -7.942     -1.462  
    abLow            -3.218    0.151  -21.338    0.000      -3.532    -2.941     -0.115  
    abMean           -8.185    0.121  -67.625    0.000      -8.433    -7.944     -0.725  
    abHigh          -13.152    0.181  -72.721    0.000     -13.513   -12.779     -1.334  
    b                 1.617    0.013  124.544    0.000       1.592     1.642      0.912  
    cprime           -1.066    0.084  -12.758    0.000      -1.216    -0.899     -0.094  
  • What does a1 tell you?

  • What does a2 tell you?

  • What does a3 tell you?

  • What does IndexOfModMed tell you?

  • What does aSSLow tell you?

  • What does aSSMean tell you?

  • What does aSSHigh tell you?

  • What does b tell you?

  • What does abLow tell you?

  • What does abMean tell you?

  • What does abHigh tell you?

  • What does cprime tell you?

  • the simple slopes of CBT -> NegThoughts (a path) are all negative at three levels of the moderator

  • the indirect effects of CBT -> NegThoughts -> Depression (ab) are all negative at three levels of the moderator

6.2.5 Step 5 JOHNSON-NEYMAN INTERVAL

Although johnson_neyman() does not work on lavaan fitted object (yet), one can use a try-and-error approach to figure out the region of significance:

First, obtain the minimum and maximum of the moderator NeedCogCont:

min(cbtData$NeedCogCont)   # -2.83
## [1] -2.829197
max(cbtData$NeedCogCont)   #  3.31
## [1] 3.310095
ex4_JN <- " 
    #Regressions
  NegThoughts ~ a1*CBTDummy + a2*NeedCogCont + a3*CBTxNeedCogCont 
    Depression ~ b*NegThoughts + cprime*CBTDummy

  #Index of Moderated Mediation
  IndexOfModMed := a3*b

  #Simple Slopes
    aSSMin := a1+a3*(-2.83) 
    aSSMin1 := a1+a3*(-1.75)    
    aSSMin2 := a1+a3*(-1.74)    
    aSSMin3 := a1+a3*(-1.58)    
    aSSMin4 := a1+a3*(-1.57)    
    aSSLow := a1+a3*(-1)    
    aSSMean := a1+a3*0      
    aSSHigh := a1+a3*1      
    aSSMax := a1+a3*(3.31)  

    #Conditional Indirect Effects
    abMin := (a1+a3*(-2.83))*b
    abMin1 := (a1+a3*(-1.75))*b    # cutoff1
    abMin2 := (a1+a3*(-1.74))*b
    abMin3 := (a1+a3*(-1.58))*b
    abMin4 := (a1+a3*(-1.57))*b    # cutoff2
    abLow := aSSLow*b
    abMean := aSSMean*b
    abHigh := aSSHigh*b
    abMax := (a1+a3*(3.31))*b
    "  
set.seed(2022)
ex4Boot <- lavaan::sem(model = ex4_JN, 
               data = cbtData, 
               se = "bootstrap", 
               bootstrap = 1000, 
               fixed.x=FALSE,
               meanstructure = TRUE) 
parameterEstimates(ex4Boot, 
                   level = 0.95, 
                   boot.ci.type="bca.simple")
## Warning in norm.inter(t, adj.alpha): extreme order statistics used as endpoints
##                lhs op               rhs         label     est    se       z pvalue ci.lower ci.upper
## 1      NegThoughts  ~          CBTDummy            a1  -5.060 0.064 -78.764  0.000   -5.183   -4.930
## 2      NegThoughts  ~       NeedCogCont            a2   2.000 0.048  42.047  0.000    1.902    2.093
## 3      NegThoughts  ~   CBTxNeedCogCont            a3  -3.071 0.067 -45.675  0.000   -3.195   -2.922
## 4       Depression  ~       NegThoughts             b   1.617 0.013 124.544  0.000    1.592    1.642
## 5       Depression  ~          CBTDummy        cprime  -1.066 0.084 -12.758  0.000   -1.216   -0.899
## 6      NegThoughts ~~       NegThoughts                 1.010 0.042  23.885  0.000    0.937    1.109
## 7       Depression ~~        Depression                 0.645 0.031  21.047  0.000    0.592    0.714
## 8         CBTDummy ~~          CBTDummy                 0.250 0.000 619.383  0.000    0.250    0.250
## 9         CBTDummy ~~       NeedCogCont                -0.020 0.016  -1.258  0.208   -0.051    0.013
## 10        CBTDummy ~~   CBTxNeedCogCont                -0.008 0.011  -0.781  0.435   -0.030    0.013
## 11     NeedCogCont ~~       NeedCogCont                 0.994 0.044  22.749  0.000    0.909    1.078
## 12     NeedCogCont ~~   CBTxNeedCogCont                 0.480 0.034  14.314  0.000    0.412    0.545
## 13 CBTxNeedCogCont ~~   CBTxNeedCogCont                 0.480 0.034  14.292  0.000    0.411    0.545
## 14     NegThoughts ~1                                   0.523 0.046  11.401  0.000    0.436    0.616
## 15      Depression ~1                                   2.089 0.037  56.930  0.000    2.021    2.160
## 16        CBTDummy ~1                                   0.500 0.016  30.669  0.000    0.467    0.529
## 17     NeedCogCont ~1                                   0.006 0.031   0.190  0.849   -0.062    0.063
## 18 CBTxNeedCogCont ~1                                  -0.017 0.021  -0.781  0.435   -0.059    0.026
## 19   IndexOfModMed :=              a3*b IndexOfModMed  -4.967 0.114 -43.431  0.000   -5.180   -4.727
## 20          aSSMin :=     a1+a3*(-2.83)        aSSMin   3.630 0.199  18.215  0.000    3.204    4.011
## 21         aSSMin1 :=     a1+a3*(-1.75)       aSSMin1   0.313 0.133   2.363  0.018    0.029    0.562
## 22         aSSMin2 :=     a1+a3*(-1.74)       aSSMin2   0.283 0.132   2.141  0.032    0.000    0.530
## 23         aSSMin3 :=     a1+a3*(-1.58)       aSSMin3  -0.209 0.123  -1.701  0.089   -0.471    0.018
## 24         aSSMin4 :=     a1+a3*(-1.57)       aSSMin4  -0.239 0.122  -1.960  0.050   -0.500   -0.013
## 25          aSSLow :=        a1+a3*(-1)        aSSLow  -1.990 0.092 -21.679  0.000   -2.176   -1.813
## 26         aSSMean :=           a1+a3*0       aSSMean  -5.060 0.064 -78.724  0.000   -5.183   -4.930
## 27         aSSHigh :=           a1+a3*1       aSSHigh  -8.131 0.094 -86.243  0.000   -8.313   -7.942
## 28          aSSMax :=      a1+a3*(3.31)        aSSMax -15.224 0.233 -65.232  0.000  -15.658  -14.751
## 29           abMin := (a1+a3*(-2.83))*b         abMin   5.871 0.324  18.092  0.000    5.185    6.487
## 30          abMin1 := (a1+a3*(-1.75))*b        abMin1   0.507 0.214   2.363  0.018    0.047    0.904
## 31          abMin2 := (a1+a3*(-1.74))*b        abMin2   0.457 0.213   2.141  0.032   -0.001    0.853
## 32          abMin3 := (a1+a3*(-1.58))*b        abMin3  -0.338 0.199  -1.700  0.089   -0.759    0.030
## 33          abMin4 := (a1+a3*(-1.57))*b        abMin4  -0.387 0.198  -1.959  0.050   -0.807   -0.020
## 34           abLow :=          aSSLow*b         abLow  -3.218 0.151 -21.338  0.000   -3.532   -2.941
## 35          abMean :=         aSSMean*b        abMean  -8.185 0.121 -67.625  0.000   -8.433   -7.944
## 36          abHigh :=         aSSHigh*b        abHigh -13.152 0.181 -72.721  0.000  -13.513  -12.779
## 37           abMax :=  (a1+a3*(3.31))*b         abMax -24.624 0.418 -58.964  0.000  -25.391  -23.738

So our regions of significance are:

  • \([-2.83, -1.75]\): In which the ab are positive and significant. Participants with this level of NeegCog experienced elevated levels of depression due to CBT because CBT induces more negative thoughts among them.
  • \([-1.75, -1.57]\): In which the ab are NOT significant.
  • \([-1.57, 3.31]\): In which the ab are negative and significant. Participants with this level of NeegCog experienced reduced levels of depression due to CBT because CBT reduced negative thoughts for them.