raphaelvallat / pingouin

Statistical package in Python based on Pandas
https://pingouin-stats.org/
GNU General Public License v3.0
1.61k stars 138 forks source link

Mann-Whitney U (mwu): the computation of rank-biserial correlation (RBC) is problematic #428

Open mmpeng9 opened 2 months ago

mmpeng9 commented 2 months ago

Hi there,

I found that the computation of rank-biserial correlation (RBC) is problematic. This is related to https://github.com/raphaelvallat/pingouin/issues/417 and https://github.com/raphaelvallat/pingouin/pull/424.

According to the cited paper, there are three ways to compute RBC. It seems you adopted the third method based on Hans Wendt (1972): r=1 – (2U)/ (n1 * n2). From the paper, U is the smaller number between U1 and U2:

Finding the test statistic U requires two steps. First, compute the number of favorable and unfavorable pairs; or what is the same thing, compute U1 and U2, as defined in Equations 1 and 2. Second, select the smaller of the two numbers; this smaller number is the test statistic U.

According to SciPy,

the Mann-Whitney U statistic corresponding with sample x; If U1 is the statistic corresponding with sample x, then the statistic corresponding with sample y is U2 = x.shape[axis] * y.shape[axis] - U1.

It seems that the returned U is not the smaller one in U1 and U2. And, it will result in a RBC value that is negative (according to the paper, this should always be positive). This is also demonstrated in my experiments.

Thanks!

raphaelvallat commented 1 month ago

Hi @mmpeng9

Thanks for opening the issue and apologies about the late reply. Can you please share your experiments here? When doing so, can you please make sure that you are using the latest available fork of Pingouin (which includes https://github.com/raphaelvallat/pingouin/pull/424) and not the current stable release (0.5.4).

Thanks Raphael