# Mediation package error message with group level mediator (bug?)

I am trying to use the mediation package with multilevel data and a group level mediator. I am getting a "groups do not match between mediator and outcome models" error message.
However, I have checked multiple times and the group definitely DO match (I provided some code snippets below). Has anyone else run into this problem and have a possible solution?

#Here is the code that results in the error message

med.fit2 <- lm(Z_lin~ANY_FK,data=toca3)

out.fit2 <- lmer(post_neq~Z_lin+ANY_FK+(1|siteid),data=stoc3)

med.out2 <- mediate(med.fit2, out.fit2, treat = "ANY_FK", mediator="Z_lin",sims=1000)

#To verify that groups matched I run the following code

table(unique(toca3$siteid)) table(unique(stoc3$siteid))


The siteid values in the two data frames match up.

Unfortunately, a group-level variable cannot be an outcome in lme4 models. Multilevel models require that the outcome be measured at the lowest level of the data hierarchy. The multilevel model partitions the variance in the outcome across the various levels - within-group, between-group, etc. Predictors at each level can be used to explain variance at their respective levels.