0

I am comparing various groups, where for one group I have > 2 classes and for one group I have only two classes.

My data:

structure(list(lake_method = structure(c(3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), levels = c("Clear Lake - Angling", 
"Clear Lake - E-fishing", "Clear Lake - Spearfishing", "Cultus Lake - Angling"
), class = "factor"), group = c("TOTAL cpuefh", "TOTAL cpuekgh", 
"MM cpuefh", "MM-N cpuefh", "MM-NN cpuefh", "MF cpuefh", "J cpuefh", 
"TOTAL cpuefh", "TOTAL cpuekgh", "MM cpuefh", "MM-N cpuefh", 
"MM-NN cpuefh", "MF cpuefh", "J cpuefh", "TOTAL cpuefh", "TOTAL cpuekgh", 
"MM cpuefh", "MM-N cpuefh", "MM-NN cpuefh", "MF cpuefh"), value = c(3.20045832408987, 
0.627289831521615, NA, NA, NA, 3.20045832408987, NA, 13.6134036988146, 
1.23881973659213, NA, NA, NA, NA, 13.6134036988146, 65.5138665685633, 
15.4612725101809, NA, NA, NA, 65.5138665685633)), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame"))

The problem is when I create the ggbetweenstats plot for the group that has three classes, I get a Games-Howell pairwise comparison:

p1 <- ggbetweenstats(
  data = dplyr::filter(data_violin_f, group == "MM cpuefh"),
  x = lake_method,
  y = value,
  xlab = "",
  ylab = "fish/h",
  title = "MM fish/h of smallmouth bass captured per method (both lakes)",
  pairwise.comparisons = TRUE, ## display pairwise comparisons
  results.subtitle = FALSE,
  pairwise.display = "s",
  p.adjust.method = "none" ## adjust p-values for multiple tests using this method
)

p1

three classes

while when I have only two classes it automatically computes a t-test, which gives me different p-values:

p2 <- ggbetweenstats(
  data = dplyr::filter(data_violin_f, group == "MM-N cpuefh"),
  x = lake_method,
  y = value,
  xlab = "",
  ylab = "fish/h",
  title = "MM-N fish/h of smallmouth bass captured per method (both lakes)",
  pairwise.comparisons = TRUE, ## display pairwise comparisons
  results.subtitle = TRUE,
  pairwise.display = "s",
  p.adjust.method = "none", ## adjust p-values for multiple tests using this method
)

p2

Two classes

Now I want to change it so that it gives me a Games-Howell comparison as well for the two so that the plots are the same.

I can not, however find any vignette or documentation on how to change the type of parametric test, only how to change to non-parametric etc...

I have found this code piece in the official documentation:

PMCMRplus::gamesHowellTest()

and also another one to change from t-test to one-way ANOVA. But how do I incorporate that into my code?

Help is highly appreciated, spent hours searching, couldnt find a solution :D

I looked into the documentation and couldnt find how to change the type of test carried out

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

I have found the answer on how to add the p-values for only two groups. Its explained under this link:

https://indrajeetpatil.github.io/ggstatsplot/articles/web_only/pairwise.html#data-frame-outputs

first creating data frame from the pairwise_comparison() function and add it the results to the plot with ggsignif. If you add var.equal = FALSE, to the pairwise_comparison(), it will compute a Games-Howell comparison instead of the t-test.

p <- ggplot(mtcars, aes(cyl, wt)) +
  geom_boxplot()



(df <-
  pairwise_comparisons(mtcars, cyl, wt) %>%
  dplyr::mutate(groups = purrr::pmap(.l = list(group1, group2), .f = c)) %>%
  dplyr::arrange(group1))
#> # A tibble: 3 × 10
#>   group1 group2 statistic   p.value alternative distribution p.adjust.method
#>   <chr>  <chr>      <dbl>     <dbl> <chr>       <chr>        <chr>          
#> 1 4      6           5.39 0.00831   two.sided   q            Holm           
#> 2 4      8           9.11 0.0000124 two.sided   q            Holm           
#> 3 6      8           5.12 0.00831   two.sided   q            Holm           
#>   test         expression groups   
#>   <chr>        <list>     <list>   
#> 1 Games-Howell <language> <chr [2]>
#> 2 Games-Howell <language> <chr [2]>
#> 3 Games-Howell <language> <chr [2]>

## using `geom_signif` to display results
## (note that you can choose not to display all comparisons)
p +
  ggsignif::geom_signif(
    comparisons = list(df$groups[[1]]),
    annotations = as.character(df$expression)[[1]],
    test        = NULL,
    na.rm       = TRUE,
    parse       = TRUE
  )