Edwards Moderated Mediation in R
This helper script runs Edwards & Lambert’s (2007) moderated mediation analysis using basic OLS regressions from Equations 5 and 20 of the article. The first step is to estimate both regression models using lm(). Something like:
lmm <- lm(m ~ {controls} + x + xz + z,data=dat)
lmy <- lm(y ~ {controls} + x + xz + z + m,data=dat)
After estimating both models, bootstrap samples from the data and recompute the same models. Then compute confidence intervals for those distributions. Note that at present the script only computes the percentile method (the bias-corrected CI would be better in a revised version).
source('edwards.modmed.R')
coefs <- bootstrap(lmm,lmy,dat)
edwards.modmed(coefs=coefs,lmm=lmm,lmy=lmy,zlevels=c(-1*sd(dat$z),sd(dat$z)),p=.05)
The z-levels here assume z is centered (a mean of zero simplifies calculating the levels of z to calculate the effect of x). These should be adjusted if z is not centered.