#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, data=jobs)
model.y <- lm(depress2 ~ treat + job_seek + depress1, 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 95% confidence interval overlaps with 0.
summary(sens.cont)
#plot mediation effect and 95% CI's for each value of rho
plot(sens.cont, main="JOBS", ylim=c(-.2,.2))
#########################################
#binary outcome and continuous mediator
#########################################
model.m <- lm(job_seek ~ treat + depress1, data=jobs)
model.y <- glm(work1 ~ treat + job_seek + depress1, 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))
#########################################
#continuous outcome and binary mediator w no interaction
#########################################
model.m <- glm(job_dich ~ treat + depress1, data=jobs, family=binomial(link="probit"))
model.y <- lm(depress2 ~ treat + job_dich + depress1, data=jobs)
sens.dichM <- medsens(model.m, model.y, T="treat", M="job_dich", INT=FALSE, DETAIL=FALSE)
summary(sens.dichM)
plot(sens.dichM, main="JOBS", ylim=c(-.2,.2))
#########################################
#continuous outcome and binary mediator w interaction
#########################################
model.m <- glm(job_dich ~ treat + depress1, data=jobs, family=binomial(link="probit"))
model.y <- lm(depress2 ~ treat + job_dich + treat:job_dich + depress1, data=jobs)
sens.dichM.int <- medsens(model.m, model.y, T="treat", M="job_dich", INT=TRUE, DETAIL=FALSE)
summary(sens.dichM.int)
plot(sens.dichM.int, main="JOBS", ylim=c(-.2,.2))
Run the code above in your browser using DataLab