[R] Mediation analysis

jawortman jwortman at gmail.com
Tue Jul 31 20:14:45 CEST 2012


Hello all,

I apologize for the simplistic question, but I have been having some trouble
learning how to do mediation analysis in R. Ideally, I would like to use
Preacher's Bootstrapping test for mediation (Preacher & Hayes, 2004). I have
attempted to use the mediate package to set this up, using code that looks
basically like this:

model.m <- lm(data$outcome ~ data$mediator + desirdata$predictor)
model.y <- lm(data$outcome ~ data$predictor)
age1 <- mediate(model.m, model.y, treat = "predictor", mediator =
"mediator", conf.level=.95, boot=TRUE, sims=50)

 However, I get an error indicating that the number of observations doesn't
match across the two models. This may be true,  because it's a somewhat
large sample (13,000) with a pretty substantial amount of missing data, but
I'm not sure how to deal with that issue. Is there any way to get this to
run given that there may be different numbers of observations in the two
models?

Thanks,

Jessica



--
View this message in context: http://r.789695.n4.nabble.com/Mediation-analysis-tp4638577.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list