I have a mixed linear model, for example,
Model <- Values ~ A + B + C + (1 | id) + A:B + A:C + B:C

I wanted to do analysis with "emmeans" a.k.a estimated marginal means, so I used these packages in sequence


ref_grid(Model)@grid Model.pred1 <- matrix(predict(ref_grid(Model)), nrow = 12)

  • the outcome of ref_grid(Model)@grid has 12 rows so I wrote 12 in "nrow"


apply(Model.pred1, 1, mean)

apply(Model.pred1, 2, mean)

Then I did analysis with Model emmeans and pairs

But I wonder whether I did it just with emmeans and pairs without procedures which I used before the emmeans & pairs cuz I cannot understand why I should use the packages(ref_grid, pred. apply etc)...I just did this with Google cuz I don't have an experience with emmenas or Estimated marginal means

Question1. Can I use only emmeans and pairs packages whenever I want to do analysis with Estimated marginal means?

Question2. Could you please explain why one should do which I described above?

  • 1
    $\begingroup$ 1. Yes -- please. 2. I have no clue why somebody would do that. 3. Who ever said you should do this? 4.. Do vignette("basics", "emmeans") and read it. Take careful note that no convoluted steps are performed to replace object slots. $\endgroup$
    – Russ Lenth
    Jul 29, 2021 at 22:09
  • 1
    $\begingroup$ I guess maybe you did get the idea from that Basics vignette, but the purpose was to demonstrate that EMMs are just averages of predictions. It wasn't meant to suggest that you need to do that. Between the vignettes and the manual pages, there must be at least 100 examples where emmeans() is used without doing those extra steps. $\endgroup$
    – Russ Lenth
    Jul 30, 2021 at 0:10
  • $\begingroup$ Thanks a lot!! Okay then I will always do analysis only with emmeans whenever I need estimated marginal means. Question no. 1 is answered :) $\endgroup$
    – Taede17
    Jul 31, 2021 at 18:06


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.