Department of Data Analysis Ghent University Software for mediation analysis Yves Rosseel Department of Data Analysis Ghent University – Belgium Symposium on Causal Mediation Analysis January 28–29, 2013 – Ghent University Yves Rosseel Software for mediation analysis 1 / 32
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Department of Data Analysis Ghent University
Software for mediation analysis
Yves RosseelDepartment of Data AnalysisGhent University – Belgium
Symposium on Causal Mediation AnalysisJanuary 28–29, 2013 – Ghent University
Yves Rosseel Software for mediation analysis 1 / 32
Department of Data Analysis Ghent University
Software for mediation analysis – two traditions• traditional software for mediation analysis
– Baron and Kenny (1986) tradition
– many applied researchers still follow these steps
– using SPSS/SAS, often in combination with macros/scripts
– modern approach: using SEM software
– psychologists are very familiar with this approach
• modern software for mediation analysis:
– based on the causal inference literature
– custom macros/code available for SPSS, SAS, Stata, R, . . .
– psychologists are very unfamiliar with this approach(and the accompanying software)
Yves Rosseel Software for mediation analysis 2 / 32
Department of Data Analysis Ghent University
Some links and resources
• traditional approaches (mostly non-SEM)
– Andrew F. Hayes website (‘My Macros and Code for SPSS and SAS’):http://www.afhayes.com/
– Kristopher J. Preacherhttp://quantpsy.org/medn.htm
– David A. Kennyhttp://davidakenny.net
• approaches based on the counterfactual framework
– Valeri, L. and VanderWeele, T.J. (in press). Mediation analysis allow-ing for exposure-mediator interactions and causal interpretation: theo-retical assumptions and implementation with SAS and SPSS macros.Psychological Methods
Yves Rosseel Software for mediation analysis 3 / 32
Department of Data Analysis Ghent University
Software for SEMCommercial – closed-source
• LISREL, EQS, AMOS, MPLUS
• SAS/Stat: proc CALIS, proc TCALIS
• SEPATH (Statistica), RAMONA (Systat), Stata 12
• Mx (free, closed-source)
Non-commercial – open-source
• outside the R ecosystem: gllamm (Stata), . . .
• R packages:
– sem
– OpenMx
– lavaan
Yves Rosseel Software for mediation analysis 4 / 32
Department of Data Analysis Ghent University
What is lavaan?• lavaan is an R package for latent variable analysis:
– confirmatory factor analysis: function cfa()– structural equation modeling: function sem()– latent curve analysis / growth modeling: function growth()– general mean/covariance structure modeling: function lavaan()– support for continuous, binary and ordinal data
• under development, future plans:
– multilevel SEM, mixture/latent-class SEM, Bayesian SEM
• the long-term goal of lavaan is
1. to implement all the state-of-the-art capabilities that are currently avail-able in commercial packages
2. to provide a modular and extensible platform that allows for easy im-plementation and testing of new statistical and modeling ideas
Yves Rosseel Software for mediation analysis 5 / 32
Department of Data Analysis Ghent University
Installing lavaan, finding documentation
• lavaan depends on the R project for statistical computing:
http://www.r-project.org
• to install lavaan, simply start up an R session and type:
> install.packages("lavaan")
• more information about lavaan:
http://lavaan.org
• the lavaan paper:
Rosseel (2012). lavaan: an R package for structural equationmodeling. Journal of Statistical Software, 48(2), 1–36.
• lavaan development:
https://github.com/yrosseel/lavaan
Yves Rosseel Software for mediation analysis 6 / 32
Yves Rosseel Software for mediation analysis 21 / 32
Department of Data Analysis Ghent University
Mediation with an ordinal mediation, and a binary outcome
intervention
intention
ciguse
a
c
b
model <- ’ciguse ˜ c*intervention +
b*intentionintention ˜ a*intervention
naive.indirect := a*bnaive.direct := c
’
fit <- sem(model, data=myData,ordered=c("ciguse","intention"))
summary(fit)
Muthen, B. Applications of Causally Defined Direct and Indirect Effects in Mediation Analysis usingSEM in Mplus. (retrieved from www.statmodel.com)
MacKinnon, D. P., Lockwood, C. M., Brown, C.H., and Hoffman, J. M. (2007). The intermediateendpoint effect in logistic and probit regression. Clinical Trials, 4, 499 - 513.
Yves Rosseel Software for mediation analysis 22 / 32
Defined parameters:naive.indirct -0.155 0.057 -2.713 0.007naive.direct -0.130 0.093 -1.402 0.161
Yves Rosseel Software for mediation analysis 23 / 32
Department of Data Analysis Ghent University
Computing ‘causal’ direct and indirect effects
• Imai et al. (2010) showed in a simulation study that the naive approach(taking the product of coefficients) results in biased estimates of the directand indirect effects
• But we can compute the correct estimates using the parameter values ascomputed in a SEM
• References:
Muthen, B. Applications of Causally Defined Direct and IndirectEffects in Mediation Analysis using SEM in Mplus.
http://www.statmodel.com/examples/penn.shtml
Yves Rosseel Software for mediation analysis 24 / 32
Department of Data Analysis Ghent University
lavaan syntax - computing probits and probabilities
Yves Rosseel Software for mediation analysis 26 / 32
Department of Data Analysis Ghent University
The R package ‘mediation’• References:
Imai, K., Keele, L. and Tingley, D. (2010) A General Approachto Causal Mediation Analysis, Psychological Methods, 15(4), pp.309-334.
Tingley, D., Yamamoto, T., Keel, L. and Imai, K. (under review).mediation: R Package for Causal Mediation Analysis.imai.princeton.edu/research/files/mediationR2.pdf
• ‘General’ approach to causal mediation analysis, based on the counterfactualframework
• accomodates linear and nonlinear relationships, parametric and nonparamet-ric models, continuous and discrete mediators, various types of outcomes
• allows for a sensitivity analysis
Yves Rosseel Software for mediation analysis 27 / 32
Department of Data Analysis Ghent University
The jobs example - linear model for outcome and mediator
treat
job.seek
depress2
econ.hardsexage
a
c
b
• job_seek: level of job-searchself-efficacy
• econ_hard: level of eco-nomic hardship pre-treatment
# model for Mmodel.M <-lm(job_seek ˜ treat +
econ_hard + sex + age,data=jobs)
# model for Ymodel.Y <-lm(depress2 ˜ treat + job_seek +
econ_hard + sex + age,data=jobs)
# Estimation via quasi-Bayesian approx.out <- mediate(model.M,
model.Y,treat = "treat",mediator = "job_seek")
summary(out)
Yves Rosseel Software for mediation analysis 28 / 32
Department of Data Analysis Ghent University
outputCausal Mediation Analysis
Quasi-Bayesian Confidence Intervals
Estimate 95% CI Lower 95% CI Upper p-valueMediation Effect -0.01600 -0.04191 0.00673 0.21Direct Effect -0.04091 -0.12296 0.04441 0.34Total Effect -0.05690 -0.14009 0.03313 0.22Proportion via Mediation 0.23156 -1.70527 3.26928 0.44
Sample Size Used: 899
Simulations: 1000
Yves Rosseel Software for mediation analysis 29 / 32
Department of Data Analysis Ghent University
The jobs example - binary outcome and ordered (K=4) mediator
treat
job.disc
work1
econ.hardsexage
a
c
b
• job_disc: The job_seekmeasure recoded into four cate-gories from lowest to highest