NAG Library Routine Document
g08ahf (test_mwu)
1
Purpose
g08ahf performs the Mann–Whitney test on two independent samples of possibly unequal size.
2
Specification
Fortran Interface
Subroutine g08ahf ( |
n1, x, n2, y, tail, u, unor, p, ties, ranks, wrk, ifail) |
Integer, Intent (In) | :: | n1, n2 | Integer, Intent (Inout) | :: | ifail | Real (Kind=nag_wp), Intent (In) | :: | x(n1), y(n2) | Real (Kind=nag_wp), Intent (Out) | :: | u, unor, p, ranks(n1+n2), wrk(n1+n2) | Logical, Intent (Out) | :: | ties | Character (1), Intent (In) | :: | tail |
|
C Header Interface
#include <nagmk26.h>
void |
g08ahf_ (const Integer *n1, const double x[], const Integer *n2, const double y[], const char *tail, double *u, double *unor, double *p, logical *ties, double ranks[], double wrk[], Integer *ifail, const Charlen length_tail) |
|
3
Description
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
which is
- : ; 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 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 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 .
The Mann–Whitney
test differs from the Median test (see
g08acf) 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
be the rank assigned to
,
and
the rank assigned to
,
. Then the test statistic
is defined as follows;
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).
g08ahf returns:
(a) |
The test statistic . |
(b) |
The approximate Normal test statistic,
where
and
where
is the number of groups of ties in the sample and is the number of ties in the th group.
Note that if no ties are present the variance of reduces to . |
(c) |
An indicator as to whether ties were present in the pooled sample or not. |
(d) |
The tail probability, , corresponding to (adjusted to allow the complement to be used in an upper one tailed or a two tailed test), depending on the choice of tail, i.e., the choice of alternative hypothesis, . The tail probability returned is an approximation of is based on an approximate Normal statistic corrected for continuity according to the tail specified. If and are not very large an exact probability may be desired. For the calculation of the exact probability see g08ajf (no ties in the pooled sample) or g08akf (ties in the pooled sample).
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 . |
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
Arguments
- 1: – IntegerInput
-
On entry: the size of the first sample, .
Constraint:
.
- 2: – Real (Kind=nag_wp) arrayInput
-
On entry: the first vector of observations, .
- 3: – IntegerInput
-
On entry: the size of the second sample, .
Constraint:
.
- 4: – Real (Kind=nag_wp) arrayInput
-
On entry: the second vector of observations. .
- 5: – Character(1)Input
-
On entry: 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.
Constraint:
, or .
- 6: – Real (Kind=nag_wp)Output
-
On exit: the Mann–Whitney rank sum statistic, .
- 7: – Real (Kind=nag_wp)Output
-
On exit: the approximate Normal test statistic,
, as described in
Section 3.
- 8: – Real (Kind=nag_wp)Output
-
On exit: the tail probability,
, as specified by the argument
tail.
- 9: – LogicalOutput
-
On exit: indicates whether the pooled sample contained ties or not. This will be useful in checking which routine to use should one wish to calculate an exact tail probability.
, no ties were present (use
g08ajf for an exact probability).
, ties were present (use
g08akf for an exact probability).
- 10: – Real (Kind=nag_wp) arrayOutput
-
On exit: contains the ranks of the pooled sample. The ranks of the first sample are contained in the first
n1 elements and those of the second sample are contained in the next
n2 elements.
- 11: – Real (Kind=nag_wp) arrayWorkspace
-
- 12: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
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
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, .
Constraint: .
On entry, .
Constraint: .
-
On entry, .
Constraint: , or .
-
The pooled sample values are all the same, i.e., the variance of .
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.
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.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The approximate tail probability, , returned by g08ahf is a good approximation to the exact probability for cases where and . The relative error of the approximation should be less than , for most cases falling in this range.
8
Parallelism and Performance
g08ahf is not threaded in any implementation.
The time taken by g08ahf increases with and .
10
Example
This example performs the Mann–Whitney test on two independent samples of sizes and 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.
10.1
Program Text
Program Text (g08ahfe.f90)
10.2
Program Data
Program Data (g08ahfe.d)
10.3
Program Results
Program Results (g08ahfe.r)