Skip to content

Conversation

@pdeffebach
Copy link
Contributor

Fix taken from here in the R source code.

Tests seem to fail for FischerExactTest for unrelated reasons.

@pdeffebach
Copy link
Contributor Author

Ready for a review @andreasnoack @nalimilan

@nalimilan nalimilan linked an issue Sep 10, 2021 that may be closed by this pull request
Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It's kind of weird that we have to clamp the value like that, but that's less surprising if other software do that. Anyway PValue throws an error for values above 1 and we probably shouldn't change that.

Do we need the same fix for other Mann-Whitney tests?

@test abs(pvalue(ExactMannWhitneyUTest(Float32[1:10;], Float32[2:11;])) - 0.5096) <= 1e-4
end

@testset "Issue #126" begin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say what this issue is about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

pdeffebach and others added 2 commits September 10, 2021 10:46
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
@pdeffebach
Copy link
Contributor Author

I fixed all the ocurrences of pvalue in that file. MannWhitneyUTest dispatches to either the exact or approximate depending on some condition.

I'm sure there are more cases of bad p-values but we can tackle those more slowly in a slew of smaller PRs as they are discovered.

@nalimilan nalimilan requested a review from devmotion October 2, 2021 18:55
@pdeffebach
Copy link
Contributor Author

Thanks for the review. This can be merged.

@pdeffebach
Copy link
Contributor Author

Bumping this @andreasnoack. Can I get a review / merge?

@andreasnoack
Copy link
Member

@devmotion Have your comments been addressed?

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the type instability was fixed 👍 I think two things should be improved:

  • Can you add a test for the type stability of pvalue(::ApproximateMannWhitneyTest)? It can be provoked on the master branch with basically any standard example and you can just change pvalue to @inferred(pvalue(...)).
  • Can you add a test for pvalue(::ApproximateMannWhitneyUTest; tail=:both) <= 1? Currently both tests just check the ExactMannWhitneyUTest. Unfortunately, the second example already works on the master branch for the approximate version so one needs different data to provoke a p-value > 1.

A = [12,10,7,6,3,1]
B = [11,9,8,5,4,2]

m = MannWhitneyUTest(A,B)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also be an ExactMannWhitneyUTest, so the changes for the p-value and type stability in the ApproximateWhitneyUTest are not tested.

I wanted to suggest changing this to

	m = ApproximateMannWhitneyUTest(A,B)

but unfortunately the p-value is already 1 for this example so it can only be used for testing type stability of pvalue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find inputs to get the p-value above 1 here. But I did fix an inference issue, which is nice.

@pdeffebach
Copy link
Contributor Author

Can you add a test for the type stability of pvalue(::ApproximateMannWhitneyTest)? It can be provoked on the master branch with basically any standard example and you can just change pvalue to @inferred(pvalue(...)).

Added @inferred where possible, including fixing a bad inference in the ApproximateMannWhitneyU test.

Can you add a test for pvalue(::ApproximateMannWhitneyUTest; tail=:both) <= 1? Currently both tests just check the ExactMannWhitneyUTest. Unfortunately, the second example already works on the master branch for the approximate version so one needs different data to provoke a p-value > 1.

Added a test, which is really just testing inference.

@pdeffebach
Copy link
Contributor Author

Thanks, let me know if you have more comments.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now, thank you @pdeffebach for taking into account all comments!

@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2021

Codecov Report

Merging #243 (56df1db) into master (dad954e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #243   +/-   ##
=======================================
  Coverage   93.64%   93.65%           
=======================================
  Files          28       28           
  Lines        1715     1717    +2     
=======================================
+ Hits         1606     1608    +2     
  Misses        109      109           
Impacted Files Coverage Δ
src/mann_whitney.jl 87.80% <100.00%> (+0.30%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dad954e...56df1db. Read the comment docs.

@devmotion
Copy link
Member

Seems Julia 1.7 broke the tests, probably due to the RNG changes. In general, equality checks of random results with fixed seeds seem very brittle and not reliable since different Julia versions are not guaranteed to yield the same random numbers (as happened now) - IMO ideally they should be replaced with some more stable tests. But of course this is not something you should have to deal with in this PR...

@pdeffebach
Copy link
Contributor Author

@andreasnoack can this be merged? Test failures unrelated.

@andreasnoack
Copy link
Member

Let's get tests green before merging. I've opened #252 as a minimal PR to make tests green again.

@pdeffebach
Copy link
Contributor Author

Will we merge #252 and then rebase?

@pdeffebach
Copy link
Contributor Author

Now that #252 is merged, what is the next course of action?

@devmotion
Copy link
Member

Update the PR so that tests pass, i.e., either merge the master branch or rebase the PR 🙂

@pdeffebach pdeffebach changed the base branch from master to dw/type_instability March 4, 2022 20:20
@pdeffebach pdeffebach changed the base branch from dw/type_instability to master March 4, 2022 20:20
@pdeffebach
Copy link
Contributor Author

Okay I rebased

Then I changed the base branch back and forth on the github UI so the changes look good. I think we should run the workflow.

Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devmotion Merge?

@devmotion devmotion merged commit ab97607 into JuliaStats:master Mar 9, 2022
@devmotion
Copy link
Member

Thank you @pdeffebach 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

p val > 1 in ExactMannWhitneyUTest

5 participants