nag_kruskal_wallis_test (g08afc) performs the Kruskal–Wallis one-way analysis of variance by ranks on independent samples of possibly unequal sizes.
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 group and the summation is over all tied groups. |
nag_kruskal_wallis_test (g08afc) 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_median_test (g08acc)) or the Mann–Whitney
test (see
nag_mann_whitney (g08amc)) is more appropriate).
- 1:
k – IntegerInput
On entry: the number of samples, .
Constraint:
.
- 2:
l[k] – const IntegerInput
-
On entry: must contain the number of observations in sample , for .
Constraint:
, for .
- 3:
x[lx] – const doubleInput
-
On entry: the elements of
x must contain the observations in the
k groups. The first
elements must contain the scores in the first group, the next
those in the second group, and so on.
- 4:
lx – IntegerInput
On entry: the total number of observations, .
Constraint:
.
- 5:
h – double *Output
-
On exit: the value of the Kruskal–Wallis test statistic, .
- 6:
p – double *Output
-
On exit: the approximate significance, , of the Kruskal–Wallis test statistic.
- 7:
fail – NagError *Input/Output
-
The NAG error argument (see
Section 3.6 in the Essential Introduction).
For estimates of the accuracy of the significance
, see
nag_prob_chi_sq (g01ecc). The
approximation is acceptable unless
and
or
.
Not applicable.
This example is taken from Moore
et al. Moore et al. (1972). There are 5 groups of sizes 5, 8, 6, 8 and 8. The data represent the weight gain, in pounds, of pigs from five different litters under the same conditions.