Closed gdmcbain closed 4 months ago
I think R's equivalent is wilcox.test
; it also has
alternative | a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less".
Oh, I see! It's already there! It's just a matter of passing tail=:right
to pvalue
with the result.
x = [0.2, 1.5, 0.2, 0.2]
y = [3.4, 1.9, 3.7, 2.1, 3.2, 2.4, 1.2, 4.1, 1.9, 0.6]
for tail ∈ [:both, :left, :right]
@show pvalue(MannWhitneyUTest(x, y), tail=tail)
end
gives
pvalue(MannWhitneyUTest(x, y), tail = tail) = 0.012825255684392028
pvalue(MannWhitneyUTest(x, y), tail = tail) = 0.006412627842196014
pvalue(MannWhitneyUTest(x, y), tail = tail) = 0.9957406660823311
Thank you.
MannWhitneyUTest
doesn't have an option for other than the two-sided test, unlikescipy.stats.mannwhitneyu
, which has an optional keyword argumentalternative: {'two-sided', 'less', 'greater'}
.I noticed this when attempting to reproduce the example from §9.2.4 ‘Example: Rank-Sum Test for Data with One Reporting Limit’ of
The example concerns "censored" data, in that some measurements fall below a detection limit. Those measurements are treated, for the purpose of applying an ordinal test, by replacing them with the detection limit; i.e., they're all deemed tied. This isn't the issue here; that's easy:
This replaces the given censored data
groups
with:and then
MannWhitneyUTest(x1, y1)
reports:i.e., a p-value of 0.0128, whereas the text gives 0.0064. I noticed:
In SciPy:
so it looks like Helsel's matches the
alternative='less'
. Rereading Helsel (p. 159):HypothesisTests.MannWhitneyUTest
does correctly give the p = 0.0520 for the earlier (two-sided) example in §9,2,2,Should
HypothesisTests.MannWhitneyUTest
be extended with somethink like SciPy'salternative
keyword option?