Nonparametric hypothesis test comparing two independent samples.
var mannWhitneyU = require( '@stdlib/stats/mannwhitneyu' );Given two independent samples x and y, the function computes the Mann–Whitney U rank-sum test to assess whether the distributions differ.
var out = mannWhitneyU( [ 7, 8, 9 ], [ 1, 2, 3 ] );
/* returns
{
'U': 0,
'pValue': 0.025,
'rejected': true
}
*/
out = mannWhitneyU( [ 10, 11, 10, 12 ], [ 9, 11, 10, 10 ] );
/* returns
{
'U': 4.5,
'pValue': 0.312,
'rejected': false
}
*/The function accepts the following options:
- alpha:
numberin the interval[0,1]giving the significance level of the hypothesis test. Default:0.05. - alternative: Either
two-sided,lessorgreater. Indicates the direction of the hypothesis test.'greater'tests whether values inxtend to be larger than those iny,'less'tests whether values inxtend to be smaller than those iny, and'two-sided'tests for any difference in distributions.
By default, the hypothesis test is carried out at a significance level of 0.05. To choose a different significance level, set the alpha option.
var out = mannWhitneyU( [ 7, 8, 9 ], [ 1, 2, 3 ], {
'alpha': 0.05,
'alternative': 'greater'
});
/* returns
{
'U': 0,
'pValue': 0.025,
'rejected': true
}
*/By default, a two-sided test is performed. To perform either of the one-sided tests, set the alternative option to less or greater.
var out = mannWhitneyU( [ 5, 6, 7, 8 ], [ 1, 2, 3, 4 ], {
'alternative': 'greater',
'alpha': 0.05
});
/* returns
{
'U': 0,
'pValue': 0.0104,
'rejected': true
}
*/
out = mannWhitneyU( [ 5, 6, 7, 8 ], [ 1, 2, 3, 4 ], {
'alternative': 'less',
'alpha': 0.05
});
/* returns
{
'U': 0,
'pValue': 0.9896,
'rejected': false
}
*/var mannWhitneyU = require( '@stdlib/stats/mannwhitneyu' );
var x = [ 12, 15, 14, 10, 13 ];
var y = [ 7, 9, 6, 8, 7 ];
var out = mannWhitneyU( x, y );
/* returns
{
'U': 0,
'pValue': 0.009,
'rejected': true
}
*/
out = mannWhitneyU( [ 5, 6, 7, 8 ], [ 1, 2, 3, 4 ] );
/* returns
{
'U': 0,
'pValue': 0.0208,
'rejected': true
}
*/
out = mannWhitneyU( [ 5, 6, 7, 8 ], [ 1, 2, 3, 4 ], {
'alternative': 'greater'
});
/* returns
{
'U': 0,
'pValue': 0.0104,
'rejected': true
}
*/
out = mannWhitneyU( [ 1, 2, 2, 3 ], [ 2, 3, 4, 5 ], {
'alternative': 'greater',
'alpha': 0.05
});
/* returns
{
'U': 2.5,
'pValue': 0.057,
'rejected': false
}
*/