Double MannWhitneyTest(TVec Data1, TVec Data2, ref THypothesisResult hRes, ref Double Signif, ref Double[] ConfInt, THypothesisType hType, Double Alpha, Boolean NormalApprox)
Two sample Mann-Whitney test.
| # | Name | Description |
|---|---|---|
| 1 | Data1 | First sample dataset. |
| 2 | Data2 | Second sample dataset. |
| 3 | hRes | Returns the result of the null hypothesis (default assumption is that there is no difference between samples). |
| 4 | ConfInt | Returns the 100*(1-Alpha) percent confidence interval for Mann-Whitney test. Valid only if normal approximation is used to calculate significance level. |
| 5 | hType | Defines the type of the null hypothesis (left, right and two - tailed). |
| 6 | Alpha | Defines the desired significance level. If the significance probability (Signif) is bellow the desired significance (Alpha), the null hypothesis is rejected. |
| 7 | 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. |
| 8 | Signif | (Significance level) returns the probability of observing the given result |
Returns: Double - 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
using Dew.Math;
using Dew.Stats;
using Dew.Stats.Units;
namespace Dew.Examples
{
private void Example()
{
Vector v1 = new Vector(0);
Vector v2 = new Vector(0);
v1.SetIt(false, new 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, new double[] {5.2, 5.3, 5.4, 5.6, 6.2, 6.3, 6.8, 7.7, 8.0, 8.1});
double signif, UStat;
double[] ci = new double[2];
THypothesisResult hres;
// don't use normal approximation
UStat = Statistics.MannWhitneyTest(v1,v2,out hres,out signif,out ci,THypothesisType.htTwoTailed,0.05, false);
}
}