naginterfaces.library.nonpar.test_mwu¶
- naginterfaces.library.nonpar.test_mwu(x, y, tail)[source]¶
test_mwu
performs the Mann–Whitney test on two independent samples of possibly unequal size.For full information please refer to the NAG Library document for g08ah
https://www.nag.com/numeric/nl/nagdoc_29.3/flhtml/g08/g08ahf.html
- Parameters
- xfloat, array-like, shape
The first vector of observations, .
- yfloat, array-like, shape
The second vector of observations. .
- tailstr, length 1
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.
- Returns
- ufloat
The Mann–Whitney rank sum statistic, .
- unorfloat
The approximate Normal test statistic, , as described in Notes.
- pfloat
The tail probability, , as specified by the argument .
- tiesbool
Indicates whether the pooled sample contained ties or not. This will be useful in checking which function to use should one wish to calculate an exact tail probability.
, no ties were present (use
prob_mwu_noties()
for an exact probability)., ties were present (use
prob_mwu_ties()
for an exact probability).- ranksfloat, ndarray, shape
Contains the ranks of the pooled sample. The ranks of the first sample are contained in the first elements and those of the second sample are contained in the next elements.
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: , or .
- Warns
- NagAlgorithmicWarning
- (errno )
The pooled sample values are all the same, i.e., the variance of .
- Notes
No equivalent traditional C interface for this routine exists in the NAG Library.
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 in Parameters).
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
test_median()
) 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).
test_mwu
returns:The test statistic .
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 .
An indicator as to whether ties were present in the pooled sample or not.
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 , 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
prob_mwu_noties()
(no ties in the pooled sample) orprob_mwu_ties()
(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 .
- 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