NAG Library Routine Document
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.
||N1, N2, LWRK, IWRK(2*(N1+N2+1)), IFAIL
||RANKS(N1+N2), U, P, WRK(LWRK)
G08AKF computes the exact tail probability for the Mann–Whitney
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 test investigates the difference between two populations defined by the distribution functions and respectively. The data consist of two independent samples of size and , denoted by and , taken from the two populations.
The hypothesis under test,
, often called the null hypothesis, is that the two distributions are the same, that is
, and this is to be tested against an alternative hypothesis
- : ; or
- : , i.e., the 's tend to be greater than the 's; or
- : , i.e., the 's tend to be less than the '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 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 in favour of the alternative hypothesis : we have evidence to suggest that the location, of the distribution defined by , is less than the location of the distribution defined by .
G08AKF returns the exact tail probability, , corresponding to , depending on the choice of alternative hypothesis, .
The value of can be used to perform a significance test on the null hypothesis against the alternative hypothesis . Let be the size of the significance test (that is is the probability of rejecting when is true). If then the null hypothesis is rejected. Typically might be or .
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
- 1: N1 – INTEGERInput
On entry: the number of non-tied pairs, .
- 2: N2 – INTEGERInput
On entry: the size of the second sample, .
- 3: TAIL – CHARACTER(1)Input
: indicates the choice of tail probability, and hence the alternative hypothesis.
- A two tailed probability is calculated and the alternative hypothesis is .
- An upper tailed probability is calculated and the alternative hypothesis , i.e., the 's tend to be greater than the 's.
- A lower tailed probability is calculated and the alternative hypothesis , i.e., the 's tend to be less than the 's.
, or .
- 4: RANKS() – REAL (KIND=nag_wp) arrayInput
: the ranks of the pooled sample. These ranks are output in the array RANKS
and should not be altered in any way if you are using the same
as used in G08AHF
- 5: U – REAL (KIND=nag_wp)Input
, the value of the Mann–Whitney rank sum test statistic. This is the statistic returned through the parameter U
- 6: P – REAL (KIND=nag_wp)Output
: the tail probability,
, as specified by the parameter TAIL
- 7: WRK(LWRK) – REAL (KIND=nag_wp) arrayWorkspace
- 8: LWRK – INTEGERInput
: the dimension of the array WRK
as declared in the (sub)program from which G08AKF is called.
, where and .
- 9: IWRK() – INTEGER arrayWorkspace
- 10: IFAIL – INTEGERInput/Output
must be set to
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
|On entry,||, or .|
|On entry,||LWRK is too small.|
The exact tail probability, , is computed to an accuracy of at least significant figures.
The time taken by G08AKF increases with and and the product . Note that the amount of workspace required becomes very large for even moderate sizes of and .
This example finds the Mann–Whitney test statistic, using G08AHF
for two independent samples of size
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.
9.1 Program Text
Program Text (g08akfe.f90)
9.2 Program Data
Program Data (g08akfe.d)
9.3 Program Results
Program Results (g08akfe.r)