Lab 5 - Conditional Indirect Effects

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

Adam Garber

May 05, 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”
  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)

Upload list of mplus.R functions

http://www.statmodel.com/mplus-R/mplus.R

## [1] "Loaded rhdf5 package"

Lab outline

  1. Run a simple moderation model with binary moderator (re-coded)
  2. Plot simple slopes with ggplot using data extracted from gh5 file produced by Mplus output
  3. Run a parallel model with interaction between two continuous variables
  4. Estimate a conditional mediation model with the teams data

Data sources:

Models are adapted to demonstrate moderation and conditional mediation effects:

  1. The first two examples utilize the Vocabulary and Education dataset from the National Opinion Research Center General Social Survey. GSS Cumulative Datafile 1972-2016 (Fox, 2008) \(\color{blue}{\text{See documentation here}}\)

To see metadata run - ?carData::Vocab

  1. The third example is from chapter 3 of the book, Regression and mediation analysis using Mplus, by Muthen et al., 2017. The dataset is called teams and is from a study about automobile parts work teams (Cole et al., 2008). This model is also discussed in the Hayes (2013) book on mediation.

Read the Vocab dataframe into your R-environment from package {carData}


Starting with a familiar example
Name Labels
year Year of the survey (1974 - 2016)
sex Sex of the respondent (Female or Male)
education Students education in years
vocabulary Vocabulary test score: number correct on a 10-word test

\[ \color{red}{\text{vocabulary}} = \alpha + \beta_{1}(\color{blue}{\text{year}}) + \beta_{2}(\color{green}{\text{education}}) + \beta_{3}(\color{blue}{\text{year}} \times \color{green}{\text{education}}) + \epsilon \]


Model 2: Run moderation with continuous moderator variable year (range: 1- 42)


Prepare plot data

Plot simple slopes moderation plot with standard error bands

Save plot

Create interactive plot with {ggplotly}


Conditional indirect effect model

This version of of moderated mediation is described as case 2 in the Muthen et al. (2016) text.

Name Labels
dysfunc (X) Dysfunctional behavior of team members
negexp (Z) Nonverbal negative expressibility between team members (measured by supervisor)
negtone (M) Negative affective tone expressed by team members
perform (Y) Team performance using measures of efficiency, timeliness, and objectives

Read in data

Model 3: Estimate conditional indirect effect model

Model 3 Mplus output

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

 Effects from DYSFUNC to PERFORM for NEGEXP = -0.100
    
      Tot natural IE      -0.088      0.045     -1.939      0.052
      Pure natural DE      0.135      0.069      1.962      0.050
      Total effect         0.047      0.071      0.664      0.507
      
    Effects from DYSFUNC to PERFORM for NEGEXP = 0.000
    
      Tot natural IE      -0.100      0.045     -2.194      0.028
      Pure natural DE      0.135      0.069      1.962      0.050
      Total effect         0.035      0.073      0.488      0.626
    
    Effects from DYSFUNC to PERFORM for NEGEXP = 0.100
    
      Tot natural IE      -0.111      0.047     -2.391      0.017
      Pure natural DE      0.135      0.069      1.962      0.050
      Total effect         0.024      0.075      0.316      0.752

View available plots from the Mplus model

Take a look at bootstrap distribution of the indirect effect to view asymptotic shape.

Create an animation depicting draws of the bootstrap distribution with {gganimate}


To see animation of how the bootsrap distribution changes with increasing sample draws (N) go here: https://raw.githubusercontent.com/minimaxir/frames-to-gif-osx/master/examples/uni_frames.gif


Create plot of moderated direct and indirect effects

Save plot


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