[Mediation-information] moderated mediation analysis using 'mediation' package
Liviu Andronic
landronimirc at gmail.com
Fri Mar 23 12:10:57 CET 2012
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