-1

I'm trying to get the test statistics ("W") for each pairwise comparison performed using pairwise.wilcoxon.test. Is there a way to access this info without running individual pairwise tests for each variable?

Photo of R output

I tried using the print function and only got the above image as a result.

This is what I'm looking for, but for each comparison:
This is what I'm looking for, but for each comparison

UseR10085
  • 7,120
  • 3
  • 24
  • 54
  • 2
    Welcome to StackOverflow. Please take the [tour](https://stackoverflow.com/tour) and read these [guidelines](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to fix your question. – John Polo Dec 20 '22 at 01:52
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Please [do not post code or data in images](https://meta.stackoverflow.com/q/285551/2372064) – MrFlick Dec 20 '22 at 03:45

2 Answers2

1

Does the pairwise_wilcox_test() function from the rstatix package (https://rpkgs.datanovia.com/rstatix/reference/wilcox_test.html) provide your expected outcome?

I.e. using Damian Oswald's example:

library(tidyverse)
library(rstatix)
attach(airquality)

Month <- factor(Month, labels = month.abb[5:9])
test <- pairwise_wilcox_test(data = airquality,
                             formula = Ozone ~ Month)
test
#> # A tibble: 10 × 9
#>    .y.   group1 group2    n1    n2 statistic        p  p.adj p.adj.signif
#>  * <chr> <chr>  <chr>  <int> <int>     <dbl>    <dbl>  <dbl> <chr>       
#>  1 Ozone 5      6         26     9      82   0.193    0.579  ns          
#>  2 Ozone 5      7         26    26     110.  0.00003  0.0003 ***         
#>  3 Ozone 5      8         26    26     128.  0.000121 0.001  **          
#>  4 Ozone 5      9         26    29     284   0.119    0.476  ns          
#>  5 Ozone 6      7          9    26      51.5 0.014    0.085  ns          
#>  6 Ozone 6      8          9    26      57.5 0.026    0.13   ns          
#>  7 Ozone 6      9          9    29     132.  0.959    1      ns          
#>  8 Ozone 7      8         26    26     348   0.862    1      ns          
#>  9 Ozone 7      9         26    29     578.  0.000744 0.006  **          
#> 10 Ozone 8      9         26    29     552   0.003    0.023  *

# I think the "statistic" column is what you're after
test$statistic
#>     W     W     W     W     W     W     W     W     W     W 
#>  82.0 109.5 127.5 284.0  51.5  57.5 132.5 348.0 577.5 552.0

Created on 2022-12-20 with reprex v2.0.2

jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
0

Is this what you are looking for?

attach(airquality)
Month <- factor(Month, labels = month.abb[5:9])
test <- pairwise.wilcox.test(Ozone, Month)
print(test[["p.value"]])
  • No, I have the p-values. I'm looking for the numeric value of the test statistic, "W" in this case. – Flyredbird Dec 20 '22 at 01:40
  • Well then you're out of luck, the function `pairwise.wilcoxon.test` only returns the p-values and not the original statistics, for every test that is run. So you'll have to run the individual tests yourself and then return the statistics. – Damian Oswald Dec 20 '22 at 02:03