Mediation Analysis: bootstrapped method

Variables

X = treat

Y = cong_mesg (binary)

M = emo

Covariates: sex, age, education, gender, income

Data

data ("framing", package = "mediation")

framing = as.data.frame(framing)
framing %>%
  headTail() %>%
  kable()
cond anx age educ gender income emo p_harm tone eth treat english immigr anti_info cong_mesg
1 3 a little anxious 45 high school male 13 7 6 0 1 0 Oppose 4 0 1
2 4 somewhat anxious 73 bachelor’s degree or higher male 16 6 3 0 0 0 Favor 3 0 0
3 2 a little anxious 53 some college female 3 8 7 1 0 0 Strongly Oppose 3 0 0
4 1 not anxious at all 45 high school male 14 9 8 1 1 1 Strongly Oppose 4 0 1
… NA NA … NA NA … … … … … … NA … … …
262 4 somewhat anxious 28 bachelor’s degree or higher female 14 6 6 0 0 0 Strongly Oppose 1 0 1
263 2 very anxious 38 bachelor’s degree or higher female 14 3 6 1 0 0 Favor 2 0 0
264 1 somewhat anxious 29 bachelor’s degree or higher male 10 9 7 1 1 1 Strongly Oppose 4 0 1
265 4 very anxious 52 some college female 1 3 2 0 0 0 Oppose 2 0 0

Center emo, recode gender, create interaction terms

framing = framing %>% 
  mutate(emo = emo-mean(emo))

framing = framing %>% 
  mutate(sex=recode(gender, "female" = 1, "male" = 0))

framing = framing %>%
  mutate (treat_emo = treat*emo,
          treat_sex = treat*sex,
          emo_sex = emo*sex)

Single mediator model without covariates (M1) - direct and indirect effects

set.seed (2024)

mediate = mediation::mediate

med.fit1 = lm(emo ~ treat, data = framing) # a path

out.fit1 = glm(cong_mesg ~ emo + treat, data = framing, family = binomial ("probit")) # b path and c' path

med.out1 = mediate(med.fit1, out.fit1, treat = "treat", mediator = "emo", robustSE = TRUE, sims = 1000)


summary(med.out1)
## 
## Causal Mediation Analysis 
## 
## Quasi-Bayesian Confidence Intervals
## 
##                           Estimate 95% CI Lower 95% CI Upper p-value    
## ACME (control)            0.090799     0.043261     0.148024  <2e-16 ***
## ACME (treated)            0.091291     0.043282     0.147557  <2e-16 ***
## ADE (control)             0.011529    -0.098538     0.129061    0.85    
## ADE (treated)             0.012022    -0.109831     0.138365    0.85    
## Total Effect              0.102820    -0.027419     0.228637    0.12    
## Prop. Mediated (control)  0.799388    -3.583906     6.001514    0.12    
## Prop. Mediated (treated)  0.818887    -3.301332     5.615969    0.12    
## ACME (average)            0.091045     0.043369     0.148391  <2e-16 ***
## ADE (average)             0.011776    -0.103855     0.132953    0.85    
## Prop. Mediated (average)  0.809137    -3.447627     5.808741    0.12    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 265 
## 
## 
## Simulations: 1000

M1 - solving for individual coefficients

model1 = 'cong_mesg ~ c*treat 

       
         emo ~ a*treat        
         cong_mesg ~ b*emo
       
         ab := a*b             
       
         total := c + (a*b)   
