Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_pwc() with emmeans_test method #606

Open
DariuszMajerek opened this issue Jun 3, 2024 · 0 comments
Open

geom_pwc() with emmeans_test method #606

DariuszMajerek opened this issue Jun 3, 2024 · 0 comments

Comments

@DariuszMajerek
Copy link

During my research I encounter an issue with geom_pwc() with emmeans_test method when I want to extract means from defined lmer model. Let say I build the following model:

library(ggpubr)
library(tidyverse)
library(rstatix)
library(datarium)
library(lme4)

df_long <- anxiety %>% 
  pivot_longer(cols = t1:t3, names_to = "time", values_to = "score")

mod <- lmer(score ~ group * time + (1 | id), data = df_long)

I want to estimate marginal means by:

emmeans_test(df_long, ~ group, ref.group = "grp1", model = mod)

the result is following:

NOTE: Results may be misleading due to involvement in interactions
# A tibble: 2 × 9
  term  .y.   group1 group2    df statistic       p  p.adj p.adj.signif
* <chr> <chr> <chr>  <chr>  <dbl>     <dbl>   <dbl>  <dbl> <chr>       
1 group group grp1   grp2    42.0      1.11 0.272   0.543  ns          
2 group group grp1   grp3    42.0      2.92 0.00557 0.0111 *  

But when I try to plot the results of test on boxplot I have a problem. Let say I do it in this way:

df_long %>% 
  ggboxplot(x = "group", y = "score", color = "group")+
  geom_pwc(method = "emmeans_test", ref.group = "grp1")

this gives me

image

which is wrong with the comparison with the results of the tests. So I tried:

df_long %>% 
  ggboxplot(x = "group", y = "score", color = "group")+
  geom_pwc(method = "emmeans_test", ref.group = "grp1",
           method.args = list(model = mod))

and this gives me the following error:

Warning message:
Computation failed in `stat_pwc()`.
Caused by error in `emmeans::emmeans()`:
! No variable named x in the reference grid

Please help :)

