[R] Mediation analysis
Michael Friendly
friendly at yorku.ca
Wed Aug 1 03:19:41 CEST 2012
Subset your data first and/or use the data= and subset= arguments to
lm() so the same data is used in all models.
On 7/31/2012 2:14 PM, jawortman wrote:
> 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