[Mediation-information] moderated mediation analysis using 'mediation' package

Teppei Yamamoto teppei at MIT.EDU
Fri Mar 23 12:57:56 CET 2012


Hi Liviu,

Glad that you got it to work and thanks for your feedback. We'll consider that for future updates. For now though, people can use your code as a template (and we can refer to it when asked). 

Best, 
Teppei

=========================
Teppei Yamamoto
Assistant Professor
Department of Political Science
MIT
teppei at mit.edu
=========================


On Mar 23, 2012, at 7:10, Liviu Andronic <landronimirc at gmail.com> wrote:

> Hello
> 
> 
> On Thu, Mar 22, 2012 at 7:47 PM, Teppei Yamamoto <teppei at mit.edu> wrote:
>> One thing you could do is to set the moderator to different values along its
>> range (running a separate mediate call for each of those values) and plot
>> the estimated mediation effects against those moderator values. That way,
>> you will see how the indirect effect (or direct effect if that's what you
>> are more interested in) varies as a function of the moderator, which I think
>> is exactly the goal of moderated mediation analysis.
>> 
> Thank you again for all the explanations.
> 
> I managed to estimate the mediation effect over the range of the
> mediator (although it's quite CPU-consuming)
> #estimate mediation effects
> med_c <- lapply(quantile(modmed$ENGAGESP), function(x){
>    mediate(mod.m2, mod.y2, dropobs=F, treat='EVPUBLIC', mediator='TRUST',
>    covariates=list(ENGAGESP=x),  boot=T, sims=50)
> })
> 
> 
> and then plotting the resulting objects
> #plot mediation effects
> par(mfrow=c(2,3))
> lapply(1:length(med_c), function(x) plot(med_c[[x]], main=names(med_c[x])))
> par(mfrow=c(1,1))
> 
> 
> and subsequently plot the estimated mediation effects against the
> moderator values.
> #plot the estimated mediation effects against the moderator values
> (xa <- ldply(1:length(med_c), function(x)
> data.frame(med_c[[x]][c('d0', 'z0')])))
> plot(quantile(modmed$ENGAGESP), xa[,'d0'])
> plot(quantile(modmed$ENGAGESP), xa[,'z0'])
> 
> 
> This wasn't immediately straightforward, however, and required some
> vectorizing magic. Could 'mediation' provide some functions or methods
> that would help automating some of the procedures above?
> 
> Regards
> Liviu


More information about the Mediation-information mailing list