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.