0

I have an experiment in which I am calling wilcox.test in r for multiple times and gather statistic output. I compute the average of these statistics and then I want to convert it to p-value. What function should I call in r to get statistic of wilcox test as input and take a p-value as output?

wilcox.statistics <- 692304.08
wilcox.pvalue <- whatFunction(wilcox.statistics) ???
jared_mamrot
  • 22,354
  • 4
  • 21
  • 46
Nmgh
  • 113
  • 7
  • 1
    I'm not sure whether your approach is 'valid'; perhaps it would be better to ask this question at https://stats.stackexchange.com/ – jared_mamrot Jan 15 '23 at 22:53
  • I just want to know having wilcox statistic is there any function in r which gives me the p-value corresponding that statistics? – Nmgh Jan 15 '23 at 23:46
  • 2
    If you had taken the time to read the help page `?wilcox.test`, you should have been able to find the answer rapidly: `pwilcox`. Somewhat more cumbersome but possibly more informative would have been to read the R code that is the `wilcox.test` function. – IRTFM Jan 15 '23 at 23:51
  • Thanks @IRTFM, yes I saw this function. However, I was not sure what are m and n arguments. Are those sample sizes in each group? – Nmgh Jan 15 '23 at 23:53
  • Now you are demonstrating that you are not reading the `?pwilcox` page. – IRTFM Jan 15 '23 at 23:54

1 Answers1

0

I don't know what function you are using to get the statistic, but if you run wilcox.test

x <- wilcox.test(rnorm(10), rnorm(10, 2), conf.int = TRUE) 
str(x)

Output:

List of 9
 $ statistic  : Named num 8
  ..- attr(*, "names")= chr "W"
 $ parameter  : NULL
 $ p.value    : num 0.000725
 $ null.value : Named num 0
  ..- attr(*, "names")= chr "location shift"
 $ alternative: chr "two.sided"
 $ method     : chr "Wilcoxon rank sum exact test"
 $ data.name  : chr "rnorm(10) and rnorm(10, 2)"
 $ conf.int   : num [1:2] -2.75 -1.19
  ..- attr(*, "conf.level")= num 0.95
 $ estimate   : Named num -1.93
  ..- attr(*, "names")= chr "difference in location"
 - attr(*, "class")= chr "htest"

You can get the statistic and the p.value inside the output list, and depending on your goal you can extract them or even use a package like broom:

broom::tidy(x)

Output:

# A tibble: 1 x 7
  estimate statistic  p.value conf.low conf.high method                       alternative
     <dbl>     <dbl>    <dbl>    <dbl>     <dbl> <chr>                        <chr>      
1    -1.93         8 0.000725    -2.75     -1.19 Wilcoxon rank sum exact test two.sided  
Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32