Skip to content

Commit

Permalink
Merge pull request #42 from grero/master
Browse files Browse the repository at this point in the history
Fixed a bug when inverting the U-value in ExactMannWhitney
  • Loading branch information
simonbyrne committed Dec 8, 2015
2 parents b44aa94 + f2d27dc commit 5deaa47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/mann_whitney.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ end
function mwuenumerate(x::ExactMannWhitneyUTest)
# Get the other U if inverted by mwu_stats
n = min(x.nx, x.ny)
U = x.U
if x.ny > x.nx
U = x.nx*x.ny - U
U = x.nx*x.ny -x.U
end
le = 0
gr = 0
Expand All @@ -89,8 +90,8 @@ function mwuenumerate(x::ExactMannWhitneyUTest)
for comb in combinations(x.ranks, n)
Up = sum(comb) - k
tot += 1
le += Up <= x.U
gr += Up >= x.U
le += Up <= U
gr += Up >= U
end
(le/tot, gr/tot)
end
Expand Down
6 changes: 6 additions & 0 deletions test/mann_whitney.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ show(IOBuffer(), ExactMannWhitneyUTest([1:10;], [2.1:2:21;]))
@test abs(pvalue(ExactMannWhitneyUTest([1:5; ones(5)], [1:10;])) - 0.0057) <= 1e-4
show(IOBuffer(), ExactMannWhitneyUTest([1:10;], [1:10;]))

#Exact with ties and unequal lengths
@test abs(pvalue(ExactMannWhitneyUTest([1:10;], [2:2:24;])) - 0.0118) <= 1e-4
@test abs(pvalue(ExactMannWhitneyUTest([2:2:24;], [1:10;])) - 0.0118) <= 1e-4
show(IOBuffer(), ExactMannWhitneyUTest([1:10;], [2:2:24;]))


# Approximate test
@test abs(pvalue(ApproximateMannWhitneyUTest([1:10;], [2.1:2:21;])) - 0.0257) <= 1e-4
@test abs(pvalue(ApproximateMannWhitneyUTest([2.1:2:21;], [1:10;])) - 0.0257) <= 1e-4
Expand Down

0 comments on commit 5deaa47

Please sign in to comment.