-1

I'm trying to run a multilevel mediation analysis in R. I get the error: Error in mediate(model.M, model.Y, treat = "treat", mediator = mediator, data=data): number of observations do not match between mediator and outcome models

Models M and Y are multilevel lme4 models, and there are uneven sample sizes in these models. Is there anything I can do to run this analysis? Will it really only run if I have the same sample sizes in each model?

DRFeinberg
  • 77
  • 1
  • 6

1 Answers1

0

Fit the model with less observations first (which is, I guess, model.Y, because that model has more predictors and thus is more likely to have more missings), then use the model frame from that model as data for the 2nd model:

model.M <- lmer(..., data = model.Y@frame)

That should work.

Daniel
  • 7,252
  • 6
  • 26
  • 38