You are here: Symbol Reference > Statistics Namespace > Functions > Statistics.MannWhitneyTest Function
Stats Master VCL
ContentsIndex
PreviousUpNext
Statistics.MannWhitneyTest Function

Two sample Mann-Whitney test.

Pascal
function MannWhitneyTest(const Data1: TVec; const Data2: TVec; out hRes: THypothesisResult; out Signif: double; var ConfInt: TTwoElmReal; const hType: THypothesisType = htTwoTailed; const Alpha: double = 0.05; const NormalApprox: boolean = true): double;
Parameters 
Description 
Data1 
First sample dataset. 
Data2 
Second sample dataset. 
hRes 
Returns the result of the null hypothesis (default assumption is that there is no difference between samples). 
Signif 
(Significance level) returns the probability of observing the given result 
ConfInt 
Returns the 100*(1-Alpha) percent confidence interval for Mann-Whitney test. Valid only if normal approximation is used to calculate significance level. 
hType 
Defines the type of the null hypothesis (left, right and two - tailed). 
Alpha 
Defines the desired significance level. If the significance probability (Signif) is bellow the desired significance (Alpha), the null hypothesis is rejected. 
NormalApprox 
If 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. 

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

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

At the end of the experimental treatment period, the subjects are individually placed in a series of claustrophobia test situations, knowing that their reactions to these situations are being recorded on videotape. Subsequently three clinical experts, uninvolved in the experimental treatment and not knowing which subject received which treatment, independently view the videotapes and rate each subject according to the degree of claustrophobic tendency shown in the test situations. Each judge's rating takes place along a 10-point scale, with 1="very low" and 10="very high"; and the final measure for each subject is the simple average of the ratings of the three judges for that subject. In this example data for first and second group is as follows: Group 1: 4.6, 4.7, 4.9, 5.1, 5.2, 5.5, 5.8, 6.1, 6.5, 6.5, 7.2 

Group 2: 5.2, 5.3, 5.4, 5.6, 6.2, 6.3, 6.8, 7.7, 8.0, 8.1 

The investigators expected first group to prove the more effective, and sure enough it is first grouš that appears to show the lower mean level of claustrophobic tendency in the test situations. You might suppose that all they need do now is plug their data into an independent-samples t-test to see whether the observed mean difference is significant. We will use Mann-Whitney U test to check if this hypothesis can be rejected. 

 

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;
#include "MtxExpr.hpp"
#include "Math387.hpp"
#include "Statistics.hpp"
void __fastcall Example()
{
  sVector v1,v2;
  v1.SetIt(false, OPENARRAY(double, (4.6, 4.7, 4.9, 5.1, 5.2, 5.5, 5.8, 6.1, 6.5, 6.5, 7.2)));
  v2.SetIt(false, OPENARRAY(double,(5.2, 5.3, 5.4, 5.6, 6.2, 6.3, 6.8, 7.7, 8.0, 8.1)));
  double signif, UStat;
  TTwoElmReal ci;
  THypothesisResult hres;
  // don't use normal approximation
  UStat = MannWhitneyTest(v1,v2,hres,signif,ci,htTwoTailed,0.05, false);
}
Examples on GitHub
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!