Repository navigation
[Repo Assist] feat: add Mann-Whitney U test (Wilcoxon rank-sum) for two independent samples - #376
Conversation
… samples Implements MannWhitneyTest.create in Testing/MannWhitney.fs: - Computes U1 and U2 statistics via rank sums - Normal approximation with optional continuity correction - Standard variance tie correction (all 3 counts handled) - Returns MannWhitneyTestStatistics with U1, U2, Statistic (z), PValueLeft, PValueRight, PValue - 8 new tests covering clear separation, moderate overlap, and tied data - All 1201 tests pass This complements the existing WilcoxonTest (signed-rank, paired samples) with the rank-sum test for two independent samples. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## developer #376 +/- ##
=============================================
+ Coverage 47.61% 47.92% +0.30%
=============================================
Files 152 136 -16
Lines 16765 12967 -3798
Branches 2253 1717 -536
=============================================
- Hits 7983 6214 -1769
+ Misses 8097 6231 -1866
+ Partials 685 522 -163 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I had a quick clarifying question regarding this PR. As far as I understand, there was a previous attempt to implement the Mann-Whitney U test (#182), and the discussion at the time seemed to conclude that for n+m<100 the exact Wilcoxon distribution should be used instead (see also #213 and #293). One reason I hadn't merged this yet is that, unless I'm missing something, the exact distribution does not appear to be implemented here. Instead, the implementation currently uses a normal approximation for sample sizes ≥ 20, while smaller sample sizes are not yet supported. Is the plan going forward to implement the Wilcoxon distribution separately and then extend this test to support smaller sample sizes? |
|
Yes, I think the documentation makes it clear enough, that for small sample sizes the test is not robust. As you pointed out in the future a exact distribution can be implemented. I had a deep dive some while ago and it is difficult to implement that exact distribution. Maybe repo-assist is a game-changer here. We definitely should plan to incorporate the exact calculation. |
🤖 This is an automated pull request from Repo Assist, an AI assistant.
Summary
Adds
MannWhitneyTest.create— the Mann-Whitney U test (also known as the Wilcoxon rank-sum test) for comparing two independent samples. This complements the existingWilcoxonTestwhich handles paired (signed-rank) samples.This addresses requests in issues #117 and #213 for a two-sample nonparametric test.
What's new
New file:
src/FSharp.Stats/Testing/MannWhitney.fsMannWhitneyTestStatisticsrecord:U1U2U1 + U2 = n1×n2StatisticPValueLeftPValueRightPValueImplementation details
Rank.RankAverage()(average ranks for ties)correct=TRUEwilcox.test(..., exact=FALSE)Test Status
✅ All 1201 tests pass (8 new tests added in
Testing.fs):U statistics - clear separationU1 + U2 = n1*n2p-values - clear separation, no ccp-values - clear separation, with ccU statistics - moderate overlapp-value not significant - moderate overlapU statistics with tiesp-values with tiesTrade-offs / limitations
n1andn2in the result record (can be inferred from input lengths).