• newscoding@gmail.com

Monthly ArchiveFebruary 2020

Mediation Package in R

By Chenyan Jia

install.packages("mediation")
library(mediation)

<code>results <- mediate(model.mediator = mod3, model.y = mod2, treat='exercise', mediator='food', boot=TRUE, sims=500)</code>
results <- mediate(model.mediator = mod3, model.y = mod2, treat='exercise', mediator='food', boot=TRUE, sims=500)
# "model.mediator": a fitted model object for mediator.
# "model.y": a fitted model object for outcome (using both the focal and mediator variables)
# "treat" a character string indicating the name of the treatment variable
# "mediator": a character string indicating the name of the mediator variable

# Typically bootstrap sample size ranges between 1000 ~ 5000. Remember, only use small simulations because our data are small.

How to decipher the results?
## ACME: Average Causal Mediation Effects
## ADE: Average Direct Effects
## Total Effect: Sum of a mediation (indirect) effect and a direct effect
## Prop. Mediated: Size of the average causal mediation effects relative to the total effect.
## When ACME is significant and ADE is not significant, a complete mediation happens (Direct effects are not significant any more because of the mediator ) 

An Example of Results