Lab 4 - Mediation

Structural Equation Modeling ED 216F - Instructor: Karen Nylund-Gibson

Adam Garber

April 24, 2020


Lab preparation


Creating a version-controlled R-Project with Github

Download repository here: https://github.com/garberadamc/SEM-Lab4

On the Github repository webpage:

  1. fork your own branch of the lab repository
  2. copy the repository web URL address from the clone or download menu

Within R-Studio:

  1. click “NEW PROJECT” (upper right corner of window)
  2. choose option Version Control
  3. choose option Git
  4. paste the repository web URL path copied from the clone or download menu on Github page
  5. choose location of the R-Project (too many nested folders will result in filepath error)

Lab outline

  1. Estimate a mediation model using the {mediation} package
  2. Estimate the same model using the Structural Equation Modeling (SEM) framework with {MplusAutomation}
  3. For the second empirical example, estimate parallel models using the mediation and SEM methods

A quick detour - Equivalent models

Figure. Picture adapted from SEM slides by Sacha Epskamp http://sachaepskamp.com/files/SEM22019/SEM2_2019_Week2_slides.pdf


Have you ever seen the perfect table and want to adapt it for your own research purposes?

Use {datapasta} by copying tables and pasting them automatically as tribbles or dfs

  1. copy a table or data matrix
  2. run the fuction tribble_paste() or df_paste()

The empirical examples of mediation used in this exercise are from the following article

Tingley, D., Yamamoto, T., Hirose, K., Keele, L., & Imai, K. (2014). Mediation: R package for causal mediation analysis.

https://cran.r-project.org/web/packages/mediation/vignettes/mediation.pdf


Data source for example 1

Brader T, Valentino NA, Suhat E (2008). What Triggers Public Opposition to Immigration? Anxiety, Group Cues, and Immigration. American Journal of Political Science, 52(4), 959–978.

https://onlinelibrary.wiley.com/doi/pdf/10.1111/j.1540-5907.2008.00353.x

To see metadata run - ?framing


Read in the framing dataset


Take a look at variables used in the mediation model
Name Labels Variable status
emo Measure of subjects’ negative feeling during the experiment (1-10). 1 indicates the most negative feeling. Mediator (Z)
treat Framing codition interaction term. News story with conditions tone (Negative/Positive) and ethnic identity cue (Latino/European) Treatment (X)
cong_mesg Whether subjects requested sending an anti-immigration message to Congress on their behalf. Outcome (Y)
age Age of subject (18-85) pre-treatment covariate
educ Education (1-4) pre-treatment covariate
gender Gender (Male/Female) pre-treatment covariate
income Subjects’ income, measured as a 19-point scale. pre-treatment covariate

Look at descriptives table for the framing dataset using {gtsummary}

Characteristic N = 2651
emo 4.97 (2.77)
treat 68 (26%)
cong_mesg 88 (33%)
age 48 (16)
educ
less than high school 20 (7.5%)
high school 92 (35%)
some college 70 (26%)
bachelor's degree or higher 83 (31%)
gender
male 126 (48%)
female 139 (52%)
income 11 (4)

1 Statistics presented: mean (SD); n (%)



Estimate a mediation model in R using {mediation}

step 1: fit a linear model of the mediator (emo) regressed on treatment (treat) and pre-treatment covariates


step 2: fit a general linear model (glm) with the binary outcome variable cong_mesg regressed on treatment (treat), mediator, and pre-treatment covariates


step 3: estimate the mediation effects with bias corrected bootstrapped confidence intervals

## 
## Causal Mediation Analysis 
## 
## Nonparametric Bootstrap Confidence Intervals with the BCa Method
## 
##                          Estimate 95% CI Lower 95% CI Upper p-value    
## ACME (control)             0.0824       0.0246         0.13  <2e-16 ***
## ACME (treated)             0.0835       0.0239         0.14  <2e-16 ***
## ADE (control)              0.0113      -0.0921         0.12    0.70    
## ADE (treated)              0.0124      -0.1051         0.13    0.70    
## Total Effect               0.0948      -0.0205         0.25    0.16    
## Prop. Mediated (control)   0.8693     419.1265       666.19    0.16    
## Prop. Mediated (treated)   0.8808     369.2224       586.64    0.16    
## ACME (average)             0.0829       0.0224         0.13  <2e-16 ***
## ADE (average)              0.0118      -0.0991         0.12    0.70    
## Prop. Mediated (average)   0.8751     394.1745       626.42    0.16    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 265 
## 
## 
## Simulations: 100