'
fit1 = sem(model1, data = framing) 
summary(fit1, fit.measures=TRUE, standardized=TRUE,rsquare=TRUE)
## lavaan 0.7-2 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##   Number of observations                           265
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                54.185
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -795.365
##   Loglikelihood unrestricted model (H1)       -795.365
##                                                       
##   Akaike (AIC)                                1600.731
##   Bayesian (BIC)                              1618.629
##   Sample-size adjusted Bayesian (SABIC)       1602.776
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Goodness of Fit Index:
## 
##   Goodness of Fit Index (GFI)                    1.000
##   90 Percent confidence interval - lower         1.000
##   90 Percent confidence interval - upper         1.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   cong_mesg ~                                                           
##     treat      (c)    0.015    0.063    0.231    0.818    0.015    0.014
##   emo ~                                                                 
##     treat      (a)    1.480    0.379    3.906    0.000    1.480    0.233
##   cong_mesg ~                                                           
##     emo        (b)    0.063    0.010    6.276    0.000    0.063    0.368
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .cong_mesg         0.191    0.017   11.511    0.000    0.191    0.862
##    .emo               7.253    0.630   11.511    0.000    7.253    0.946
## 
## R-Square:
##                    Estimate
##     cong_mesg         0.138
##     emo               0.054
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ab                0.093    0.028    3.316    0.001    0.093    0.086
##     total             0.107    0.066    1.626    0.104    0.107    0.099
## lavaan NOTE:  
##    Standard errors and confidence intervals of the (nonlinear) defined (:=) 
##    parameters are based on the first-order delta method; for strongly 
##    nonlinear definitions, se.def = "mc" (Monte Carlo) or se = "bootstrap" may 
##    be more accurate.

M1 - Bootstrapping for indirect effect (ab)

med.out11 = mediate(med.fit1, out.fit1, boot = TRUE, treat = "treat", mediator = "emo", sims = 1000)
## Running nonparametric bootstrap
summary(med.out11)
## 
## Causal Mediation Analysis 
## 
## Nonparametric Bootstrap Confidence Intervals with the Percentile Method
## 
##                            Estimate 95% CI Lower 95% CI Upper p-value    
## ACME (control)            0.0914692    0.0411799    0.1547408  <2e-16 ***
## ACME (treated)            0.0923476    0.0400259    0.1526879  <2e-16 ***
## ADE (control)             0.0095796   -0.0977230    0.1258384   0.862    
## ADE (treated)             0.0104579   -0.1109980    0.1359675   0.862    
## Total Effect              0.1019272   -0.0276142    0.2274098   0.124    
## Prop. Mediated (control)  0.8973980   -4.1840963    7.1683299   0.124    
## Prop. Mediated (treated)  0.9060155   -3.8134399    6.2812620   0.124    
## ACME (average)            0.0919084    0.0410999    0.1544160  <2e-16 ***
## ADE (average)             0.0100188   -0.1042986    0.1308804   0.862    
## Prop. Mediated (average)  0.9017068   -3.9994471    6.7649858   0.124    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 265 
## 
## 
## Simulations: 1000

Model 1 with covariates (M2) - direct and indirect effects

med.fit2 = lm(emo ~ treat + age + educ + sex +income, data = framing)

out.fit2 = glm(cong_mesg ~ emo + treat + age + educ + sex + income, data = framing, family = binomial("probit"))

med.out2 = mediate(med.fit2, out.fit2, treat = "treat", mediator = "emo",
                   robustSE = TRUE, sims = 1000)

summary(med.out2)
## 
## Causal Mediation Analysis 
## 
## Quasi-Bayesian Confidence Intervals
## 
##                            Estimate 95% CI Lower 95% CI Upper p-value   
## ACME (control)            0.0825692    0.0336174    0.1420394   0.002 **
## ACME (treated)            0.0827035    0.0340365    0.1393389   0.002 **
## ADE (control)             0.0091973   -0.1045786    0.1289743   0.880   
## ADE (treated)             0.0093316   -0.1153011    0.1365178   0.880   
## Total Effect              0.0919008   -0.0327006    0.2249734   0.154   
## Prop. Mediated (control)  0.8100225   -7.6754353    7.5767577   0.152   
## Prop. Mediated (treated)  0.8241335   -6.9615413    6.8407080   0.152   
## ACME (average)            0.0826364    0.0337485    0.1405705   0.002 **
## ADE (average)             0.0092645   -0.1093045    0.1330040   0.880   
## Prop. Mediated (average)  0.8170780   -7.3236651    7.1841352   0.152   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 265 
## 
## 
## Simulations: 1000

M2 - individual coefficients

