Statistics.MannWhitneyTest Method

function MannWhitneyTest(const Data1: TVec; const Data2: TVec; out hRes: THypothesisResult; out Signif: Double; var ConfInt: TDoubleArray; const hType: THypothesisType; const Alpha: Double; const NormalApprox: Boolean): Double;

Two sample Mann-Whitney test.

#NameDescription
1Data1First sample dataset.
2Data2Second sample dataset.
3hResReturns the result of the null hypothesis (default assumption is that there is no difference between samples).
4ConfIntReturns the 100*(1-Alpha) percent confidence interval for Mann-Whitney test. Valid only if normal approximation is used to calculate significance level.
5hTypeDefines the type of the null hypothesis (left, right and two - tailed).
6AlphaDefines the desired significance level. If the significance probability (Signif) is bellow the desired significance (Alpha), the null hypothesis is rejected.
7NormalApproxIf either of the sample size is greater than 8, a z-value can be used to approximate the significance level for the test. In this case, the calculated z is compared to the standard normal significance levels. Set NormalApprox to true if you want normal approximation for significance level.
8Signif(Significance level) returns the probability of observing the given result

Returns: Double - The Mann-Whitney statistics (U, the smallest value of U1 and U2).

Remarks:

Performs two sample Mann-Whitney test. This is a method for the comparison of two independent random samples (Data1 and Data2). The Mann Whitney U statistic is defined as:

U1 = n1*n2 + 0.5*(n2+1)*n2 - sum (i=n1+1, n2) Ri

where samples of size n1 and n2 are pooled and Ri are the ranks. Actually, there are two versions of the U statistic calculated, where U2 = n1n2 - U1, where n1 and n2 are the sample sizes of the two groups. The smallest of U1 or U2 is compared to the critical value for the purpose of the test.

U can be resolved as the number of times observations in one sample precede observations in the other sample in the ranking. Wilcoxon rank sum, Kendall's S and the Mann-Whitney U test are exactly equivalent tests. In the presence of ties the Mann-Whitney test is also equivalent to a chi-square test for trend.

In most circumstances a two sided test is required; here the alternative hypothesis is that Data1 values tend to be distributed differently to Data2 values. For a lower side test the alternative hypothesis is that Data1 values tend to be smaller than Data2 values. For an upper side test the alternative hypothesis is that Data1 values tend to be larger than Data2 values.

Assumptions of the Mann-Whitney test:

  • random samples from populations
  • independence within samples and mutual independence between samples
  • measurement scale is at least ordinal

A confidence interval for the difference between two measures of location is provided with the sample medians. The assumptions of this method are slightly different from the assumptions of the Mann-Whitney test:

  • random samples from populations
  • independence within samples and mutual independence between samples
  • two population distribution functions are identical apart from a possible difference in location parameters
Examples
Uses Math387, MtxExpr, Statistics;
procedure Example;
var v1,v2: Vector;
hRes: THypothesisResult;
Signif: double;
UStat: double;
CI: TTwoElmReal;
begin
    v1.SetIt([4.6, 4.7, 4.9, 5.1, 5.2, 5.5, 5.8, 6.1, 6.5, 6.5, 7.2]);
    v2.SetIt([5.2, 5.3, 5.4, 5.6, 6.2, 6.3, 6.8, 7.7, 8.0, 8.1]);
    // don't use normal approximation
    UStat := MannWhitneyTest(v1,v2,hRes,Signif,CI,htTwoTailed,0.05,false);
end;