session_info()

Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.0 (2024-04-24)
 os       macOS Sonoma 14.5
 system   aarch64, darwin20
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Europe/Warsaw
 date     2024-06-03
 rstudio  2024.04.1+748 Chocolate Cosmos (desktop)
 pandoc   3.1.11 @ /opt/homebrew/bin/pandocPackages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package      * version  date (UTC) lib source
 abind          1.4-5    2016-07-21 [1] CRAN (R 4.4.0)
 backports      1.5.0    2024-05-23 [1] CRAN (R 4.4.0)
 boot           1.3-30   2024-02-26 [1] CRAN (R 4.4.0)
 broom          1.0.6    2024-05-17 [1] CRAN (R 4.4.0)
 car            3.1-2    2023-03-30 [1] CRAN (R 4.4.0)
 carData        3.0-5    2022-01-06 [1] CRAN (R 4.4.0)
 cli            3.6.2    2023-12-11 [1] CRAN (R 4.4.0)
 coda           0.19-4.1 2024-01-31 [1] CRAN (R 4.4.0)
 codetools      0.2-20   2024-03-31 [1] CRAN (R 4.4.0)
 colorspace     2.1-0    2023-01-23 [1] CRAN (R 4.4.0)
 datarium     * 0.1.0    2019-05-21 [1] CRAN (R 4.4.0)
 dplyr        * 1.1.4    2023-11-17 [1] CRAN (R 4.4.0)
 emmeans        1.10.2   2024-05-20 [1] CRAN (R 4.4.0)
 estimability   1.5.1    2024-05-12 [1] CRAN (R 4.4.0)
 fansi          1.0.6    2023-12-08 [1] CRAN (R 4.4.0)
 farver         2.1.2    2024-05-13 [1] CRAN (R 4.4.0)
 forcats      * 1.0.0    2023-01-29 [1] CRAN (R 4.4.0)
 generics       0.1.3    2022-07-05 [1] CRAN (R 4.4.0)
 ggplot2      * 3.5.1    2024-04-23 [1] CRAN (R 4.4.0)
 ggpubr       * 0.6.0    2023-02-10 [1] CRAN (R 4.4.0)
 ggsignif       0.6.4    2022-10-13 [1] CRAN (R 4.4.0)
 glue           1.7.0    2024-01-09 [1] CRAN (R 4.4.0)
 gtable         0.3.5    2024-04-22 [1] CRAN (R 4.4.0)
 hms            1.1.3    2023-03-21 [1] CRAN (R 4.4.0)
 labeling       0.4.3    2023-08-29 [1] CRAN (R 4.4.0)
 lattice        0.22-6   2024-03-20 [1] CRAN (R 4.4.0)
 lifecycle      1.0.4    2023-11-07 [1] CRAN (R 4.4.0)
 lme4         * 1.1-35.3 2024-04-16 [1] CRAN (R 4.4.0)
 lubridate    * 1.9.3    2023-09-27 [1] CRAN (R 4.4.0)
 magrittr       2.0.3    2022-03-30 [1] CRAN (R 4.4.0)
 MASS           7.3-60.2 2024-04-24 [1] local
 Matrix       * 1.7-0    2024-03-22 [1] CRAN (R 4.4.0)
 minqa          1.2.7    2024-05-20 [1] CRAN (R 4.4.0)
 multcomp       1.4-25   2023-06-20 [1] CRAN (R 4.4.0)
 munsell        0.5.1    2024-04-01 [1] CRAN (R 4.4.0)
 mvtnorm        1.2-5    2024-05-21 [1] CRAN (R 4.4.0)
 nlme           3.1-164  2023-11-27 [1] CRAN (R 4.4.0)
 nloptr         2.0.3    2022-05-26 [1] CRAN (R 4.4.0)
 pbkrtest       0.5.2    2023-01-19 [1] CRAN (R 4.4.0)
 pillar         1.9.0    2023-03-22 [1] CRAN (R 4.4.0)
 pkgconfig      2.0.3    2019-09-22 [1] CRAN (R 4.4.0)
 purrr        * 1.0.2    2023-08-10 [1] CRAN (R 4.4.0)
 R6             2.5.1    2021-08-19 [1] CRAN (R 4.4.0)
 Rcpp           1.0.12   2024-01-09 [1] CRAN (R 4.4.0)
 readr        * 2.1.5    2024-01-10 [1] CRAN (R 4.4.0)
 rlang          1.1.3    2024-01-10 [1] CRAN (R 4.4.0)
 rstatix      * 0.7.2    2023-02-01 [1] CRAN (R 4.4.0)
 rstudioapi     0.16.0   2024-03-24 [1] CRAN (R 4.4.0)
 sandwich       3.1-0    2023-12-11 [1] CRAN (R 4.4.0)
 scales         1.3.0    2023-11-28 [1] CRAN (R 4.4.0)
 sessioninfo    1.2.2    2021-12-06 [1] CRAN (R 4.4.0)
 stringi        1.8.4    2024-05-06 [1] CRAN (R 4.4.0)
 stringr      * 1.5.1    2023-11-14 [1] CRAN (R 4.4.0)
 survival       3.6-4    2024-04-24 [1] CRAN (R 4.4.0)
 TH.data        1.1-2    2023-04-17 [1] CRAN (R 4.4.0)
 tibble       * 3.2.1    2023-03-20 [1] CRAN (R 4.4.0)
 tidyr        * 1.3.1    2024-01-24 [1] CRAN (R 4.4.0)
 tidyselect     1.2.1    2024-03-11 [1] CRAN (R 4.4.0)
 tidyverse    * 2.0.0    2023-02-22 [1] CRAN (R 4.4.0)
 timechange     0.3.0    2024-01-18 [1] CRAN (R 4.4.0)
 tzdb           0.4.0    2023-05-12 [1] CRAN (R 4.4.0)
 utf8           1.2.4    2023-10-22 [1] CRAN (R 4.4.0)
 vctrs          0.6.5    2023-12-01 [1] CRAN (R 4.4.0)
 withr          3.0.0    2024-01-16 [1] CRAN (R 4.4.0)
 xtable         1.8-4    2019-04-21 [1] CRAN (R 4.4.0)
 zoo            1.8-12   2023-04-13 [1] CRAN (R 4.4.0)

 [1] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant