G08AKF (PDF version)
G08 Chapter Contents
G08 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G08AKF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

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

SUBROUTINE G08AKF ( N1, N2, TAIL, RANKS, U, P, WRK, LWRK, IWRK, IFAIL)
INTEGER  N1, N2, LWRK, IWRK(2*(N1+N2+1)), IFAIL
REAL (KIND=nag_wp)  RANKS(N1+N2), U, P, WRK(LWRK)
CHARACTER(1)  TAIL

3  Description

G08AKF computes the exact tail probability for the Mann–Whitney U test statistic (calculated by G08AHF and returned through the parameter 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 Fx and Gy respectively. The data consist of two independent samples of size n1 and n2, denoted by x1,x2,,xn1 and y1,y2,,yn2, taken from the two populations.
The hypothesis under test, H0, often called the null hypothesis, is that the two distributions are the same, that is Fx=Gx, and this is to be tested against an alternative hypothesis H1 which is 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 parameter 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 H0 in favour of the alternative hypothesis H1: Fx>Gy we have evidence to suggest that the location, of the distribution defined by Fx, is less than the location of the distribution defined by Gy.
G08AKF returns the exact tail probability, p, corresponding to U, depending on the choice of alternative hypothesis, H1.
The value of p can be used to perform a significance test on the null hypothesis H0 against the alternative hypothesis H1. Let α be the size of the significance test (that is α is the probability of rejecting H0 when H0 is true). If p<α then the null hypothesis is rejected. Typically α 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) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill

5  Parameters

1:     N1 – INTEGERInput
On entry: the number of non-tied pairs, n1.
Constraint: N11.
2:     N2 – INTEGERInput
On entry: the size of the second sample, n2.
Constraint: N21.
3:     TAIL – CHARACTER(1)Input
On entry: indicates the choice of tail probability, and hence the alternative hypothesis.
TAIL='T'
A two tailed probability is calculated and the alternative hypothesis is H1:FxGy.
TAIL='U'
An upper tailed probability is calculated and the alternative hypothesis H1:Fx<Gy, i.e., the x's tend to be greater than the y's.
TAIL='L'
A lower tailed probability is calculated and the alternative hypothesis H1:Fx>Gy, i.e., the x's tend to be less than the y's.
Constraint: TAIL='T', 'U' or 'L'.
4:     RANKSN1+N2 – 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 n1, n2 and U as used in G08AHF.
5:     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 parameter U by G08AHF.
Constraint: U0.0.
6:     P – REAL (KIND=nag_wp)Output
On exit: the tail probability, p, as specified by the parameter TAIL.
7:     WRKLWRK – REAL (KIND=nag_wp) arrayWorkspace
8:     LWRK – INTEGERInput
On entry: the dimension of the array WRK as declared in the (sub)program from which G08AKF is called.
Constraint: LWRKn+nn+1n+m- nn+12×n+13+1, where n=minN1,N2 and m=maxN1,N2.
9:     IWRK2×N1+N2+1 – INTEGER arrayWorkspace
10:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ 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 parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry 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:
IFAIL=1
On entry,N1<1,
orN2<1.
IFAIL=2
On entry,TAIL'T', 'U' or 'L'.
IFAIL=3
On entry,U<0.0.
IFAIL=4
On entry,LWRK is too small.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction 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 implementation-specific information.

9  Further Comments

The time taken by G08AKF increases with n1 and n2 and the product n1n2. Note that the amount of workspace required becomes very large for even moderate sizes of n1 and n2.

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)


G08AKF (PDF version)
G08 Chapter Contents
G08 Chapter Introduction
NAG Library Manual

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