#Example with JOBS II Field experiment
#For illustration purposes simulations set to low number.
#Example with JOBS II Field experiment
data(jobs)
#########################################
#continuous mediator and continuous outcome
#########################################
#fit parametric model
model.m <- lm(job_seek ~ treat + depress1 + econ_hard + sex + age + occp + marital + nonwhite + educ + income, data=jobs)
model.y <- lm(depress2 ~ treat + job_seek + depress1 + econ_hard + sex + age + occp + marital + nonwhite + educ + income, data=jobs)
#pass model objects through medsens function
sens.cont <- medsens(model.m, model.y, T="treat", M="job_seek", INT=FALSE, DETAIL=FALSE, sims=1000)
#use summary function to display values of rho where 95summary(sens.cont)
#plot mediation effect and 95plot(sens.cont, main="JOBS", ylim=c(-.2,.2))
#########################################
#binary outcome and continuous mediator
#########################################
model.m <- lm(job_seek ~ treat + depress1 + econ_hard + sex + age + occp + marital + nonwhite + educ + income, data=jobs)
model.y <- glm(work1 ~ treat + job_seek + depress1 + econ_hard + sex + age + occp + marital + nonwhite + educ + income, family=binomial(link="probit"), data=jobs)
sens.dichO <- medsens(model.m, model.y, T="treat", M="job_seek", INT=FALSE, DETAIL=FALSE)
summary(sens.dichO)
plot(sens.dichO, main="JOBS", ylim=c(-.2,.2))
Run the code above in your browser using DataLab