myfatson
myfatson

Reputation: 547

p value of 1 for Mann-Whitney U - artifact?

I'm using the rstatix library in R 3.6.3 through RStudio 1.2.5042 and am getting the impossible p-value of 1 when running a two-sample Wilcoxon aka Mann-Whitney U Test.

My first instinct says this is a floating point precision issue and the actual value is something like 0.999999 but I came here to confirm before an undisclosed federal research agency gets up my ass about it.

Here's my code:

wilcox_test(data,
            DV ~ Group,
            paired = F,
            exact = T, 
            alternative = "two.sided",
            conf.level = 0.95,
            detailed = T)

Link to .csv formatted data

Data has been anonymized of course. This link expires in 1 week.

Cross-posting for consistency:

https://stats.stackexchange.com/questions/467572/p-value-of-1-for-mann-whitney-u-artifact-of-r

Upvotes: 2

Views: 944

Answers (2)

Ben Bolker
Ben Bolker

Reputation: 226692

A little bit of digging finds that rstatix::wilcox_test() is suppressing warnings about ties being incompatible with exactness in its implementation. If you run plain old stats::wilcox.test() (which rstatix is calling eventually anyway), this happens:

w <- wilcox.test(DV~Group,data=dat)

Warning message: In wilcox.test.default(x = c(5L, 0L, 0L, 3L, 0L, 1L, 3L, 4L, 0L, : cannot compute exact p-value with ties

You can see here that rstatix is suppressing this warning.

Just to double-check, I worked through the guts of wilcox.test: the formula for the Z-statistic for the approximate test is

STATISTIC-n.x*n.y/2-CORRECTION

(see Wikipedia: doesn't mention the continuity correction though).

In this case the W-statistic is 209.5, n.x*n.y/2 is 209, and the continuity correction is 0.5 - so you do get a Z-statistic of exactly zero, so that pnorm(z) is 0.5 and the two-tailed test statistic is exactly 1.

If you instead want to deal with the ties exactly:

coin::wilcox_test(DV~factor(Group), data=dat, distribution="exact")
##  Exact Wilcoxon-Mann-Whitney Test
## data:  DV by factor(Group) (Control, Treatment)
## Z = 0.013327, p-value = 0.9954
## alternative hypothesis: true mu is not equal to 0

Upvotes: 3

Ahorn
Ahorn

Reputation: 3876

P-values of 1 are not impossible, as described here and here. Also note that in your case the exact p-value cannot be computed because you have ties. The function you use does not give this information but the wilcox.test() function from the stats package gives a warning.

wilcox.test(test_data$DV ~ test_data$Group)

#>Warning message:
#>In wilcox.test.default(x = c(5, 0, 0, 3, 0, 1, 3, 4, 0, 3, 2, 1,  :
#>  cannot compute exact p-value with ties

Upvotes: 2

Related Questions