Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_nonpar_prob_mwu_ties (g08ak)

Purpose

nag_nonpar_prob_mwu_ties (g08ak) 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.

Syntax

[p, ifail] = g08ak(n1, n2, tail, ranks, u)
[p, ifail] = nag_nonpar_prob_mwu_ties(n1, n2, tail, ranks, u)

Description

nag_nonpar_prob_mwu_ties (g08ak) computes the exact tail probability for the Mann–Whitney $U$ test statistic (calculated by nag_nonpar_test_mwu (g08ah) 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), 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 Arguments).
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)$.
nag_nonpar_prob_mwu_ties (g08ak) 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$.

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) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill

Parameters

Compulsory Input Parameters

1:     $\mathrm{n1}$int64int32nag_int scalar
The number of non-tied pairs, ${\mathit{n}}_{1}$.
Constraint: ${\mathbf{n1}}\ge 1$.
2:     $\mathrm{n2}$int64int32nag_int scalar
The size of the second sample, ${\mathit{n}}_{2}$.
Constraint: ${\mathbf{n2}}\ge 1$.
3:     $\mathrm{tail}$ – string (length ≥ 1)
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), 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:     $\mathrm{ranks}\left({\mathbf{n1}}+{\mathbf{n2}}\right)$ – double array
The ranks of the pooled sample. These ranks are output in the array ranks by nag_nonpar_test_mwu (g08ah) 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 nag_nonpar_test_mwu (g08ah).
5:     $\mathrm{u}$ – double scalar
$U$, the value of the Mann–Whitney rank sum test statistic. This is the statistic returned through the argument u by nag_nonpar_test_mwu (g08ah).
Constraint: ${\mathbf{u}}\ge 0.0$.

None.

Output Parameters

1:     $\mathrm{p}$ – double scalar
The tail probability, $p$, as specified by the argument tail.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n1}}<1$, or ${\mathbf{n2}}<1$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{tail}}\ne \text{'T'}$, $\text{'U'}$ or $\text{'L'}$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{u}}<0.0$.
${\mathbf{ifail}}=4$
 On entry, lwrk is too small.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

Accuracy

The exact tail probability, $p$, is computed to an accuracy of at least $4$ significant figures.

The time taken by nag_nonpar_prob_mwu_ties (g08ak) 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}$.

Example

This example finds the Mann–Whitney test statistic, using nag_nonpar_test_mwu (g08ah) 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. nag_nonpar_prob_mwu_ties (g08ak) is then called to obtain the exact two tailed probability. The exact probability is also printed.
```function g08ak_example

fprintf('g08ak example results\n\n');

x = [13;  6; 12;  7; 12;  7; 10;  7;
10;  7; 16;  7; 10;  8;  9;  8];
y = [17;  6; 10;  8; 15;  8; 15; 10;
15; 10; 14; 10; 14; 11; 14; 11;
13; 12; 13; 12; 13; 12; 12];
n1 = int64(numel(x));
n2 = int64(numel(y));

fprintf('Mann-Whitney U test\n\n');
fprintf('Sample size of group 1 = %5d\n', n1);
fprintf('Sample size of group 2 = %5d\n\n', n2);
fprintf('Data values\n');
fprintf('\n     Group 1 ');
for j = 1:floor(n1/8)
i1 = (j-1)*8 + 1;
i2 = min(n1,i1+7);
fprintf('%4.0f',x(i1:i2));
fprintf('\n             ');
end
fprintf('\n     Group 2 ');
for j = 1:floor(n2/8)
i1 = (j-1)*8 + 1;
i2 = min(n2,i1+7);
fprintf('%4.0f',y(i1:i2));
fprintf('\n             ');
end

% Perform test
tail = 'Lower-tail';
[u, unor, p, ties, ranks, ifail] =  ...
g08ah(x, y, tail);

% Calculate exact probabilities
if ties
[pexact, ifail] = g08ak( ...
n1, n2, tail, ranks, u);
else
[pexact, ifail] = g08aj( ...
n1, n2, tail, u);
end

fprintf('\nTest statistic            = %8.4f\n', u);
fprintf('Normalized test statistic = %8.4f\n', unor);
fprintf('Approx. tail probability  = %8.4f\n\n', p);

fprintf('\nRanks\n\n');
fprintf('     Group 1 ');
for j = 1:floor(n1/8)
i1 = (j-1)*8 + 1;
i2 = min(n1,i1+7);
fprintf('%5.1f',ranks(i1:i2));
fprintf('\n             ');
end
fprintf('\n     Group 2 ');
for j = 1:floor(n2/8)
i1 = (j-1)*8 + 1;
i2 = min(n2,i1+7);
fprintf('%5.1f',ranks(i1+n1:i2+n1));
fprintf('\n             ');
end

fprintf('\nExact tail probability    = %8.4f\n', pexact);

```
```g08ak example results

Mann-Whitney U test

Sample size of group 1 =    16
Sample size of group 2 =    23

Data values

Group 1   13   6  12   7  12   7  10   7
10   7  16   7  10   8   9   8

Group 2   17   6  10   8  15   8  15  10
15  10  14  10  14  11  14  11
13  12  13  12  13  12  12

Test statistic            =  86.0000
Normalized test statistic =  -2.8039
Approx. tail probability  =   0.0025

Ranks

Group 1  29.5  1.5 24.5  5.0 24.5  5.0 16.0  5.0
16.0  5.0 38.0  5.0 16.0  9.5 12.0  9.5

Group 2  39.0  1.5 16.0  9.5 36.0  9.5 36.0 16.0
36.0 16.0 33.0 16.0 33.0 20.5 33.0 20.5
29.5 24.5 29.5 24.5 29.5 24.5 24.5

Exact tail probability    =   0.0020
```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015