[ 
https://issues.apache.org/jira/browse/MATH-1233?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18145986#comment-18145986
 ] 

Tasuku Kobayashi commented on MATH-1233:
----------------------------------------

A further consequence of the `max(W+, W-)` design discussed above, observed on 
3.6.1: the exact two-sided p-value exceeds 1 whenever the positive and negative 
rank sums are equal, for data without ties or zeros.

```java
double[] x = \{1, 2, -3};
double[] y = \{0, 0, 0};
double p = new WilcoxonSignedRankTest().wilcoxonSignedRankTest(x, y, true);
// p = 1.25; the exact two-sided p-value is 1
```

`calculateExactPValue` returns `2 * largerRankSums / 2^N`, where the count is 
over rank sums `>= max(W+, W-)`. At `W+ = W-` the inclusive tail is larger than 
one half, so the doubled value is above 1. On 2,453 inputs with distinct 
nonzero integer differences (N up to 30) this occurred on exactly the 32 inputs 
with equal rank sums (values from 1.0146 to 1.25); all other results agreed 
with exact rational values.

`commons-statistics-inference` 1.3 (`WilcoxonSignedRankTest` with 
`PValueMethod.EXACT`) returned correct values on the same inputs; it applies 
`Math.min(1, p)`. The Hipparchus fork still carries the uncapped expression, 
and I have reported it there separately.

> Uncommon wilcoxon signed-rank p-values
> --------------------------------------
>
>                 Key: MATH-1233
>                 URL: https://issues.apache.org/jira/browse/MATH-1233
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.5
>            Reporter: Icaro Cavalcante Dourado
>            Assignee: Rob Tompkins
>            Priority: Major
>             Fix For: 4.X
>
>         Attachments: MATH-1233-test.patch
>
>
> This implementation in WilcoxonSignedRankTest looks weird. For equal vectors, 
> the correct pValue should be 1, because it is the probability of the vectors 
> to come from same population.
> On the opposite, this implementation returns ~0 for equal vectors. So we need 
> to analyze the returned pValue > significanceLevel to reject H0 hypothesis, 
> while in R and many others tools we perform the opposite: pValue <= 
> significanceLevel gives us an argument to reject null hypothesis.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to