The Kruskal-Wallis Test for Independent Samples
5.4.1 The Kruskal-Wallis Test for Independent Samples
The Kruskal-Wallis test is the non-parametric counterpart of the one-way ANOVA test described in section 4.5.2. The test assesses whether c independent samples are from the same population or from populations with continuous distribution and the same median for the variable being tested. The variable being tested must be at least of ordinal type. The test procedure is a direct generalisation of the Mann- Whitney rank sum test described in section 5.3.1.2. Thus, one starts by assigning natural ordered ranks to the sample values, from the smallest to the largest. Tied ranks are substituted by their average.
Commands 5.10. SPSS, STATISTICA, MATLAB and R commands used to perform the Kruskal-Wallis test.
SPSS Analyze; Nonparametric Tests; K
Independent Samples STATISTICA Statistics; Nonparametrics; Comparing multiple indep. samples (groups)
MATLAB p=kruskalwallis(x) R
kruskal.test(X~CLASS)
Let R i denote the sum of ranks for sample i, with n i cases. Under the null hypothesis, we expect that each R i will exhibit a small deviation from the average of all R i , R . The test statistic is:
12 c KW = n ( R − 2 i i R ) , 5.38
which, under the null hypothesis, has an asymptotic chi-square distribution with
df = c – 1 degrees of freedom (when the number of observations in each group exceeds 5). When there are tied ranks, a correction is inserted in formula 5.38, dividing the KW value by:
5.4 Inference on More Than Two Populations
( t i − t i ) / ( N − N ) , 5.39
where t i is the number of ties in group i of g tied groups, and N is the total number of cases in the c samples (sum of the n i ).
The power-efficiency of the Kruskal-Wallis test, referred to the one-way ANOVA, is asymptotically 95.5%.
Example 5.21
Q: Consider the Clays’ dataset (see Appendix E). Assume that at a certain stage of the data collection process, only the first 15 cases were available and the Kruskal-Wallis test was used to assess which clay features best discriminated the three types of clays (variable AGE). Perform this test and analyse its results for the
alumina content (Al 2 O 3 ) measured with only 3 significant digits.
A: Table 5.24 shows the 15 cases sorted and ranked. Notice the tied values for Al 2 O 3 = 17.3, corresponding to ranks 6 and 7, which are assigned the mean rank
(6+7)/2. The sum of the ranks is 57, 41 and 22 for the groups 1, 2 and 3, respectively; therefore, we obtain the mean ranks shown in Table 5.25. The asymptotic significance of 0.046 leads us to reject the null hypothesis of equality of medians for the three groups at a 5% level.
Table 5.24. The first fifteen cases of the Clays’ dataset, sorted and ranked.
AGE 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 Al 2 O 3 23.0 21.4 16.6 22.1 18.8 17.3 17.8 18.4 17.3 19.1 11.5 14.9 11.6 15.8 19.5 Rank 15
Table 5.25. Results, obtained with SPSS, for the Kruskal-Wallis test of alumina in the Clays’ dataset: a) ranks, b) significance.
AGE N Mean Rank AL2O3 pliocenic good clay
5 11.40 Chi-Square 6.151
pliocenic bad clay
df 2
holocenic clay
Total 15 Asymp. Sig. 0.046
214 5 Non-Parametric Tests of Hypotheses
Example 5.22
Q: Consider the Freshmen dataset and use the Kruskal-Wallis test in order to assess whether the freshmen performance (EXAMAVG) differs according to their attitude towards skipping the Initiation (Question 8).
A: The mean ranks and results of the test are shown in Table 5.26. Based on the observed asymptotic significance, we reject the null hypothesis at a 5% level, i.e., we have evidence that the freshmen answer Question 8 of the enquiry differently, depending on their average performance on the examinations.
Table 5.26. Results, obtained with SPSS, for the Kruskal-Wallis test of average freshmen performance in 5 categories of answers to Question 8: a) ranks; b) significance.
Q8 N Mean Rank EXAMAVG
5 12 63.46 Asymp. Sig. 0.007 Total 131
Example 5.23
Q: The variable ART of the Cork Stoppers’ dataset was analysed in section
4.5.2.1 using the one-way ANOVA test. Perform the same analysis using the Kruskal-Wallis test and estimate its power for the alternative hypothesis corresponding to the sample means.
A: We saw in 4.5.2.1 that a logarithmic transformation of ART was needed in order to be able to apply the ANOVA test. This transformation is not needed with the Kruskal-Wallist test, whose only assumption is the independency of the samples.
Table 5.27 shows the results, from which we conclude that the null hypothesis of median equality of the three populations is rejected at a 5% significance level (or even at a smaller level).
In order to estimate the power of this Kruskal-Wallis test, we notice that the sample size is large, and therefore, we expect the power to be the same as for the
one-way ANOVA test using a number of cases equal to n = 50 × 0.955 ≈ 48. The power of the one-way ANOVA, for the alternative hypothesis corresponding to the sample means and with n = 48, is 1.
5.4 Inference on More Than Two Populations
Table 5.27. Results, obtained with SPSS, for the Kruskal-Wallis test of variable ART of the Cork Stoppers’ dataset: a) ranks, b) significance.
CN Mean Rank ART