g08amc performs the Mann–Whitney $U$ test on two independent samples of possibly unequal size and calculates the exact probability for the Mann–Whitney rank sum test statistic for the case where there are either ties or no ties in the samples pooled together.
The function may be called by the names: g08amc, nag_nonpar_mann_whitney or nag_mann_whitney.
3Description
The Mann–Whitney $U$ test investigates the difference between two populations defined by the distribution functions $F\left(x\right)$ and $G\left(y\right)$ respectively. The data consist of two independent samples of size ${n}_{1}$ and ${n}_{2}$, denoted by ${x}_{1},{x}_{2},\dots ,{x}_{{n}_{1}}$ and ${y}_{1},{y}_{2},\dots ,{y}_{{n}_{2}}$, taken from the two populations.
The hypothesis under test, ${H}_{0}$, often called the null hypothesis, is that the two distributions are the same, that is $F\left(x\right)=G\left(x\right)$, and this is to be tested against an alternative hypothesis ${H}_{1}$ which is
${H}_{1}$ : $F\left(x\right)\ne G\left(y\right)$; or
${H}_{1}$ : $F\left(x\right)<G\left(y\right)$, i.e., the $x$'s tend to be greater than the $y$'s; or
${H}_{1}$ : $F\left(x\right)>G\left(y\right)$, i.e., the $x$'s tend to be less than the $y$'s,
using a two tailed, upper tailed or lower tailed probability respectively. You select the alternative hypothesis by choosing the appropriate tail probability to be computed (see the description of argument tail in Section 5).
Note that when using this test to test for differences in the distributions one is primarily detecting differences in the location of the two distributions. That is to say, if we reject the null hypothesis ${H}_{0}$ in favour of the alternative hypothesis ${H}_{1}$: $F\left(x\right)>G\left(y\right)$ we have evidence to suggest that the location, of the distribution defined by $F\left(x\right)$, is less than the location, of the distribution defined by $G\left(y\right)$.
The Mann–Whitney $U$ test differs from the Median test (see g08acc) in that the ranking of the individual scores within the pooled sample is taken into account, rather than simply the position of a score relative to the median of the pooled sample. It is, therefore, a more powerful test if score differences are meaningful.
The test procedure involves ranking the pooled sample, average ranks being used for ties. Let ${r}_{1i}$ be the rank assigned to ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,{n}_{1}$ and ${r}_{2\mathit{j}}$ the rank assigned to ${y}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{n}_{2}$. Then the test statistic $U$ is defined as follows;
$U$ is also the number of times a score in the second sample precedes a score in the first sample (where we only count a half if a score in the second sample actually equals a score in the first sample).
$\tau $ is the number of groups of ties in the sample and ${t}_{j}$ is the number of ties in the $j$th group.
Note that if no ties are present the variance of $U$ reduces to $\frac{{n}_{1}{n}_{2}}{12}({n}_{1}+{n}_{2}+1)$.
(c)An indicator as to whether ties were present in the pooled sample or not.
(d)The tail probability, $p$, corresponding to $U$, depending on the choice of tail, i.e., the choice of alternative hypothesis, ${H}_{1}$. An exact probability or a normal approximation may be selected using the exact option. For large values of ${n}_{1}$ and ${n}_{2}$ the normal approximation should be adequate while the exact computation may require extensive calculation, particularly in cases where there are ties in the observations. For small samples the exact probability should be used.
The value of $p$ can be used to perform a significance test on the null hypothesis ${H}_{0}$ against the alternative hypothesis ${H}_{1}$. Let $\alpha $ be the size of the significance test (that is, $\alpha $ is the probability of rejecting ${H}_{0}$ when ${H}_{0}$ is true). If $p<\alpha $ then the null hypothesis is rejected. Typically $\alpha $ might be $0.05$ or 0.01.
4References
Conover W J (1980) Practical Nonparametric Statistics Wiley
Neumann N (1988) Some procedures for calculating the distributions of elementary nonparametric teststatistics Statistical Software Newsletter14(3) 120–126
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
5Arguments
1: $\mathbf{n1}$ – IntegerInput
On entry: the number of non-tied pairs, ${n}_{1}$.
On entry: the second vector of observations. ${y}_{1},{y}_{2},\dots ,{y}_{{n}_{2}}$.
5: $\mathbf{tail}$ – Nag_TailProbabilityInput
On entry: indicates the choice of tail probability, and hence the alternative hypothesis.
${\mathbf{tail}}=\mathrm{Nag\_TwoTail}$
A two tailed probability is calculated and the alternative hypothesis is ${H}_{1}:F\left(x\right)\ne G\left(y\right)$.
${\mathbf{tail}}=\mathrm{Nag\_UpperTail}$
An upper tailed probability is calculated and the alternative hypothesis ${H}_{1}:F\left(x\right)<G\left(y\right)$, i.e., the $x$'s tend to be greater than the $y$'s.
${\mathbf{tail}}=\mathrm{Nag\_LowerTail}$
A lower tailed probability is calculated and the alternative hypothesis ${H}_{1}:F\left(x\right)>G\left(y\right)$, i.e., the $x$'s tend to be less than the $y$'s.
Constraint:
${\mathbf{tail}}=\mathrm{Nag\_TwoTail}$, $\mathrm{Nag\_UpperTail}$ or $\mathrm{Nag\_LowerTail}$.
6: $\mathbf{exact}$ – Nag_CompProbInput
On entry: indicates if exact probability, $p$, is to be computed.
${\mathbf{exact}}=\mathrm{Nag\_CompProbExact}$
Compute the exact probability.
${\mathbf{exact}}=\mathrm{Nag\_CompProbApprox}$
Compute the approximate probability.
Constraint:
${\mathbf{exact}}=\mathrm{Nag\_CompProbExact}$ or $\mathrm{Nag\_CompProbApprox}$.
7: $\mathbf{u}$ – double *Output
On exit: the Mann–Whitney rank sum statistic, $U$.
8: $\mathbf{z}$ – double *Output
On exit: the approximate Normal test statistic, $z$, as described in Section 3.
9: $\mathbf{p}$ – double *Output
On exit: the exact tail probability, $p$, as specified by the argument tail.
10: $\mathbf{fail}$ – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
The pooled samples are all the same, that is the variance of $U=0.0$.
NE_INT_3
On entry, n1 and n2 require allocated work length exceeding integer limit.
NE_INT_ARG_LT
On entry, n1 must not be less than 1: ${\mathbf{n1}}=\u27e8\mathit{\text{value}}\u27e9$.
On entry, n2 must not be less than 1: ${\mathbf{n2}}=\u27e8\mathit{\text{value}}\u27e9$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_MANN_WHITNEY_STAT
The computed Mann–Whitney statistic, $U=\u27e8\mathit{\text{value}}\u27e9$. If the exact tail probability is to be computed, then $U\ge 0$.
7Accuracy
The approximate tail probability, $p$, returned by g08amc is a good approximation to the exact probability for cases where $\mathrm{max}\phantom{\rule{0.125em}{0ex}}({n}_{1},{n}_{2})\ge 30$ and $({n}_{1}+{n}_{2})\ge 40$. The relative error of the approximation should be less than 10 percent, for most cases falling in this range.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g08amc is not threaded in any implementation.
9Further Comments
The time taken by g08amc increases with ${\mathit{n}}_{1}$ and ${\mathit{n}}_{2}$ and the product ${\mathit{n}}_{1}{\mathit{n}}_{2}$. Note that when exact probability is requested and ties are present, the amount of interrnal workspace required becomes very large for even moderate sizes of ${\mathit{n}}_{1}$ and ${\mathit{n}}_{2}$.
10Example
The example program performs the Mann–Whitney test on two independent samples of sizes 16 and 23 respectively. This is used to test the null hypothesis that the distributions of the two populations from which the samples were taken are the same against the alternative hypothesis that the distributions are different. The test statistic, the approximate Normal statistic and the approximate two-tail probability are printed. An exact tail probability is also calculated and printed depending on whether ties were found in the pooled sample or not.