The function may be called by the names: g08afc, nag_nonpar_test_kruskal or nag_kruskal_wallis_test.
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 group and the summation is over all tied groups.
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 g08acc) or the Mann–Whitney test (see g08amc) 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: – IntegerInput
On entry: the number of samples, .
2: – const IntegerInput
On entry: must contain the number of observations in sample , for .
, for .
3: – 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: – IntegerInput
On entry: the total number of observations, .
5: – double *Output
On exit: the value of the Kruskal–Wallis test statistic, .
6: – double *Output
On exit: the approximate significance, , of the Kruskal–Wallis test statistic.
7: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
Dynamic memory allocation failed.
The contents of array l are not valid.
Constraint: , for .
On entry, .
Constraint: , for .
On entry, .
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
For estimates of the accuracy of the significance , see g01ecc. The approximation is acceptable unless and or .
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
g08afc is not threaded in any implementation.
The time taken by g08afc is small, and increases with and .
If , the Median test (see g08acc) or the Mann–Whitney test (see g08amc) is more appropriate.
This example is taken from Moore et al.Moore et al. (1972). There are 5 groups of sizes , , , 8 and . The data represent the weight gain, in pounds, of pigs from five different litters under the same conditions.