kassambara / rstatix

Pipe-friendly Framework for Basic Statistical Tests in R
https://rpkgs.datanovia.com/rstatix/
432 stars 51 forks source link

Slightly different p-values using `p.adjust.method` in `wilcox_test` or running `p.adjust` afterwards #187

Open lucygarner opened 1 year ago

lucygarner commented 1 year ago

Hi @kassambara,

I am getting slightly different p-values if I p.adjust.method within wilcox_test or run p.adjust afterwards and I am just trying to understand why.

data(iris)
iris$Petal.Width <- factor(iris$Petal.Width)

wilcox_p <- iris %>% 
    group_by(Species) %>% 
    wilcox_test(Sepal.Length ~ Petal.Width, p.adjust.method = "BH")

image

The first 15 rows correspond to the setosa species, so I run:

p.adjust(wilcox_p$p[1:15], method = "BH")

The first three p-values are 0.9313636, 0.9313636, 0.1950000. This compares with 0.931, 0.931, 0.192 from wilcox_test. Any thoughts on why this is?

As far as I understand, multiple testing correction is only done within a group e.g. for comparisons made within a species in this example. Would you not also want to correct for the fact that you are testing multiple species?

So do you recommend:

wilcox_p <- iris %>% 
    group_by(Species) %>% 
    wilcox_test(Sepal.Length ~ Petal.Width) %>% 
    adjust_pvalue(p.col = "p", method = "BH")

Best wishes, Lucy