model2 = 'cong_mesg ~ c*treat + age +  sex + income
       
         emo ~ a*treat + age +  sex + income
         cong_mesg ~ b*emo
       
         ab := a*b  
       
         total := c + (a*b)
'
fit2 = sem(model2, data = framing) 
summary(fit2, fit.measures=TRUE, standardized=TRUE,rsquare=TRUE)  
## lavaan 0.7-2 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        11
## 
##   Number of observations                           265
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                76.092
##   Degrees of freedom                                 9
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -784.411
##   Loglikelihood unrestricted model (H1)       -784.411
##                                                       
##   Akaike (AIC)                                1590.823
##   Bayesian (BIC)                              1630.200
##   Sample-size adjusted Bayesian (SABIC)       1595.324
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Goodness of Fit Index:
## 
##   Goodness of Fit Index (GFI)                    1.000
##   90 Percent confidence interval - lower         1.000
##   90 Percent confidence interval - upper         1.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   cong_mesg ~                                                           
##     treat      (c)    0.010    0.062    0.159    0.874    0.010    0.009
##     age               0.002    0.002    1.225    0.221    0.002    0.069
##     sex              -0.122    0.053   -2.316    0.021   -0.122   -0.129
##     income            0.020    0.007    2.936    0.003    0.020    0.166
##   emo ~                                                                 
##     treat      (a)    1.517    0.374    4.051    0.000    1.517    0.239
##     age               0.009    0.010    0.859    0.390    0.009    0.051
##     sex               0.099    0.329    0.300    0.764    0.099    0.018
##     income           -0.102    0.042   -2.422    0.015   -0.102   -0.144
##   cong_mesg ~                                                           
##     emo        (b)    0.067    0.010    6.806    0.000    0.067    0.394
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .cong_mesg         0.181    0.016   11.511    0.000    0.181    0.816
##    .emo               7.059    0.613   11.511    0.000    7.059    0.920
## 
## R-Square:
##                    Estimate
##     cong_mesg         0.184
##     emo               0.080
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ab                0.102    0.029    3.481    0.000    0.102    0.094
##     total             0.111    0.065    1.713    0.087    0.111    0.103
## lavaan NOTE:  
##    Standard errors and confidence intervals of the (nonlinear) defined (:=) 
##    parameters are based on the first-order delta method; for strongly 
##    nonlinear definitions, se.def = "mc" (Monte Carlo) or se = "bootstrap" may 
##    be more accurate.

M2 bootstrapping for indirect effect (ab)

med.out22 = mediate(med.fit2, out.fit2, boot = TRUE, treat = "treat", mediator = "emo", sims = 1000)
## Running nonparametric bootstrap
summary(med.out22)
## 
## Causal Mediation Analysis 
## 
## Nonparametric Bootstrap Confidence Intervals with the Percentile Method
## 
##                           Estimate 95% CI Lower 95% CI Upper p-value   
## ACME (control)            0.084676     0.035120     0.142844   0.002 **
## ACME (treated)            0.085766     0.034584     0.142195   0.002 **
## ADE (control)             0.011616    -0.103141     0.149562   0.832   
## ADE (treated)             0.012706    -0.117830     0.157626   0.832   
## Total Effect              0.097382    -0.040137     0.246686   0.152   
## Prop. Mediated (control)  0.869526    -3.886964     6.588640   0.154   
## Prop. Mediated (treated)  0.880717    -3.515250     6.259787   0.154   
## ACME (average)            0.085221     0.034574     0.142987   0.002 **
## ADE (average)             0.012161    -0.110885     0.153629   0.832   
## Prop. Mediated (average)  0.875121    -3.701546     6.439923   0.154   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 265 
## 
## 
## Simulations: 1000

Moderation effect (M3) - direct and indirect effects

med.fit3 = lm(emo ~ treat + sex + treat_sex + age + educ + income, data = framing)

out.fit3 = glm(cong_mesg ~ treat + emo + sex + treat_sex + emo_sex + age + educ + income, data = framing, family = binomial("probit"))

