| mann_whitney_test_pv | R Documentation |
mann_whitney_test_pv() performs an exact or approximate
Wilcoxon-Mann-Whitney U test about the location shift between two
independent groups when the data is not necessarily normally distributed. In
contrast to stats::wilcox.test(), it is vectorised and only calculates
p-values. Furthermore, it is capable of returning the discrete p-value
supports, i.e. all observable p-values under a null hypothesis. Multiple
tests can be evaluated simultaneously.
mann_whitney_test_pv(
x,
y,
mu = 0,
alternative = "two.sided",
exact = NULL,
correct = TRUE,
digits_rank = Inf,
simple_output = FALSE
)
x, y |
numerical vectors forming the samples to be tested or lists of numerical vectors for multiple tests. |
mu |
numerical vector or single number of hypothesised location shift(s). |
alternative |
character vector that indicates the alternative hypotheses; each value must be one of |
exact |
single logical value that indicates whether |
correct |
either a single logical value that indicates if a continuity correction in the normal approximation is to be applied ( |
digits_rank |
single number giving the significant digits used to compute ranks for the test statistics. |
simple_output |
logical value that indicates whether an R6 class object, including the tests' parameters and support sets, i.e. all observable p-values under each null hypothesis, is to be returned (see below). |
We use a test statistic called the Wilcoxon Rank Sum Statistic, defined by
U = \sum_{i = 1}^{n_X}{rank(X_i)} - \frac{n_X(n_X + 1)}{2},
where rank(X_i) is the rank of X_i in the concatenated sample
of X and Y, and n_X and n_Y are the respective
sizes of the samples X and Y. Note that U
can range from 0 to n_X \cdot n_Y.
This is the same statistic used by stats::wilcox.test() and
whose distribution is accessible with pwilcox.
This is also the statistic defined by the two given references.
Note, however, that it is not what is called the Mann-Whitney U Statistic
in the (English-language) Wikipedia article (as of February 12, 2026). The
latter is defined as, using our notation, \min(U, n_X \cdot n_Y - U).
Using the Wikipedia notation, the Wilcoxon Rank Sum Statistic is U_2.
The parameters x, y, mu and alternative are vectorised. If x and
y are lists, they are replicated automatically to have the same lengths. In
case x or y are not lists, they are added to new ones, which are then
replicated to the appropriate lengths. This allows multiple hypotheses to be
tested simultaneously.
In the presence of ties, computation of the Edgeworth series (up to
correct = 3) is not possible. Therefore, numeric values of correct
are ignored and only a continuity correction is performed.
By setting exact = NULL, exact computation is performed only if both
samples sizes in a test setting are lower than or equal to 200. Otherwise,
p-values are computed by normal approximation.
If digits_rank = Inf (the default), rank() is used to
compute ranks for the tests statistics instead of
rank(signif(., digits_rank))
If simple.output = TRUE, a vector of computed p-values is returned.
Otherwise, the output is a DiscreteTestResults R6 class object, which
also includes the p-value supports and testing parameters. These have to be
accessed by public methods, e.g. $get_pvalues().
Mann, H. D. & Whitney, D. R. (1947). On a Test of Whether one of Two Random Variables is Stochastically Larger than the Other. Ann. Math. Statist., 18(1), pp. 50-60. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/aoms/1177730491")}
Hollander, M. & Wolfe, D. (1973). Nonparametric Statistical Methods. Third Edition. New York: Wiley. pp. 115-135. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1002/9781119196037")}
stats::wilcox.test(), pwilcox, wilcox_test_pv()
# Constructing
set.seed(1)
r1 <- rnorm(100)
r2 <- rnorm(100, 1)
# Exact two-sided p-values and their supports
results_ex <- mann_whitney_test_pv(r1, r2)
print(results_ex)
results_ex$get_pvalues()
results_ex$get_pvalue_supports()
# Normal-approximated one-sided p-values ("less") and their supports
results_ap <- mann_whitney_test_pv(r1, r2, alternative = "less", exact = FALSE)
print(results_ap)
results_ap$get_pvalues()
results_ap$get_pvalue_supports()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.