The routine may be called by the names g08aff or nagf_nonpar_test_kruskal.
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.
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).
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
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.
3: – Integer arrayInput
On entry: must contain the number of observations in sample , for .
, for .
4: – IntegerInput
On entry: , the number of samples.
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 , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended. When the value or 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).
6Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, .
On entry, and .
On entry, and .
On entry, all the observations were equal.
An unexpected error has been triggered by this routine. Please
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
For estimates of the accuracy of the significance , see g01ecf. The approximation is acceptable unless and or .
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g08aff is not threaded in any implementation.
The time taken by g08aff is small, and increases with and .
If , the Median test (see g08acf) or the Mann–Whitney test (see g08ahf) is more appropriate.
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.