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. |
g08aff 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
g08acf) or the Mann–Whitney
test (see
g08ahf) is more appropriate).
- 1: – Real (Kind=nag_wp) arrayInput
-
On entry: 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: – IntegerInput
-
On entry: , the total number of observations.
Constraint:
.
- 3: – Integer arrayInput
-
On entry: must contain the number of observations in sample , for .
Constraint:
, for .
- 4: – IntegerInput
-
On entry: , the number of samples.
Constraint:
.
- 5: – Real (Kind=nag_wp) arrayWorkspace
-
- 6: – Real (Kind=nag_wp)Output
-
On exit: the value of the Kruskal–Wallis test statistic, .
- 7: – Real (Kind=nag_wp)Output
-
On exit: the approximate significance, , of the Kruskal–Wallis test statistic.
- 8: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
For estimates of the accuracy of the significance
, see
g01ecf. The
approximation is acceptable unless
and
or
.
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.