NAG Library Routine Document
g08akf (prob_mwu_ties)
1
Purpose
g08akf calculates the exact tail probability for the Mann–Whitney rank sum test statistic for the case where there are ties in the two samples pooled together.
2
Specification
Fortran Interface
Integer, Intent (In)  ::  n1, n2, lwrk  Integer, Intent (Inout)  ::  ifail  Integer, Intent (Out)  ::  iwrk(2*(n1+n2+1))  Real (Kind=nag_wp), Intent (In)  ::  ranks(n1+n2), u  Real (Kind=nag_wp), Intent (Out)  ::  p, wrk(lwrk)  Character (1), Intent (In)  ::  tail 

C Header Interface
#include <nagmk26.h>
void 
g08akf_ (const Integer *n1, const Integer *n2, const char *tail, const double ranks[], const double *u, double *p, double wrk[], const Integer *lwrk, Integer iwrk[], Integer *ifail, const Charlen length_tail) 

3
Description
g08akf computes the exact tail probability for the Mann–Whitney
$U$ test statistic (calculated by
g08ahf and returned through the argument
u) using a method based on an algorithm developed by
Neumann (1988), for the case where there are ties in the pooled sample.
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 ${\mathit{n}}_{1}$ and ${\mathit{n}}_{2}$, denoted by ${x}_{1},{x}_{2},\dots ,{x}_{{\mathit{n}}_{1}}$ and ${y}_{1},{y}_{2},\dots ,{y}_{{\mathit{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)$.
g08akf returns the exact tail probability, $p$, corresponding to $U$, depending on the choice of alternative hypothesis, ${H}_{1}$.
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$.
4
References
Conover W J (1980) Practical Nonparametric Statistics Wiley
Neumann N (1988) Some procedures for calculating the distributions of elementary nonparametric teststatistics Statistical Software Newsletter 14(3) 120–126
Siegel S (1956) Nonparametric Statistics for the Behavioral Sciences McGraw–Hill
5
Arguments
 1: $\mathbf{n1}$ – IntegerInput

On entry: the number of nontied pairs, ${\mathit{n}}_{1}$.
Constraint:
${\mathbf{n1}}\ge 1$.
 2: $\mathbf{n2}$ – IntegerInput

On entry: the size of the second sample, ${\mathit{n}}_{2}$.
Constraint:
${\mathbf{n2}}\ge 1$.
 3: $\mathbf{tail}$ – Character(1)Input

On entry: indicates the choice of tail probability, and hence the alternative hypothesis.
 ${\mathbf{tail}}=\text{'T'}$
 A two tailed probability is calculated and the alternative hypothesis is ${H}_{1}:F\left(x\right)\ne G\left(y\right)$.
 ${\mathbf{tail}}=\text{'U'}$
 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}}=\text{'L'}$
 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}}=\text{'T'}$, $\text{'U'}$ or $\text{'L'}$.
 4: $\mathbf{ranks}\left({\mathbf{n1}}+{\mathbf{n2}}\right)$ – Real (Kind=nag_wp) arrayInput

On entry: the ranks of the pooled sample. These ranks are output in the array
ranks by
g08ahf and should not be altered in any way if you are using the same
${\mathit{n}}_{1}$,
${\mathit{n}}_{2}$ and
${\mathbf{u}}$ as used in
g08ahf.
 5: $\mathbf{u}$ – Real (Kind=nag_wp)Input

On entry:
$U$, the value of the Mann–Whitney rank sum test statistic. This is the statistic returned through the argument
u by
g08ahf.
Constraint:
${\mathbf{u}}\ge 0.0$.
 6: $\mathbf{p}$ – Real (Kind=nag_wp)Output

On exit: the tail probability,
$p$, as specified by the argument
tail.
 7: $\mathbf{wrk}\left({\mathbf{lwrk}}\right)$ – Real (Kind=nag_wp) arrayWorkspace
 8: $\mathbf{lwrk}$ – IntegerInput

On entry: the dimension of the array
wrk as declared in the (sub)program from which
g08akf is called.
Constraint:
${\mathbf{lwrk}}\ge \mathit{n}+\mathit{n}\left(\mathit{n}+1\right)\left(\mathit{n}+\mathit{m}\right)\frac{\mathit{n}\left(\mathit{n}+1\right)\left(2\times \mathit{n}+1\right)}{3}+1$, where $\mathit{n}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n1}},{\mathbf{n2}}\right)$ and $\mathit{m}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left({\mathbf{n1}},{\mathbf{n2}}\right)$.
 9: $\mathbf{iwrk}\left(2\times \left({\mathbf{n1}}+{\mathbf{n2}}+1\right)\right)$ – Integer arrayWorkspace

 10: $\mathbf{ifail}$ – IntegerInput/Output

On entry:
ifail must be set to
$0$,
$1\text{or}1$. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
$0$.
When the value $\mathbf{1}\text{or}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit:
${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
${\mathbf{ifail}}=0$ or
$1$, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
 ${\mathbf{ifail}}=1$

On entry, ${\mathbf{n1}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{n1}}\ge 1$.
On entry, ${\mathbf{n2}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{n2}}\ge 1$.
 ${\mathbf{ifail}}=2$

On entry, ${\mathbf{tail}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{tail}}=\text{'T'}$, $\text{'U'}$ or $\text{'L'}$.
 ${\mathbf{ifail}}=3$

On entry, ${\mathbf{u}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{u}}\ge 0.0$.
 ${\mathbf{ifail}}=4$

On entry, ${\mathbf{lwrk}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{lwrk}}\ge \u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=5$

On entry, at least one rank, given in
ranks, was outside the expected range.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The exact tail probability, $p$, is computed to an accuracy of at least $4$ significant figures.
8
Parallelism and Performance
g08akf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementationspecific information.
The time taken by g08akf increases with ${\mathit{n}}_{1}$ and ${\mathit{n}}_{2}$ and the product ${\mathit{n}}_{1}{\mathit{n}}_{2}$. Note that the amount of workspace required becomes very large for even moderate sizes of ${\mathit{n}}_{1}$ and ${\mathit{n}}_{2}$.
10
Example
This example finds the Mann–Whitney test statistic, using
g08ahf for two independent samples of size
$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.
g08akf is then called to obtain the exact two tailed probability. The exact probability is also printed.
10.1
Program Text
Program Text (g08akfe.f90)
10.2
Program Data
Program Data (g08akfe.d)
10.3
Program Results
Program Results (g08akfe.r)