# Mediated effect for female
med.female = mediate(med.fit3, out.fit3, treat = "treat", mediator = "emo", covariates = list(sex = 1), sims = 1000)

# Mediated effect for male
med.male = mediate(med.fit3, out.fit3, treat = "treat", mediator = "emo",
                   covariates = list(sex=0), sims = 1000)

summary(med.fit3)
## 
## Call:
## lm(formula = emo ~ treat + sex + treat_sex + age + educ + income, 
##     data = framing)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.9090 -2.0655 -0.3542  1.7491  6.6581 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      1.655556   0.886806   1.867  0.06306 .  
## treat                            1.671838   0.535378   3.123  0.00200 ** 
## sex                              0.226423   0.365054   0.620  0.53565    
## treat_sex                       -0.608006   0.723071  -0.841  0.40121    
## age                              0.001259   0.010054   0.125  0.90042    
## educhigh school                 -1.055228   0.634088  -1.664  0.09730 .  
## educsome college                -1.852526   0.666234  -2.781  0.00583 ** 
## educbachelor's degree or higher -3.062183   0.660378  -4.637 5.64e-06 ***
## income                          -0.033484   0.041748  -0.802  0.42326    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.533 on 256 degrees of freedom
## Multiple R-squared:  0.1918, Adjusted R-squared:  0.1666 
## F-statistic: 7.596 on 8 and 256 DF,  p-value: 4.12e-09
summary(out.fit3)
## 
## Call:
## glm(formula = cong_mesg ~ treat + emo + sex + treat_sex + emo_sex + 
##     age + educ + income, family = binomial("probit"), data = framing)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                     -1.236617   0.507492  -2.437 0.014821 *  
## treat                            0.382214   0.296081   1.291 0.196735    
## emo                              0.205294   0.049761   4.126  3.7e-05 ***
## sex                             -0.220780   0.204660  -1.079 0.280693    
## treat_sex                       -0.662937   0.411821  -1.610 0.107448    
## emo_sex                          0.001710   0.067793   0.025 0.979875    
## age                              0.004868   0.005605   0.869 0.385060    
## educhigh school                 -0.205649   0.337480  -0.609 0.542280    
## educsome college                -0.639750   0.365862  -1.749 0.080358 .  
## educbachelor's degree or higher -0.381445   0.369916  -1.031 0.302463    
## income                           0.086807   0.025738   3.373 0.000744 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 336.89  on 264  degrees of freedom
## Residual deviance: 276.55  on 254  degrees of freedom
## AIC: 298.55
## 
## Number of Fisher Scoring iterations: 5
summary(med.male)
## 
## Causal Mediation Analysis 
## 
## Quasi-Bayesian Confidence Intervals
## 
## (Inference Conditional on the Covariate Values Specified in `covariates')
## 
##                           Estimate 95% CI Lower 95% CI Upper p-value   
## ACME (control)            0.101854     0.031817     0.190630   0.004 **
## ACME (treated)            0.106350     0.035959     0.192598   0.004 **
## ADE (control)             0.114317    -0.051157     0.280195   0.180   
## ADE (treated)             0.118812    -0.055537     0.288819   0.180   
## Total Effect              0.220666     0.043773     0.387824   0.014 * 
## Prop. Mediated (control)  0.454610     0.138858     1.628791   0.018 * 
## Prop. Mediated (treated)  0.473360     0.149097     1.593041   0.018 * 
## ACME (average)            0.104102     0.034153     0.191631   0.004 **
## ADE (average)             0.116564    -0.053124     0.285657   0.180   
## Prop. Mediated (average)  0.463985     0.146171     1.610916   0.018 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 265 
## 
## 
## Simulations: 1000
summary(med.female)
## 
## Causal Mediation Analysis 
## 
## Quasi-Bayesian Confidence Intervals
## 
## (Inference Conditional on the Covariate Values Specified in `covariates')
## 
##                           Estimate 95% CI Lower 95% CI Upper p-value   
## ACME (control)            0.095339     0.030709     0.185923   0.002 **
## ACME (treated)            0.102178     0.033833     0.192158   0.002 **
## ADE (control)             0.103152    -0.059548     0.276319   0.244   
## ADE (treated)             0.109990    -0.069308     0.280948   0.244   
## Total Effect              0.205329     0.026661     0.380407   0.020 * 
## Prop. Mediated (control)  0.451443     0.125024     2.200149   0.022 * 
## Prop. Mediated (treated)  0.498001     0.149336     2.095363   0.022 * 
## ACME (average)            0.098759     0.031895     0.188456   0.002 **
## ADE (average)             0.106571    -0.063229     0.281056   0.244   
## Prop. Mediated (average)  0.474722     0.139990     2.170861   0.022 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 265 
## 
## 
## Simulations: 1000
plot(med.male, 
     col = "blue",
     main = "M3: Male")

