PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_nonpar_test_kruskal (g08af)
Purpose
nag_nonpar_test_kruskal (g08af) performs the Kruskal–Wallis one-way analysis of variance by ranks on independent samples of possibly unequal sizes.
Syntax
[
h,
p,
ifail] = nag_nonpar_test_kruskal(
x,
l, 'lx',
lx, 'k',
k)
Description
The Kruskal–Wallis test investigates the differences between scores from independent samples of unequal sizes, the th sample containing observations. The hypothesis under test, , often called the null hypothesis, is that the samples come from the same population, and this is to be tested against the alternative hypothesis that they come from different populations.
The test proceeds as follows:
(a) |
The pooled sample of all the observations is ranked. Average ranks are assigned to tied scores. |
(b) |
The ranks of the observations in each sample are summed, to give the rank sums , for . |
(c) |
The Kruskal–Wallis' test statistic is computed as:
i.e., is the total number of observations. If there are tied scores, is corrected by dividing by:
where is the number of tied scores in a sample and the summation is over all tied samples. |
nag_nonpar_test_kruskal (g08af) returns the value of
, and also an approximation,
, to the probability of a value of at least
being observed,
is true. (
approximately follows a
distribution).
is rejected by a test of chosen size
if
The approximation
is acceptable unless
and
,
or
in which case tables should be consulted (e.g., O of
Siegel (1956)) or
(in which case the Median test (see
nag_nonpar_test_median (g08ac)) or the Mann–Whitney
test (see
nag_nonpar_test_mwu (g08ah)) is more appropriate).
References
Moore P G, Shirley E A and Edwards D E (1972) Standard Statistical Calculations Pitman
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The elements of
x must contain the observations in the
k samples. The first
elements must contain the scores in the first sample, the next
those in the second sample, and so on.
- 2:
– int64int32nag_int array
-
must contain the number of observations in sample , for .
Constraint:
, for .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
x.
, the total number of observations.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
l.
, the number of samples.
Constraint:
.
Output Parameters
- 1:
– double scalar
-
The value of the Kruskal–Wallis test statistic, .
- 2:
– double scalar
-
The approximate significance, , of the Kruskal–Wallis test statistic.
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
-
-
On entry, | for some , . |
-
-
-
-
On entry, | all the observations were equal. |
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
For estimates of the accuracy of the significance
, see
nag_stat_prob_chisq (g01ec). The
approximation is acceptable unless
and
or
.
Further Comments
The time taken by nag_nonpar_test_kruskal (g08af) is small, and increases with and .
If
, the Median test (see
nag_nonpar_test_median (g08ac)) or the Mann–Whitney
test (see
nag_nonpar_test_mwu (g08ah)) is more appropriate.
Example
This example is taken from
Moore et al. (1972). There are
groups of sizes
,
,
,
and
. The data represent the weight gain, in pounds, of pigs from five different litters under the same conditions.
Open in the MATLAB editor:
g08af_example
function g08af_example
fprintf('g08af example results\n\n');
x = [23; 27; 26; 19; 30;
29; 25; 33; 36; 32; 28; 30; 31;
38; 31; 28; 35; 33; 36;
30; 27; 28; 22; 33; 34; 34; 32;
31; 33; 31; 28; 30; 24; 29; 30];
l = [int64(5);8;6;8;8];
fprintf('Kruskal-Wallis test\n\n');
fprintf('Data values\n\n');
fprintf(' Group Observations');
ix = 1;
for j = 1:numel(l)
fprintf('\n%5d ', j);
fprintf('%4.0f', x(ix:ix+l(j)-1));
ix = ix + l(j);
end
[h, p, ifail] = g08af(x, l);
fprintf('\n\nTest statistic %8.3f\n', h);
fprintf('Degrees of freedom %4d\n', numel(l)-1);
fprintf('Significance %8.3f\n', p);
g08af example results
Kruskal-Wallis test
Data values
Group Observations
1 23 27 26 19 30
2 29 25 33 36 32 28 30 31
3 38 31 28 35 33 36
4 30 27 28 22 33 34 34 32
5 31 33 31 28 30 24 29 30
Test statistic 10.537
Degrees of freedom 4
Significance 0.032
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015