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: X(LX) – 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: LX – INTEGERInput
On entry: , the total number of observations.
Constraint:
.
- 3: L(K) – INTEGER arrayInput
On entry: must contain the number of observations in sample , for .
Constraint:
, for .
- 4: K – INTEGERInput
On entry: , the number of samples.
Constraint:
.
- 5: W(LX) – REAL (KIND=nag_wp) arrayWorkspace
- 6: H – REAL (KIND=nag_wp)Output
On exit: the value of the Kruskal–Wallis test statistic, .
- 7: P – REAL (KIND=nag_wp)Output
On exit: the approximate significance, , of the Kruskal–Wallis test statistic.
- 8: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction 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 parameter, 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.