ranovaemmeansposthoc

No function `emmeans_test` when using package "emmeans"


I'm doing a three-way ANOVA and I want to do a post-hoc analysis on it.

To make a comparison by groups, I saw that function emmeans_test from the package emmeans was the best option. But when I run my code, R doesn't find emmeans_test. I don't understand why. I have installed emmeans and done library(emmeans) already.

library(emmeans)

donnees_tot_g_J4 %>%
  group_by(quality, temperature) %>%
  emmeans_test(growth_rate ~ quantity, p.adjust.method = "bonferroni")

Error in emmeans_test(., growth_rate ~ quantity, p.adjust.method = "bonferroni"):
  could not find function "emmeans_test"

Solution

  • Function emmeans_test is not from emmeans but from rstatix. So you need:

    if (!require(rstatix)) install.packages("rstatix")
    library(rstatix)
    

    Thank you, it was that ! Sorry for the dumb question.

    Don't worry. The name is indeed misleading. And in fact, neither package depends on or imports the other. rstatix only suggests that it could enhance emmeans.


    Thanks for the useful feedback from dipetkov.

    Actually, rstatix calls emmeans to do the actual analysis; it's not enhancing anything. It can't deal for example with a model that omits the three-way interactions.

    Sorry for the confusion. My statement is based on what I saw from the CRAN page for rstatix. Surprisingly, emmeans is in neither "depends" nor "imports"; only in "suggests". Don't know how that emmeans_test would work if the package does not import emmeans in the first place.

    I strongly suggest to the OP to learn how to do their analysis with lm() followed by emmeans(), as they'll have lots more flexibility (and confidence in the results).

    Thanks. I update my answer to pass this suggestion to OP, as well as future readers.