#For illustration purposes simulations set to low number.
#Example with JOBS II Field experiment
data(jobs)
####################################################
#Continuous Outcome - Continuous Mediator--Equivalent to Baron-Kenny Method
####################################################
b <- lm(job_seek ~ treat + econ_hard + sex + age, data=jobs)
c <- lm(depress2 ~ treat + job_seek + depress1 + econ_hard + sex + age, data=jobs)
#Calculates quantities using parametric bootstrap
#The general format of the function is to record two model objects
#The first for the mediator the second for the outcome variable
continuous <- mediate(b, c, sims=1000, T="treat", M="job_seek")
summary(continuous)
#Calculates quantities using the non-parametric bootstrap - This takes several minutes
continuous_boot <- mediate(b, c, boot=TRUE, T="treat", M="job_seek")
summary(continuous_boot)
#INTERACTION TERM BTWN TREATEMENT AND MEDIATOR IS INCLUDED IN THE MODEL
b <- lm(job_seek ~ treat + depress1, data=jobs)
d <- lm(depress2 ~ treat + job_seek + treat:job_seek + depress1, data=jobs)
cont.int <- mediate(b, d, sims=10, INT=TRUE, T="treat", M="job_seek")
summary(cont.int)
######################################################
#Binary Outcome
######################################################
b <- lm(job_seek ~ treat + depress1, data=jobs)
c <- glm(work1 ~ treat + job_seek + depress1, family=binomial(link="probit"), data=jobs)
binary <- mediate(b, c, T="treat", M="job_seek")
summary(binary)
Run the code above in your browser using DataLab