R Mediation Analysis -- Bootstrapping
As I read the examples in the documentation, the model.m
for the mediator model will have different outcome than that for the main regression object model.y
. Since you haven't described the background and what sorts of data it's hard to be very certain of this, but wondering if you meant to type:
model.m <- lm(zdesir1 ~ age, data=desirdata1)
model.y <- lm(zpers1 ~ age, , data=desirdata1 )
age1test <- mediate(model.m, model.y,treat="age", mediator="zdesir1",
boot=TRUE, sims=50)
I cast it using formula
and data
objects, since some regression functions break down when just given vectors. Also makes it easier to see typos.
Your models are not correct. model.m should predict the mediator from the IV, and model.y should predict the DV from the mediator and IV.
model.m <- lm(desirdata1$zdesir1 ~ desirdata1$age)
model.y <- lm(desirdata1$zpers1 ~ desirdata1$zdesir1 + desirdata1$age)
age1test <- mediate(model.m, model.y, treat="age", mediator="zdesir1", boot=TRUE, sims=50)