I am trying to conduct a mediation analysis in R using a mediation package. I looked at the documentation on how to do this and read the examples provided by R (i.e. I already completed the βexample (mediator)β). Despite this, I cannot get the simplest mediation. Ideally, I would like to do a bootstrap procedure, a la Preacher and Hayes (2004).
Here is the code I'm trying to run:
model.m <- lm(desirdata1$zpers1 ~ desirdata1$zdesir1 + desirdata1$age) model.y <- lm(desirdata1$zpers1 ~ desirdata1$age) age1test <- mediate(model.m, model.y,treat="age", mediator="zdesir1", boot=TRUE, sims=50)
Note that the dataset is called desirdata , the processing is called age , the result is called zpers1 , and the pick is called "zdesir1". When I run this, I get the following error:
Error in `[.data.frame`(m.data, , treat) : undefined columns selected
It seems to be argued that the variable (in particular, the processing variable) does not exist. However, running names (desirdata) show that the variable is there, and it is named correctly, like all other variables. The first two models (model.m and model.y) work fine, and the result looks as it should. This is just a mediation model that I cannot run. As far as I can tell, I did not make a typo, and I checked it a hundred times.
Thoughts?
source share