Data source for example 2

Vinokur AD, Price RH, Schul Y (1995). Impact of the JOBS Intervention on Unemployed Workers Varying in Risk for Depression. American Journal of Community Psychology, 23(1), 39–74.

https://link.springer.com/content/pdf/10.1007/BF02506922.pdf

To see metadata run - ?jobs


Note: For this example we will ignore the issue of non-compliance addressed in Tingley et al. (2014) as this causal inference topic is beyond the scope of this course.

Read in the data from the job search intervention study (jobs)

Take a look at variables used in the mediation model
Name Label
depress2 (Y) Measure of depressive symptoms post-treatment.
treat (X) Indicator variable for whether participant was randomly selected for the JOBS II training program. 1 = assignment to participation.
job_dich (Z) The job_seek measure recoded into two categories of high and low. 1 = high job search self-efficacy.
sex Indicator variable for sex. 1 = female
age Age in years.
marital Factor with five categories for marital status.
nonwhite Indicator variable for race. 1 = nonwhite.
educ Factor with five categories for educational attainment.
income Factor with five categories for level of income.

Look at descriptives of the framing dataset using {gtsummary}



step 1: fit a binomial logist model using glm with the binary mediator (job_dich) regressed on treatment (treat) and pre-treatment covariates


step 2: fit a linear model with depression score (depress2) regressed on treatment, mediator, and pre-treatment covariates


step 3: Estimate the mediation effects with bias corrected bootstrapped confidence intervals.

## 
## Causal Mediation Analysis 
## 
## Nonparametric Bootstrap Confidence Intervals with the BCa Method
## 
##                Estimate 95% CI Lower 95% CI Upper p-value    
## ACME            -0.0145      -0.0571        -0.01  <2e-16 ***
## ADE             -0.0306      -0.1047         0.04    0.56    
## Total Effect    -0.0451      -0.1350         0.03    0.30    
## Prop. Mediated   0.3208     -78.0586         0.15    0.30    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Sample Size Used: 899 
## 
## 
## Simulations: 100

Run model 3 including the mediator*treatement interaction (potential outcomes framework)

For further reading on this topic see chapter 3 of Regression and mediation analysis using Mplus (Muthen et al., 2017)



Model 3 Mplus output

TOTAL, INDIRECT, AND DIRECT EFFECTS BASED ON COUNTERFACTUALS (CAUSALLY-DEFINED EFFECTS)

Effects from TREAT to DEPRESS2

                 Estimate       S.E.  Est./S.E.    P-Value

  Tot natural IE      -0.026      0.011     -2.357      0.018
  Pure natural DE     -0.022      0.055     -0.401      0.688
  Total effect        -0.048      0.055     -0.878      0.380

 Other effects

  Pure natural IE     -0.023      0.012     -1.938      0.053
  Tot natural DE      -0.026      0.052     -0.494      0.621
  Total effect        -0.048      0.055     -0.878      0.380

References

Brader T, Valentino NA, Suhat E (2008). What Triggers Public Opposition to Immigration? Anxiety, Group Cues, and Immigration. American Journal of Political Science, 52(4), 959–978.

Hallquist, M. N., & Wiley, J. F. (2018). MplusAutomation: An R Package for Facilitating Large-Scale Latent Variable Analyses in Mplus. Structural equation modeling: a multidisciplinary journal, 25(4), 621-638.

Ingels, S. J., Pratt, D. J., Herget, D. R., Burns, L. J., Dever, J. A., Ottem, R., … & Leinwand, S. (2011). High School Longitudinal Study of 2009 (HSLS: 09): Base-Year Data File Documentation. NCES 2011-328. National Center for Education Statistics.

Muthén, B. O., Muthén, L. K., & Asparouhov, T. (2017). Regression and mediation analysis using Mplus. Los Angeles, CA: Muthén & Muthén.

Muthén, L.K. and Muthén, B.O. (1998-2017). Mplus User’s Guide. Eighth Edition. Los Angeles, CA: Muthén & Muthén

R Core Team (2017). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL http://www.R-project.org/

Tingley, D., Yamamoto, T., Hirose, K., Keele, L., & Imai, K. (2014). Mediation: R package for causal mediation analysis.

Vinokur AD, Price RH, Schul Y (1995). Impact of the JOBS Intervention on Unemployed Workers Varying in Risk for Depression. American Journal of Community Psychology, 23(1), 39–74.

Wickham et al., (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686, https://doi.org/10.21105/joss.01686