plot(med.female, 
     col = "pink",
     main = "M3: Female")

M3 - individual coefficients of male and female groups

model3 = 'cong_mesg ~ c(cg1,cg2)*treat

       
         emo ~ c(ag1,ag2)*treat        
         cong_mesg ~ c(bg1,bg2)*emo
       
         ab_g1 := ag1*bg1            
         ab_g2 := ag2*bg2             
       
         total_g1 := cg1 + (ag1*bg1)    
         total_g2 := cg2 + (ag2*bg2)
         
'
fit3 = sem(model3, data = framing,group="sex") 
summary(fit3, fit.measures=TRUE, standardized=TRUE,rsquare=TRUE) 
## lavaan 0.7-2 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations per group:                   
##     0                                              126
##     1                                              139
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                                58.344
##   Degrees of freedom                                 6
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)               -790.855
##   Loglikelihood unrestricted model (H1)       -790.855
##                                                       
##   Akaike (AIC)                                1609.711
##   Bayesian (BIC)                              1659.827
##   Sample-size adjusted Bayesian (SABIC)       1615.439
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Goodness of Fit Index:
## 
##   Goodness of Fit Index (GFI)                    1.000
##   90 Percent confidence interval - lower         1.000
##   90 Percent confidence interval - upper         1.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   cong_mesg ~                                                           
##     treat    (cg1)    0.108    0.096    1.123    0.261    0.108    0.094
##   emo ~                                                                 
##     treat    (ag1)    1.850    0.560    3.304    0.001    1.850    0.282
##   cong_mesg ~                                                           
##     emo      (bg1)    0.068    0.015    4.607    0.000    0.068    0.387
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .cong_mesg         0.371    0.046    8.101    0.000    0.371    0.761
##    .emo              -0.557    0.273   -2.038    0.042   -0.557   -0.200
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .cong_mesg         0.195    0.025    7.937    0.000    0.195    0.820
##    .emo               7.168    0.903    7.937    0.000    7.168    0.920
## 
## R-Square:
##                    Estimate
##     cong_mesg         0.180
##     emo               0.080
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   cong_mesg ~                                                           
##     treat    (cg2)   -0.055    0.082   -0.672    0.502   -0.055   -0.054
##   emo ~                                                                 
##     treat    (ag2)    1.159    0.513    2.257    0.024    1.159    0.188
##   cong_mesg ~                                                           
##     emo      (bg2)    0.058    0.013    4.369    0.000    0.058    0.354
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .cong_mesg         0.289    0.042    6.890    0.000    0.289    0.644
##    .emo              -0.211    0.268   -0.787    0.431   -0.211   -0.077
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .cong_mesg         0.177    0.021    8.337    0.000    0.177    0.879
##    .emo               7.274    0.873    8.337    0.000    7.274    0.965
## 
## R-Square:
##                    Estimate
##     cong_mesg         0.121
##     emo               0.035
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##     ab_g1             0.125    0.047    2.685    0.007    0.125    0.109
##     ab_g2             0.067    0.033    2.006    0.045    0.067    0.067
##     total_g1          0.233    0.100    2.337    0.019    0.233    0.204
##     total_g2          0.012    0.085    0.143    0.886    0.012    0.012
## lavaan NOTE:  
##    Standard errors and confidence intervals of the (nonlinear) defined (:=) 
##    parameters are based on the first-order delta method; for strongly 
##    nonlinear definitions, se.def = "mc" (Monte Carlo) or se = "bootstrap" may 
##    be more accurate.

Bootstrapping male and female samples for indirect effect (ab)

# Male

med.out30 = mediate(med.fit3, out.fit3, boot = TRUE, treat = "treat", mediator = "emo",
                   covariates = list(sex=0), sims = 1000)
## Running nonparametric bootstrap
summary(med.out30)
## 
## Causal Mediation Analysis 
## 
## Nonparametric Bootstrap Confidence Intervals with the Percentile Method
## 
## (Inference Conditional on the Covariate Values Specified in `covariates')
## 
##                           Estimate 95% CI Lower 95% CI Upper p-value   
## ACME (control)            0.104989     0.028671     0.199485   0.002 **
## ACME (treated)            0.111307     0.029872     0.197394   0.002 **
## ADE (control)             0.117463    -0.066977     0.314680   0.208   
## ADE (treated)             0.123781    -0.071890     0.317275   0.208   
## Total Effect              0.228770     0.025164     0.429102   0.028 * 
## Prop. Mediated (control)  0.458928     0.111284     1.953191   0.030 * 
## Prop. Mediated (treated)  0.486546     0.124012     1.876747   0.030 * 
## ACME (average)            0.108148     0.029268     0.197168   0.002 **
## ADE (average)             0.120622    -0.069904     0.314433   0.208   
## Prop. Mediated (average)  0.472737     0.115263     1.914969   0.030 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 265 
## 
## 
## Simulations: 1000
# Female

med.out31 = mediate(med.fit3, out.fit3, boot = TRUE, treat = "treat", mediator = "emo", covariates = list(sex = 1), sims = 1000)
## Running nonparametric bootstrap
summary(med.out31)
## 
## Causal Mediation Analysis 
## 
## Nonparametric Bootstrap Confidence Intervals with the Percentile Method
## 
## (Inference Conditional on the Covariate Values Specified in `covariates')
## 
##                           Estimate 95% CI Lower 95% CI Upper p-value   
## ACME (control)            0.097037     0.025141     0.196250   0.006 **
## ACME (treated)            0.108803     0.026581     0.204371   0.006 **
## ADE (control)             0.108888    -0.055233     0.296616   0.190   
## ADE (treated)             0.120654    -0.061036     0.302604   0.190   
## Total Effect              0.217691     0.023116     0.415958   0.030 * 
## Prop. Mediated (control)  0.445755     0.093263     1.851392   0.032 * 
## Prop. Mediated (treated)  0.499806     0.110593     1.721065   0.032 * 
## ACME (average)            0.102920     0.027028     0.199626   0.006 **
## ADE (average)             0.114771    -0.058925     0.301207   0.190   
## Prop. Mediated (average)  0.472780     0.101992     1.786012   0.032 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 265 
## 
## 
## Simulations: 1000

Moderation significance test between males and females

med.init = mediate(med.fit3, out.fit3, treat = "treat", mediator = "emo", sims = 1000)

test.modmed(med.init, covariates.1 = list(sex=1), covariates.2 = list(sex=0))
## 
##  Test of ACME(covariates.1) - ACME(covariates.2) = 0
## 
## data:  estimates from med.init
## ACME(covariates.1) - ACME(covariates.2) = -0.0015659, p-value = 0.998
## alternative hypothesis: true ACME(covariates.1) - ACME(covariates.2) is not equal to 0
## 95 percent confidence interval:
##  -0.1219402  0.1044566
## 
## 
##  Test of ADE(covariates.1) - ADE(covariates.2) = 0
## 
## data:  estimates from med.init
## ADE(covariates.1) - ADE(covariates.2) = -0.0014891, p-value = 0.998
## alternative hypothesis: true ADE(covariates.1) - ADE(covariates.2) is not equal to 0
## 95 percent confidence interval:
##  -0.2352679  0.2296625