Statology

Statistics Made Easy

Kruskal-Wallis Test: Definition, Formula, and Example

A Kruskal-Wallis test is used to determine whether or not there is a statistically significant difference between the medians of three or more independent groups.

This test is the nonparametric equivalent of the one-way ANOVA and is typically used when the normality assumption is violated.

The Kruskal-Wallis test does not assume normality in the data and is much less sensitive to outliers than the one-way ANOVA.

Here are a couple examples of when you might conduct a Kruskal-Wallis test:

Example 1: Comparing Study Techinques

You randomly split up a class of 90 students into three groups of 30. Each group uses a different studying technique for one month to prepare for an exam.

At the end of the month, all of the students take the same exam. You want to know whether or not the studying technique has an impact on exam scores.

From previous studies you know that the distributions of exam scores for these three studying techniques are not normally distributed so you conduct a Kruskal-Wallis test to determine if there is a statistically significant difference between the median scores of the three groups.

Example 2: Comparing Sunlight Exposure

You want to know whether or not sunlight impacts the growth of a certain plant, so you plant groups of seeds in four different locations that experience either high sunlight, medium sunlight, low sunlight or no sunlight.

After one month you measure the height of each group of plants. It is known that the distribution of heights for this certain plant is not normally distributed and is prone to outliers.

To determine if sunlight impacts growth, you conduct a Kruskal-Wallis test to determine if there is a statistically significant difference between the median height of the four groups.

Kruskal-Wallis Test Assumptions

Before we can conduct a Kruskal-Wallis test, we need to make sure the following assumptions are met:

1. Ordinal or Continuous Response Variable  – the response variable should be an ordinal or continuous variable. An example of an ordinal variable is a survey response question measured on a Likert Scale (e.g. a 5-point scale from “strongly disagree” to “strongly agree”) and an example of a continuous variable is weight (e.g. measured in pounds).

2. Independence – the observations in each group need to be independent of each other. Usually a randomized design will take care of this.

3. Distributions have similar shapes – the distributions in each group need to have a similar shape.

If these assumptions are met, then we can proceed with conducting a Kruskal-Wallis test.

Example of a Kruskal-Wallis Test

A researcher wants to know whether or not three drugs have different effects on knee pain, so he recruits 30 individuals who all experience similar knee pain and randomly splits them up into three groups to receive either Drug 1, Drug 2, or Drug 3.

After one month of taking the drug, the researcher asks each individual to rate their knee pain on a scale of 1 to 100, with 100 indicating the most severe pain.

The ratings for all 30 individuals are shown below:

The researcher wants to know whether or not the three drugs have different effects on knee pain, so he conducts a Kruskal-Wallis Test using a .05 significance level to determine if there is a statistically significant difference between the median knee pain ratings across these three groups.

We can use the following steps to perform the Kruskal-Wallis Test:

Step 1. State the hypotheses. 

The null hypothesis (H 0 ): The median knee-pain ratings across the three groups are equal.

The alternative hypothesis: (Ha): At least one of the median knee-pain ratings is different from the others.

Step 2. Perform the Kruskal-Wallis Test.

To conduct a Kruskal-Wallis Test, we can simply enter the values shown above into the Kruskal-Wallis Test Calculator :

Kruskal-Wallis Test Calculator

Then click the “Calculate” button:

kruskal wallis test null and alternative hypothesis

Step 3. Interpret the results. 

Since the p-value of the test ( 0.21342 ) is not less than 0.05, we fail to reject the null hypothesis.

We do not have sufficient evidence to say that there is a statistically significant difference between the median knee pain ratings across these three groups.

Additional Resources

The following tutorials explain how to perform a Kruskal-Wallis Test using different statistical software:

How to Perform a Kruskal-Wallis Test in Excel How to Perform a Kruskal-Wallis Test in Python How to Perform a Kruskal-Wallis Test in SPSS How to Perform a Kruskal-Wallis Test in Stata How to Perform a Kruskal-Wallis Test in SAS Online Kruskal-Wallis Test Calculator

' src=

Published by Zach

Leave a reply cancel reply.

Your email address will not be published. Required fields are marked *

Library homepage

  • school Campus Bookshelves
  • menu_book Bookshelves
  • perm_media Learning Objects
  • login Login
  • how_to_reg Request Instructor Account
  • hub Instructor Commons
  • Download Page (PDF)
  • Download Full Book (PDF)
  • Periodic Table
  • Physics Constants
  • Scientific Calculator
  • Reference & Cite
  • Tools expand_more
  • Readability

selected template will load here

This action is not available.

Statistics LibreTexts

12.11: Kruskal–Wallis Test

  • Last updated
  • Save as PDF
  • Page ID 13854

  • John H. McDonald
  • University of Delaware

Learning Objectives

  • To learn to use the Kruskal–Wallis test when you have one nominal variable and one ranked variable. It tests whether the mean ranks are the same in all the groups.

When to use it

The most common use of the Kruskal–Wallis test is when you have one nominal variable and one measurement variable, an experiment that you would usually analyze using one-way anova, but the measurement variable does not meet the normality assumption of a one-way anova. Some people have the attitude that unless you have a large sample size and can clearly demonstrate that your data are normal, you should routinely use Kruskal–Wallis; they think it is dangerous to use one-way anova, which assumes normality, when you don't know for sure that your data are normal. However, one-way anova is not very sensitive to deviations from normality. I've done simulations with a variety of non-normal distributions, including flat, highly peaked, highly skewed, and bimodal, and the proportion of false positives is always around \(5\%\) or a little lower, just as it should be. For this reason, I don't recommend the Kruskal-Wallis test as an alternative to one-way anova. Because many people use it, you should be familiar with it even if I convince you that it's overused.

The Kruskal-Wallis test is a non-parametric test, which means that it does not assume that the data come from a distribution that can be completely described by two parameters, mean and standard deviation (the way a normal distribution can). Like most non-parametric tests, you perform it on ranked data, so you convert the measurement observations to their ranks in the overall data set: the smallest value gets a rank of \(1\), the next smallest gets a rank of \(2\), and so on. You lose information when you substitute ranks for the original values, which can make this a somewhat less powerful test than a one-way anova; this is another reason to prefer one-way anova.

The other assumption of one-way anova is that the variation within the groups is equal (homoscedasticity). While Kruskal-Wallis does not assume that the data are normal, it does assume that the different groups have the same distribution, and groups with different standard deviations have different distributions. If your data are heteroscedastic, Kruskal–Wallis is no better than one-way anova, and may be worse. Instead, you should use Welch's anova for heteoscedastic data.

The only time I recommend using Kruskal-Wallis is when your original data set actually consists of one nominal variable and one ranked variable; in this case, you cannot do a one-way anova and must use the Kruskal–Wallis test. Dominance hierarchies (in behavioral biology) and developmental stages are the only ranked variables I can think of that are common in biology.

The Mann–Whitney \(U\)-test (also known as the Mann–Whitney–Wilcoxon test, the Wilcoxon rank-sum test, or the Wilcoxon two-sample test) is limited to nominal variables with only two values; it is the non-parametric analogue to two-sample t –test. It uses a different test statistic (\(U\) instead of the \(H\) of the Kruskal–Wallis test), but the \(P\) value is mathematically identical to that of a Kruskal–Wallis test. For simplicity, I will only refer to Kruskal–Wallis on the rest of this web page, but everything also applies to the Mann–Whitney \(U\)-test.

The Kruskal–Wallis test is sometimes called Kruskal–Wallis one-way anova or non-parametric one-way anova. I think calling the Kruskal–Wallis test an anova is confusing, and I recommend that you just call it the Kruskal–Wallis test.

Null hypothesis

The null hypothesis of the Kruskal–Wallis test is that the mean ranks of the groups are the same. The expected mean rank depends only on the total number of observations (for \(n\) observations, the expected mean rank in each group is (\(\frac{n+1}{2}\)), so it is not a very useful description of the data; it's not something you would plot on a graph.

You will sometimes see the null hypothesis of the Kruskal–Wallis test given as "The samples come from populations with the same distribution." This is correct, in that if the samples come from populations with the same distribution, the Kruskal–Wallis test will show no difference among them. I think it's a little misleading, however, because only some kinds of differences in distribution will be detected by the test. For example, if two populations have symmetrical distributions with the same center, but one is much wider than the other, their distributions are different but the Kruskal–Wallis test will not detect any difference between them.

The null hypothesis of the Kruskal–Wallis test is not that the means are the same. It is therefore incorrect to say something like "The mean concentration of fructose is higher in pears than in apples (Kruskal–Wallis test, \(P=0.02\))," although you will see data summarized with means and then compared with Kruskal–Wallis tests in many publications. The common misunderstanding of the null hypothesis of Kruskal-Wallis is yet another reason I don't like it.

The null hypothesis of the Kruskal–Wallis test is often said to be that the medians of the groups are equal, but this is only true if you assume that the shape of the distribution in each group is the same. If the distributions are different, the Kruskal–Wallis test can reject the null hypothesis even though the medians are the same. To illustrate this point, I made up these three sets of numbers. They have identical means (\(43.5\)), and identical medians (\(27.5\)), but the mean ranks are different (\(34.6\), \(27.5\) and \(20.4\), respectively), resulting in a significant (\(P=0.025\)) Kruskal–Wallis test:

How the test works

Here are some data on Wright's \(F_{ST}\) (a measure of the amount of geographic variation in a genetic polymorphism) in two populations of the American oyster, Crassostrea virginica . McDonald et al. (1996) collected data on \(F_{ST}\) for six anonymous DNA polymorphisms (variation in random bits of DNA of no known function) and compared the \(F_{ST}\) values of the six DNA polymorphisms to \(F_{ST}\) values on \(13\) proteins from Buroker (1983). The biological question was whether protein polymorphisms would have generally lower or higher \(F_{ST}\) values than anonymous DNA polymorphisms. McDonald et al. (1996) knew that the theoretical distribution of \(F_{ST}\) for two populations is highly skewed, so they analyzed the data with a Kruskal–Wallis test.

When working with a measurement variable, the Kruskal–Wallis test starts by substituting the rank in the overall data set for each measurement value. The smallest value gets a rank of \(1\), the second-smallest gets a rank of \(2\), etc. Tied observations get average ranks; in this data set, the two \(F_{ST}\) values of \(-0.005\) are tied for second and third, so they get a rank of \(2.5\).

You calculate the sum of the ranks for each group, then the test statistic, \(H\). \(H\) is given by a rather formidable formula that basically represents the variance of the ranks among groups, with an adjustment for the number of ties. \(H\) is approximately chi-square distributed, meaning that the probability of getting a particular value of \(H\) by chance, if the null hypothesis is true, is the \(P\) value corresponding to a chi-square equal to \(H\); the degrees of freedom is the number of groups minus \(1\). For the example data, the mean rank for DNA is \(10.08\) and the mean rank for protein is \(10.68\), \(H=0.043\), there is \(1\) degree of freedom, and the \(P\) value is \(0.84\). The null hypothesis that the \(F_{ST}\) of DNA and protein polymorphisms have the same mean ranks is not rejected.

For the reasons given above, I think it would actually be better to analyze the oyster data with one-way anova. It gives a \(P\) value of \(0.75\), which fortunately would not change the conclusions of McDonald et al. (1996).

If the sample sizes are too small, \(H\) does not follow a chi-squared distribution very well, and the results of the test should be used with caution. \(N\) less than \(5\) in each group seems to be the accepted definition of "too small."

Assumptions

The Kruskal–Wallis test does NOT assume that the data are normally distributed; that is its big advantage. If you're using it to test whether the medians are different, it does assume that the observations in each group come from populations with the same shape of distribution, so if different groups have different shapes (one is skewed to the right and another is skewed to the left, for example, or they have different variances), the Kruskal–Wallis test may give inaccurate results (Fagerland and Sandvik 2009). If you're interested in any difference among the groups that would make the mean ranks be different, then the Kruskal–Wallis test doesn't make any assumptions.

Heteroscedasticity is one way in which different groups can have different shaped distributions. If the distributions are heteroscedastic, the Kruskal–Wallis test won't help you; instead, you should use Welch's t –test for two groups, or Welch's anova for more than two groups.

Bolek and Coggins (2003) collected multiple individuals of the toad Bufo americanus, , the frog Rana pipiens, and the salamander Ambystoma laterale from a small area of Wisconsin. They dissected the amphibians and counted the number of parasitic helminth worms in each individual. There is one measurement variable (worms per individual amphibian) and one nominal variable (species of amphibian), and the authors did not think the data fit the assumptions of an anova. The results of a Kruskal–Wallis test were significant (\(H=63.48\), \(2 d.f.\), \(P=1.6\times 10^{-14}\)); the mean ranks of worms per individual are significantly different among the three species.

Cafazzo et al. (2010) observed a group of free-ranging domestic dogs in the outskirts of Rome. Based on the direction of \(1815\) observations of submissive behavior, they were able to place the dogs in a dominance hierarchy, from most dominant (Merlino) to most submissive (Pisola). Because this is a true ranked variable, it is necessary to use the Kruskal–Wallis test. The mean rank for males (\(11.1\)) is lower than the mean rank for females (\(17.7\)), and the difference is significant (\(H=4.61\), \(1 d.f.\), \(P=0.032\)).

Graphing the results

It is tricky to know how to visually display the results of a Kruskal–Wallis test. It would be misleading to plot the means or medians on a bar graph, as the Kruskal–Wallis test is not a test of the difference in means or medians. If there are relatively small number of observations, you could put the individual observations on a bar graph, with the value of the measurement variable on the \(Y\) axis and its rank on the \(X\) axis, and use a different pattern for each value of the nominal variable. Here's an example using the oyster \(F_{ST}\) data:

If there are larger numbers of observations, you could plot a histogram for each category, all with the same scale, and align them vertically. I don't have suitable data for this handy, so here's an illustration with imaginary data:

Similar tests

One-way anova is more powerful and a lot easier to understand than the Kruskal–Wallis test, so unless you have a true ranked variable, you should use it.

How to do the test

Spreadsheet.

I have put together a spreadsheet to do the Kruskal–Wallis test kruskalwallis.xls on up to \(20\) groups, with up to \(1000\) observations per group.

Richard Lowry has web pages for performing the Kruskal–Wallis test for two groups , three groups , or four groups .

Salvatore Mangiafico's \(R\) Companion has a sample R program for the Kruskal–Wallis test .

To do a Kruskal–Wallis test in SAS, use the NPAR1WAY procedure (that's the numeral "one," not the letter "el," in NPAR1WAY). WILCOXON tells the procedure to only do the Kruskal–Wallis test; if you leave that out, you'll get several other statistical tests as well, tempting you to pick the one whose results you like the best. The nominal variable that gives the group names is given with the CLASS parameter, while the measurement or ranked variable is given with the VAR parameter. Here's an example, using the oyster data from above:

DATA oysters; INPUT markername $ markertype $ fst; DATALINES; CVB1 DNA -0.005 CVB2m DNA 0.116 CVJ5 DNA -0.006 CVJ6 DNA 0.095 CVL1 DNA 0.053 CVL3 DNA 0.003 6Pgd protein -0.005 Aat-2 protein 0.016 Acp-3 protein 0.041 Adk-1 protein 0.016 Ap-1 protein 0.066 Est-1 protein 0.163 Est-3 protein 0.004 Lap-1 protein 0.049 Lap-2 protein 0.006 Mpi-2 protein 0.058 Pgi protein -0.002 Pgm-1 protein 0.015 Pgm-2 protein 0.044 Sdh protein 0.024 ; PROC NPAR1WAY DATA=oysters WILCOXON; CLASS markertype; VAR fst; RUN;

The output contains a table of "Wilcoxon scores"; the "mean score" is the mean rank in each group, which is what you're testing the homogeneity of. "Chi-square" is the \(H\)-statistic of the Kruskal–Wallis test, which is approximately chi-square distributed. The "Pr > Chi-Square" is your \(P\) value. You would report these results as "\(H=0.04\), \(1 d.f.\), \(P=0.84\)."

Wilcoxon Scores (Rank Sums) for Variable fst classified by Variable markertype Sum of Expected Std Dev Mean markertype N Scores Under H0 Under H0 Score ----------------------------------------------------------------- DNA 6 60.50 63.0 12.115236 10.083333 protein 14 149.50 147.0 12.115236 10.678571

Kruskal–Wallis Test Chi-Square 0.0426 DF 1 Pr > Chi-Square 0.8365

Power analysis

I am not aware of a technique for estimating the sample size needed for a Kruskal–Wallis test.

  • Picture of a salamander from Cortland Herpetology Connection .
  • Bolek, M.G., and J.R. Coggins. 2003. Helminth community structure of sympatric eastern American toad, Bufo americanus americanus, northern leopard frog, Rana pipiens, and blue-spotted salamander, Ambystoma laterale, from southeastern Wisconsin. Journal of Parasitology 89: 673-680.
  • Buroker, N. E. 1983. Population genetics of the American oyster Crassostrea virginica along the Atlantic coast and the Gulf of Mexico. Marine Biology 75:99-112.
  • Cafazzo, S., P. Valsecchi, R. Bonanni, and E. Natoli. 2010. Dominance in relation to age, sex, and competitive contexts in a group of free-ranging domestic dogs. Behavioral Ecology 21: 443-455.
  • Fagerland, M.W., and L. Sandvik. 2009. The Wilcoxon-Mann-Whitney test under scrutiny. Statistics in Medicine 28: 1487-1497.
  • McDonald, J.H., B.C. Verrelli and L.B. Geyer. 1996. Lack of geographic variation in anonymous nuclear polymorphisms in the American oyster, Crassostrea virginica. Molecular Biology and Evolution 13: 1114-1118.

Kruskal-Wallis Test (Jump to: Lecture | Video )

Ordinal data is displayed in the table below. Is there a difference between Groups 1, 2, and 3 using alpha = 0.05?

Let's test to see if there are any differences with a hypothesis test.

1. Define Null and Alternative Hypotheses

2. State Alpha

alpha = 0.05

3. Calculate Degrees of Freedom

df = k � 1, where k = number of groups

df = 3 � 1 = 2

4. State Decision Rule

We look up our critical value in the Chi-Square Table and find a critical value of plus/minus 5.99.

5. Calculate Test Statistic

First, we must rank every score we have:

We then replace our original values with the rankings we've just found:

An "H" score (think of it as a Chi-Square value) is then calculated using the sums of the ranks of each group:

6. State Results

Do not reject the null hypothesis.

7. State Conclusion

There is no significant difference among the three groups, H = 2.854 (2, N=18), p > .05.

Back to Top

Spring 2024

UVA's newly-renovated main library, Shannon, is open! As we move the books back in, services may be impacted. See current service status.

Home

Getting Started with the Kruskal-Wallis Test

One of the most well-known statistical tests to analyze the differences between means of given groups is the ANOVA (analysis of variance) test. While ANOVA is a great tool, it assumes that the data in question follows a normal distribution. What if your data doesn’t follow a normal distribution or if your sample size is too small to determine a normal distribution? That’s where the Kruskal-Wallis test comes in.

The Kruskal-Wallis test can be thought of as the non-parametric equivalent to ANOVA. This test determines if independent groups have the same mean on ranks; instead of using the data values themselves, a rank is assigned to each data point and those ranks are used to determine if the data in each group originates from the same distribution. Essentially this test determines if the groups have the same median.

As mentioned above, Kruskal-Wallis is a non-parametric test, meaning it makes no assumptions about the data’s parameters such as it’s mean, variance, etc. Because it makes no assumptions about the data’s parameters, it is unable to make an assumption about the distribution of the data; this is how Kruskal-Wallis does not assume normally distributed data.

Kruskal-Wallis is typically used with three or more independent groups, but can be used with just two, and each group should have a sample size of 5 or more. To perform a Kruskal-Wallis test, we use the ranks of the data to calculate the test statistic, H, given by

\[H = \frac{12}{N(N+1)} \sum_{i=1}^{k} \frac{R_i^2}{n_i}-3(N+1)\]

where N is the total sample size, k is the number of groups we are comparing, \(R_i\) is the sum of ranks for group i, and \(n_i\) is the sample size of group i.

We then compare H to a critical cutoff point determined by the chi-square distribution (chi-square is used because it is a good approximation of H, especially if each group’s sample size is >= 5). If the H statistic is significant (H is larger than the cutoff) we reject the null hypothesis. If the H statistic is not significant (H is smaller than the cutoff) we fail to reject the null hypothesis. In this test the null hypothesis is that the medians of each group are the same, meaning that all groups come from the same distribution. The alternative hypothesis is that at least one of the groups has a different median, meaning at least one comes from a different distribution than the others.

Assumptions

  • Ordinal Variables - the variable in question should be ordinal or continuous, i.e., have some kind of hierarchy to them
  • Independence - each group should be independent from the others
  • Sample size - each group must have a sample size of 5 or more. With a sample size in this range, the chi-square distribution well-approximates the H statistic.

How-To and Example (by hand)

The step-by-step process to calculate the H statistic is as follows:

Step 1: State your hypothesis - Null Hypothesis: the medians (mean on ranks) are equal across the samples; Alternative Hypothesis: at least one median is different

Step 2: Prepare and rank your data - Arrange data from all groups together in one list in an ascending order - Give a rank to each of the data entries

Step 3: Sum the ranks for each group

Step 4: Calculate the test statistic, H

Step 5: Compare it to the critical cutoff, determined by the critical chi-square value

Step 6: Interpret your results

As an example, we will use data on antibody production after receiving a vaccine. A hospital administered three different vaccines to 6 individuals each and measured the antibody presence in their blood after a chosen time period. The data is as follows:

We want to determine how the three vaccines perform compared to each other. This can be quantified by determining if each vaccine causes the recipients to produce the same number of antibodies. Essentially we are looking to determine if the antibody data for each vaccine originates from the same distribution. We have relatively small sample sizes so we cannot well-determine if the data is normally distributed, so we use the Kruskal-Wallis test.

Null Hypothesis \(H_0 =\) the vaccines cause the same amount of antibodies to be produced (all three groups originate from the same distribution and have the same median)

Alternative Hypothesis \(H_A =\) At least one of the vaccines causes a different amount of antibodies to be produced (at least one group originates from a different distribution and has a different median)

Here we organize our data into ascending order then give each a rank.

Now we put our data back into their original groups and sum the ranks for each group.

Here, the sum of ranks for vaccine A is 77 , the sum of ranks for vaccine B is 29 , and the sum of ranks for vaccine C is 65 .

Now we are ready to calculate our test statistic H \(H = \frac{12}{N(N+1)} \sum_{i=1}^{k} \frac{R_i^2}{n_i}-3(N+1)\) . For our data,

\[R_i = 77, 29, 65\]

\[n_i = 6, 6, 6 \]

Plugging these in we get:

\[H = \frac{12}{18(18+1)} \left[\frac{77^2}{6} + \frac{29^2}{6} + \frac{65^2}{6}\right]-3(18+1)\]

Working out the math gives us a test statistic of \[H = 7.29824\]

Next we compare this H statistic to the critical cutoff: the corresponding chi-square value. We can determine the chi-squre value by referencing a chi-square probabilities table.

We find the degrees of freedom by subtracting 1 from \(k\) :

\[df = k-1 \] \[ = 3-1 = 2\]

Using this value and a probability of 0.05 we find

\[\chi^2(2) = 5.99\]

The comparison between H = 7.29824 and \(\chi^2(2)\) = 5.99 gives

\[H > \chi^2(2).\]

Finally we interpret our results. Since H is larger than the critical cutoff \(\chi^2(2)\) , we reject the null hypothesis ; the medians are not the same across all three groups, at least one of them has a different median than the others. This means that all three vaccines do not perform equally, at least one vaccine causes their recipients to produce a different amount of antibodies than the others.

It’s important to note that Kruskal-Wallis can only tell us that at least one of the groups originates from a different distribution. It cannot tell us which of the group(s) that is(are).

How-To and Example (with Python)

The Python scipy.stats module has a function called kruskal() . Basically this function carries out the above calculation for us. This function takes two or more array-like objects as arguments and returns the H statistic and the p-value. Like most statistical software, the kruskal() function computes approximate p-values that are based on the chi-squared distribution. To refresh our memories, the p-value in this case is the probability of seeing differences in the groups as large as what we witnessed if the null hypothesis is true. If we have a small p-value, say less than 0.05, we have evidence against the null. Small p-values with Kruskal-Wallis lead us to reject the null hypothesis and say that at least one of our groups likely originates from a different distribution than the others.

Here we will use the same example data and use kruskal() to carry out the test. We enter the data into three separate arrays, one array for each group (in this case vaccine). We store the data in one array per group to make it easy for kruskal() to tell our groups apart. This function interprets each array input as a separate group and will use each array as its own group in the H statistic and \(\chi^2\) calculations.

Here we see that the p-value is ~0.026 which is less than the cutoff 0.05, so we reject the null hypothesis : the medians are not the same across all three groups, at least one of them has a different median than the others. This means that the vaccines do not perform equally well because the resulting antibody production is not the same for each vaccine. We draw the same conclusion as we did above when we performed the calculation ourselves!

Again we emphasize that the Kruskal-Wallis test can only tell us that at least one of the vaccines performs differently than the others. It cannot tell us which vaccine(s) that is(are). In order to determine which vaccine performs differently we would need to conduct a post hoc test.

Kruskal-Wallis tests if groups originate from the same distribution by determining if the groups have the same median

Kruskal-Wallis is a non-parametric test, meaning it does not assume normally distributed data

The test statistic is the H statistic given by \(H = \frac{12}{N(N+1)} \sum_{i=1}^{k} \frac{R_i^2}{n_i}-3(N+1)\)

Compare the H statistic to the critical cutoff given by the \(\chi^2\) distribution (with df=k-1 and chosen probability)

  • H > \(\chi^2\) –> reject the null hypothesis
  • H < \(\chi^2\) –> fail to reject the null hypothesis

Use the Python scipy.stats function kruskal() to compute this quickly

  • p < 0.05 : reject the null hypothesis
  • p >= 0.05 : fail to reject the null hypothesis

Reject the null hypothesis : at least one group has a different median so we're confident at least one group originates from a different distribution

Fail to reject the null hypothesis : we cannot reject the possibility that all groups originate from the same distribution

Kruskal-Wallis can only tell us if the groups originate from the same distribution. If we reject the null hypothesis, we can only conclude that one or more of the groups has a different median (comes from a different distribution). The test cannot tell us which groups originate from a different distribution .

Samantha Lomuscio StatLab Associate University of Virginia Library December 07, 2021

For questions or clarifications regarding this article, contact  [email protected] .

View the entire collection  of UVA Library StatLab articles, or learn how to cite .

Research Data Services

Want updates in your inbox? Subscribe to our monthly Research Data Services Newsletter!

Related categories:

SPSS tutorials website header logo

Kruskal-Wallis Test – Simple Tutorial

Kruskal-wallis test example, kruskal-wallis test assumptions, kruskal-wallis test formulas, kruskal-wallis post hoc tests, apa reporting a kruskal-wallis test.

A Kruskal-Wallis test tests if 3(+) populations have equal mean ranks on some outcome variable. The figure below illustrates the basic idea.

Kruskal Wallis Test Diagram

  • First off, our scores are ranked ascendingly, regardless of group membership.
  • Now, if scores are not related to group membership, then the average mean ranks should be roughly equal over groups.
  • If these average mean ranks are very different in our sample, then some groups tend to have higher scores than other groups in our population as well: scores are related to group membership.

Kruskal-Wallis Test - Purposes

The Kruskal-Wallis test is a distribution free alternative for an ANOVA : we basically want to know if 3+ populations have equal means on some variable. However,

  • ANOVA is not suitable if the dependent variable is ordinal;
  • ANOVA requires the dependent variable to be normally distributed in each subpopulation, especially if sample sizes are small.

The Kruskal-Wallis test is a suitable alternative for ANOVA if sample sizes are small and/or the dependent variable is ordinal.

A hospital runs a quick pilot on 3 vaccines: they administer each to N = 5 participants. After a week, they measure the amount of antibodies in the participants’ blood. The data thus obtained are in this Googlesheet , partly shown below.

Kruskal Wallis Test Example Data

Now, we'd like to know if some vaccines trigger more antibodies than others in the underlying populations. Since antibodies is a quantitative variable, ANOVA seems the right choice here. However, ANOVA requires antibodies to be normally distributed in each subpopulation. And due to our minimal sample sizes, we can't rely on the central limit theorem like we usually do (or should anyway). And on top of that, our sample sizes are too small to examine normality. Just the emphasize this point, the histograms for antibodies by group are shown below.

Split Histogram Antibodies

If anything, the bottom two histograms seem slightly positively skewed . This makes sense because the amount of antibodies has a lower bound of zero but no upper bound. However, speculations regarding the population distributions don't get any more serious than that.

A particularly bad idea here is trying to demonstrate normality by running

  • a Shapiro-Wilk normality test and/or
  • a Kolmogorov-Smirnov test .

Due to our tiny sample sizes, these tests are unlikely to reject the null hypothesis of normality. However, that's merely due to their lack of power and doesn't say anything about the population distributions. Put differently: a different null hypothesis (our variable following a uniform or Poisson distribution) would probably not be rejected either for the exact same data.

In short: ANOVA really requires normality for tiny sample sizes but we don't know if it holds. So we can't trust ANOVA results. And that's why we should use a Kruskal-Wallis test instead.

Kruskal-Wallis Test - Null Hypothesis

The null hypothesis for a Kruskal-Wallis test is that the mean ranks on some outcome variable are equal across 3+ populations. Note that the outcome variable must be ordinal or quantitative in order for “mean ranks” to be meaningful.

Many textbooks propose an incorrect null hypothesis such as:

  • some outcome variable has equal medians over 3+ populations or
  • some outcome variable follows identical distributions over 3+ populations.

So why are these incorrect? Well, the Kruskal-Wallis formula uses only 2 statistics: ranks sums and the sample sizes on which they're based. It completely ignores everything else about the data -including medians and frequency distributions. Neither of these affect whether the null hypothesis is (not) rejected.

If that still doesn't convince you, we'll perhaps add some example data files to this tutorial. These illustrate that wildly different medians or frequency distributions don't always result in a “significant” Kruskal-Wallis test (or reversely).

A Kruskal-Wallis test requires 3 assumptions 1 , 5 , 8 :

  • independent observations;
  • the dependent variable must be quantitative or ordinal;
  • sufficient sample sizes (say, each n i ≥ 5) unless the exact significance level is computed.

Regarding the last assumption, exact p-values for the Kruskal-Wallis test can be computed. However, this is rarely done because it often requires very heavy computations. Some exact p-values are also found in Use of Ranks in One-Criterion Variance Analysis . Instead, most software computes approximate (or “asymptotic”) p-values based on the chi-square distribution. This approximation is sufficiently accurate if the sample sizes are large enough. There's no real consensus with regard to required sample sizes: some authors 1 propose each n i ≥ 4 while others 6 suggest each n i ≥ 6.

First off, we rank the values on our dependent variable ascendingly, regardless of group membership. We did just that in this Googlesheet , partly shown below.

Next, we compute the sum over all ranks for each group separately.

Kruskal Wallis Test Descriptive Statistics

We then enter a) our samples sizes and b) our ranks sums into the following formula:

$$Kruskal\;Wallis\;H = \frac{12}{N(N + 1)}\sum\limits_{i = 1}^k\frac{R_i^2}{n_i} - 3(N + 1)$$

  • \(N\) denotes the total sample size;
  • \(k\) denotes the number of groups we're comparing;
  • \(R_i\) denotes the rank sum for group \(i\);
  • \(n_i\) denotes the sample size for group \(i\).

For our example, that'll be

$$Kruskal\;Wallis\;H = \frac{12}{15(15 + 1)}(\frac{55^2}{5}+\frac{20^2}{5}+\frac{45^2}{5}) - 3(15 + 1) =$$

$$Kruskal\;Wallis\;H = 0.05\cdot(605 + 80 + 405) - 48 = 6.50$$

\(H\) approximately follows a chi-square (written as χ 2 ) distribution with

$$df = k - 1$$

degrees of freedom (\(df\)) for \(k\) groups. For our example,

$$df = 3 - 1 = 2$$

so our significance level is

$$\chi^2(2) = 6.50, p \approx 0.039.$$

The SPSS output for our example, shown below, confirms our calculations.

Kruskal Wallis Test Apa Reporting

So what do we conclude now? Well, assuming alpha = 0.05, we reject our null hypothesis: the population mean ranks of antibodies are not equal among vaccines. In normal language, our 3 vaccines do not perform equally well. Judging from the mean ranks, it seems vaccine B performs worse than its competitors: its mean rank is lower and this means that it triggered fewer antibodies than the other vaccines.

Thus far, we concluded that the amounts of antibodies differ among our 3 vaccines. So precisely which vaccine differs from which vaccine? We'll compare each vaccine to each other vaccine for finding out. This procedure is generally known as running post-hoc tests.

In contrast to popular belief, Kruskal-Wallis post-hoc tests are not equivalent to Bonferroni corrected Mann-Whitney tests . Instead, each possible pair of groups is compared using the following formula:

$$Z_{kw} = \frac{\overline{R}_i - \overline{R}_j}{\sqrt{\frac{N(N + 1)}{12}(\frac{1}{n_i}+\frac{1}{n_j})}}$$

  • our test statistic, \(Z_{kw}\), approximately follows a standard normal distribution ;
  • \(\overline R_i\) denotes the mean rank for group \(i\);
  • \(N\) denotes the total sample size (including groups not used in this pairwise comparison);

For comparing vaccines A and B, that'll be

$$Z_{kw} = \frac{11 - 4}{\sqrt{\frac{15(15 + 1)}{12}(\frac{1}{5}+\frac{1}{5})}} \approx 2.475 $$

$$P(|Z_{kw}| > 2.475) \approx 0.013$$

A Bonferroni correction is usually applied to this p-value because we're running multiple comparisons on (partly) the same observations. The number of pairwise comparisons for \(k\) groups is

$$N_{comp} = \frac{k (k - 1)}{2}$$

Therefore, the Bonferroni corrected p-value for our example is

$$P_{Bonf} = 0.013 \cdot \frac{3 (2 - 1)}{2} \approx 0.040$$

The screenshot from SPSS (below) confirms these findings.

Kruskal Wallis Test Post Hoc Tests Output SPSS

For APA reporting our example analysis, we could write something like “a Kruskal-Wallis test indicated that the amount of antibodies differed over vaccines, H(2) = 6.50, p = 0.039.

Although the APA doesn't mention it, we encourage reporting the mean ranks and perhaps some other descriptives statistics in a separate table as well.

Reporting Kruskal Wallis Test Descriptives

Right, so that should do. If you've any questions or remarks, please throw me a comment below. Other than that:

Thanks for reading!

  • Van den Brink, W.P. & Koele, P. (2002). Statistiek, deel 3 [Statistics, part 3]. Amsterdam: Boom.
  • Warner, R.M. (2013). Applied Statistics (2nd. Edition) . Thousand Oaks, CA: SAGE.
  • Agresti, A. & Franklin, C. (2014). Statistics. The Art & Science of Learning from Data. Essex: Pearson Education Limited.
  • Field, A. (2013). Discovering Statistics with IBM SPSS Statistics . Newbury Park, CA: Sage.
  • Howell, D.C. (2002). Statistical Methods for Psychology (5th ed.). Pacific Grove CA: Duxbury.
  • Siegel, S. & Castellan, N.J. (1989). Nonparametric Statistics for the Behavioral Sciences (2nd ed.). Singapore: McGraw-Hill.
  • Slotboom, A. (1987). Statistiek in woorden [Statistics in words]. Groningen: Wolters-Noordhoff.
  • Kruskal, W.H. & Wallis, W.A. (1952). Use of ranks in one-criterion variance analysis. Journal of the American Statistical Association, 47, 583-621.

Tell us what you think!

This tutorial has 18 comments:.

kruskal wallis test null and alternative hypothesis

By Ruben Geert van den Berg on June 10th, 2021

Thanks for the compliment!

We're trying to publish some new (and better) tutorials but it's a slow process due to tons of project work...

Anyway, keep up the good work!

SPSS tutorials

kruskal wallis test null and alternative hypothesis

By Carlos Hernández on October 13th, 2022

Excelent tutorial. Very helpful.

I´m trying to improve my visualization habilities, so I´ve a question: the graph showing histogram by vaccine was made in SPSS? If so, there are some help on this topic?

Thank you very much.

By Ruben Geert van den Berg on October 14th, 2022

Hola Carlos!

In general, you'll want to avoid avoid Graph - Chart builder. You can create 95% of the charts you need via Graph - Legacy Dialogs . This is much easier and the charts will be identical.

If you create a histogram via the legacy dialogs, you can add a split variable to the columns (or in this case) rows pane. This creates a split histogram in a single chart.

Hope that helps!

Ruben SPSS tutorials

Privacy Overview

Kruskal-Wallis test

This page offers all the basic information you need about the kruskal-wallis test. It is part of Statkat’s wiki module, containing similarly structured info pages for many different statistical methods. The info pages give information about null and alternative hypotheses, assumptions, test statistics and confidence intervals, how to find p values, SPSS how-to’s and more.

To compare the kruskal-wallis test with other statistical methods, go to Statkat's Comparison tool or practice with the kruskal-wallis test at Statkat's Practice question center

  • 1. When to use
  • 2. Null hypothesis
  • 3. Alternative hypothesis
  • 4. Assumptions
  • 5. Test statistic
  • 6. Sampling distribution
  • 7. Significant?
  • 8. Example context

When to use?

Note that theoretically, it is always possible to 'downgrade' the measurement level of a variable. For instance, a test that can be performed on a variable of ordinal measurement level can also be performed on a variable of interval measurement level, in which case the interval variable is downgraded to an ordinal variable. However, downgrading the measurement level of variables is generally a bad idea since it means you are throwing away important information in your data (an exception is the downgrade from ratio to interval level, which is generally irrelevant in data analysis).

If you are not sure which method you should use, you might like the assistance of our method selection tool or our method selection table .

Null hypothesis

The kruskal-wallis test tests the following null hypothesis (H 0 ):

  • H 0 : the population medians for the $I$ groups are equal
  • H 0 : the population scores in any of the $I$ groups are not systematically higher or lower than the population scores in any of the other groups
  • H 0 : P(an observation from population $g$ exceeds an observation from population $h$) = P(an observation from population $h$ exceeds an observation from population $g$), for each pair of groups.

Alternative hypothesis

The kruskal-wallis test tests the above null hypothesis against the following alternative hypothesis (H 1 or H a ):

  • H 1 : not all of the population medians for the $I$ groups are equal
  • H 1 : the poplation scores in some groups are systematically higher or lower than the population scores in other groups
  • H 1 : for at least one pair of groups: P(an observation from population $g$ exceeds an observation from population $h$) $\neq$ P(an observation from population $h$ exceeds an observation from population $g$)

Assumptions

Statistical tests always make assumptions about the sampling procedure that was used to obtain the sample data. So called parametric tests also make assumptions about how data are distributed in the population. Non-parametric tests are more 'robust' and make no or less strict assumptions about population distributions, but are generally less powerful. Violation of assumptions may render the outcome of statistical tests useless, although violation of some assumptions (e.g. independence assumptions) are generally more problematic than violation of other assumptions (e.g. normality assumptions in combination with large samples).

The kruskal-wallis test makes the following assumptions:

  • Group 1 sample is a simple random sample (SRS) from population 1, group 2 sample is an independent SRS from population 2, $\ldots$, group $I$ sample is an independent SRS from population $I$. That is, within and between groups, observations are independent of one another

Test statistic

The kruskal-wallis test is based on the following test statistic:

$H = \dfrac{12}{N (N + 1)} \sum \dfrac{R^2_i}{n_i} - 3(N + 1)$ Here $N$ is the total sample size, $R_i$ is the sum of ranks in group $i$, and $n_i$ is the sample size of group $i$. Remember that multiplication precedes addition, so first compute $\frac{12}{N (N + 1)} \times \sum \frac{R^2_i}{n_i}$ and then subtract $3(N + 1)$.

Sampling distribution

For large samples, approximately the chi-squared distribution with $I - 1$ degrees of freedom.

For small samples, the exact distribution of $H$ should be used.

Significant?

This is how you find out if your test result is significant:

  • Check if $X^2$ observed in sample is equal to or larger than critical value $X^{2*}$ or
  • Find $p$ value corresponding to observed $X^2$ and check if it is equal to or smaller than $\alpha$

Example context

The kruskal-wallis test could for instance be used to answer the question:

How to perform the kruskal-wallis test in SPSS:

  • Put your dependent variable in the box below Test Variable List and your independent (grouping) variable in the box below Grouping Variable
  • Click on the Define Range... button. If you can't click on it, first click on the grouping variable so its background turns yellow
  • Fill in the smallest value you have used to indicate your groups in the box next to Minimum, and the largest value you have used to indicate your groups in the box next to Maximum
  • Continue and click OK

How to perform the kruskal-wallis test in jamovi :

  • Put your dependent variable in the box below Dependent Variables and your independent (grouping) variable in the box below Grouping Variable

LEARN STATISTICS EASILY

LEARN STATISTICS EASILY

Learn Data Analysis Now!

LEARN STATISTICS EASILY LOGO 2

Kruskal-Wallis Test: Mastering Non-Parametric Analysis for Multiple Groups

You will learn the essential steps to accurately applying the Kruskal-Wallis Test in diverse research scenarios.

Introduction

Imagine understanding how different medications impact patient recovery times without assuming a normal data distribution. Enter the  Kruskal-Wallis Test , a powerful tool in non-parametric statistical analysis that transcends the limitations of traditional parametric tests. Designed for comparing median values across multiple groups, this test is important for researchers dealing with non-normal or ordinal data distributions. It provides:

  • A robust method for discerning significant differences;
  • Ensuring that insights gleaned from diverse datasets are both accurate and reliable;
  • Marking a pivotal advancement in statistical methodologies.
  • The Kruskal-Wallis Test is ideal for non-normal data distribution.
  • It compares medians across multiple groups effectively.
  • There is no need for data to meet strict variance homogeneity.
  • Applicable for both small and large sample sizes.
  • Interpreting H statistics and p-values reveals group differences.

 width=

Ad description. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Background and Theory

In statistical analysis,  non-parametric statistics  provide a vital framework for analyzing data without relying on the traditional assumptions of parametric tests, such as normal distribution or homogeneity of variances. Non-parametric methods, including the  Kruskal-Wallis Test , are particularly useful for handling ordinal data or when the sample size is too small to validate the distribution assumptions required by parametric tests.

Understanding Non-Parametric Statistics

Non-parametric statistics do not presume an underlying probability distribution for the analyzed data. This makes them highly versatile and applicable in various situations where parametric assumptions cannot be met. Non-parametric tests are particularly useful for skewed distributions and ordinal data, offering a robust alternative when the data’s measurement scale does not support parametric assumptions.

The Kruskal-Wallis Test: A Closer Look

The  Kruskal-Wallis Test  is a non-parametric alternative to the one-way ANOVA and is used to determine if there are statistically significant differences between two or more groups of an independent variable on a continuous or ordinal dependent variable. It’s particularly noteworthy for its application across multiple groups where the assumptions of ANOVA are not tenable.

Assumptions

  • The dependent variable should be continuous, ordinal, or count data.
  • The dependent variable should be continuous or ordinal.
  • The independent variable should consist of two or more categorical, independent groups.
  • Observations across groups should be independent.

Note: The data does not need to follow a normal distribution, making the Kruskal-Wallis Test a non-parametric method.

Comparison with ANOVA

While the ANOVA test relies on the data meeting assumptions of normality and homogeneity of variances, the Kruskal-Wallis Test does not. Instead, it ranks the data and compares the sums of these ranks between groups, making it suitable for non-normal distributions and ordinal data. However, unlike ANOVA, it does not directly test for mean differences but rather for differences in the median or distribution between groups.

Key Takeaways

  • Non-parametric statistics, like the Kruskal-Wallis Test, are essential when data do not meet the normality assumption.
  • The Kruskal-Wallis Test is valuable for analyzing differences across multiple groups without the stringent assumptions required by parametric tests like ANOVA.
  • It is applicable to a wide range of fields and research scenarios, making it a versatile tool in statistical analysis.

Effect Size and Types in the Kruskal-Wallis Test

The Kruskal-Wallis Test identifies significant differences across multiple groups, but discerning the practical impact of these differences necessitates the calculation of effect sizes. Effect size metrics translate statistical significance into quantifiable impact measures, crucial for real-world application and interpretation.

Standard Measures of Effect Size

Adapted Eta Squared (η²) : Traditionally used in ANOVA, η² can be adapted for Kruskal-Wallis by relating the test’s H statistic to the total variance. This adaptation offers an estimate of the effect’s magnitude. However, it should be interpreted with the non-parametric nature of the data in mind.

Epsilon Squared (ε²) : Designed for the Kruskal-Wallis Test, ε² provides insight into the variance explained by group differences, considering the non-parametric ranking of data. It’s a nuanced measure that complements the test’s findings by quantifying effect size without relying on parametric assumptions.

Additional Non-Parametric Effect Size Measures

Cohen’s d (Adapted for Non-Parametric Use) : When conducting post-hoc pairwise comparisons, an adapted version of Cohen’s d can be applied to quantify the standardized difference between groups. This adaptation should account for the rank-based nature of the comparisons.

Rank-Biserial Correlation : This measure offers an intuitive effect size as a correlation coefficient by comparing mean ranks between groups. It’s particularly user-friendly, providing a straightforward interpretation of effect size that’s accessible to a broad audience.

Incorporating these effect size calculations into Kruskal-Wallis Test analyses enriches the statistical narrative, ensuring that findings are statistically significant and carry clear implications for practical application. By quantifying the magnitude of group differences, researchers can convey their results’ real-world relevance more effectively.

Post-Hoc Tests for Kruskal-Wallis Test

Upon finding significant results with the Kruskal-Wallis Test, it’s often necessary to perform post-hoc tests to pinpoint where the differences lie between groups. These tests provide:

  • Detailed pairwise comparisons;
  • Helping to understand which specific groups differ from each other;
  • Thus offering more profound insights into the data.

After identifying significant results with the Kruskal-Wallis Test, post-hoc analyses are essential for pinpointing specific group differences. Here are the critical tests:

Dunn’s Test

  • What it is : A widely-used non-parametric method for comparing ranks between pairs of groups.
  • Usage : Preferred for detailed analysis after a Kruskal-Wallis Test indicates significant overall differences.
  • Characteristics : Incorporates adjustments for multiple comparisons, minimizing the risk of Type I errors.

Nemenyi Test

  • What it is : The Nemenyi Test is a non-parametric approach similar to the Tukey HSD test used in ANOVA, designed for conducting multiple pairwise comparisons based on rank sums.
  • Usage : This test follows a significant Kruskal-Wallis Test, mainly when the objective is to compare every group against every other group.
  • Characteristics : It offers a comprehensive analysis without assuming normal distributions, making it applicable to various data types. The test is beneficial for providing a detailed overview of the pairwise differences among groups.

Conover’s Test

  • What it is : A non-parametric test for pairwise group comparisons, akin to Dunn’s Test, but employs a distinct method for p-value adjustment.
  • Usage : Applied when a more nuanced pairwise comparison is desired post-Kruskal-Wallis.
  • Characteristics : Provides an alternative p-value adjustment method suitable for various data types.

Dwass-Steel-Critchlow-Fligner (DSCF) Test

  • What it is : A non-parametric method tailored for multiple pairwise comparisons.
  • Usage : Ideal for post-Kruskal-Wallis analysis, offering a comprehensive pairwise comparison framework without normal distribution assumptions.
  • Characteristics : Adjusts for multiple testing, ensuring the integrity of statistical conclusions.

Mann-Whitney U Test

  • What it is : Also known as the Wilcoxon rank-sum test, it compares two independent groups.
  • Usage : Suitable for pairwise comparisons post-Kruskal-Wallis, especially when analyzing specific group differences.
  • Considerations : Not designed for multiple comparisons; adjustments (like the Bonferroni correction) are necessary to manage the Type I error rate.

Each test has unique features and applicability, making them valuable tools for post-hoc analysis following a Kruskal-Wallis Test. The specific research questions, data characteristics, and the need for Type I error control should guide the choice of test.

When to Use the Kruskal-Wallis Test

The  Kruskal-Wallis Test  is a non-parametric method for comparing medians across multiple independent groups. It is beneficial in scenarios where the assumptions required for parametric tests like ANOVA are violated. Below are specific situations where the Kruskal-Wallis Test is most appropriate:

Non-Normal Data Distributions : When the data does not follow a normal distribution, especially with small sample sizes where the Central Limit Theorem does not apply, the Kruskal-Wallis Test provides a reliable alternative.

Ordinal Data : This test can compare groups effectively for data measured on an ordinal scale, where numerical differences between levels are not consistent or meaningful.

Heterogeneous Variances : In cases where the groups have different variances, the Kruskal-Wallis Test can still be applied, unlike many parametric tests that require homogeneity of variances.

Small Sample Sizes : When sample sizes are too small to check the assumptions of parametric tests reliably, the Kruskal-Wallis Test can be a more suitable choice.

By applying the  Kruskal-Wallis Test  in these scenarios, researchers can obtain reliable insights into group differences without the stringent assumptions required by parametric tests. This enhances the robustness and applicability of statistical analyses across diverse research fields, ensuring findings are grounded in accurate, methodologically sound practices.

Clinical Research : Comparing the effect of three different medications on pain relief, where pain relief levels are rated on an ordinal scale (e.g., no relief, mild relief, moderate relief, complete relief).

Environmental Science : Assessing the impact of various pollutants on plant growth where the growth is categorized into ordinal levels (e.g., no growth, slow growth, moderate growth, high growth), and the data is skewed or does not meet normality assumptions.

Marketing Studies : Evaluating customer satisfaction across multiple stores in a retail chain, where satisfaction is measured on a Likert scale (e.g., very dissatisfied, dissatisfied, neutral, satisfied, very satisfied).

Educational Research : Analyzing test score improvements across different teaching methods where the improvement is categorized (e.g., no improvement, slight improvement, moderate improvement, significant improvement) and the data distribution is unknown or non-normal.

Step-by-Step Guide to Calculate the Kruskal-Wallis Test

The Kruskal-Wallis Test is a non-parametric statistical test used to determine if there are statistically significant differences between the medians of three or more independent groups. This guide will walk you through the manual calculations involved in performing this test, providing a clear and understandable approach.

Preparing Your Data

1. Collect Data : Ensure your data is organized, with one column representing the independent variable (the groups) and another for the dependent variable (the data you want to compare across groups).

2. Assumptions Check : Confirm that your data meets the assumptions for the Kruskal-Wallis Test. The test requires that the data from each group be independent and that the dependent variable is at least ordinal.

Manual Calculations

1. Rank the Data : Combine all group observations into a single dataset and rank them from smallest to largest. If there are tied values, assign them the average rank.

2. Sum the Ranks : Calculate the sum of ranks for each group.

3. Calculate the Test Statistic (H) :

The formula for the Kruskal-Wallis H statistic is:

Where n is the total number of observations, k is the number of groups , R i​ is the sum of ranks for the i th  group, and n i ​ is the number of observations in the i th  group.

4. Determine Degrees of Freedom : This is one less than the number of groups being compared.

5. Find the Critical Value : Use a chi-square ( χ 2) distribution table to find the critical value corresponding to your degrees of freedom and chosen significance level (commonly 0.05).

6. Compare H to the Critical Value : If your calculated H statistic is greater than the critical value from the  χ 2 table, you can reject the null hypothesis and conclude that there is a significant difference between the groups.

Calculating Effect Size ( η 2 )

The Kruskal-Wallis test does not inherently provide an effect size, but one approach to estimate it is through eta squared ( η 2 ), calculated as:

η 2 = ( H  –  k  + 1)/( n  –  k )​

where H is the Kruskal-Wallis statistic, k is the number of groups, and n is the total number of observations.

This provides a measure of how much of the variance in the data is explained by the group differences.

Visual Representation

Consider creating a box plot to visualize the distribution of your data across the groups. This can help in understanding the data and explaining the results.

Box-Plot for Kruskal-Wallis Test

How to Perform the Kruskal-Wallis Test in R

This guide provides a detailed, step-by-step tutorial on performing the Kruskal-Wallis Test using R, including calculating effect size and conducting post-hoc tests for multiple comparisons.

Preparation of Data:

1. Data Input : Begin by ensuring your data is formatted correctly in R. Typically, you will have one column representing the independent variable (grouping factor) and another for the dependent variable (scores or measurements you wish to compare).

2. Data Inspection : Visualizing and inspecting your data before running the test is crucial. Use boxplots to assess the distribution across groups.

Performing Kruskal-Wallis Test:

1. Run the Test : Utilize the kruskal.test() function in R, specifying your dependent and independent variables.

2. Interpret Results : The output will provide the Kruskal-Wallis statistic and the associated p-value. A significant p-value (typically < 0.05) indicates a difference in medians across the groups.

Effect Size Calculation:

1. Compute Eta-squared : While Kruskal-Wallis test does not directly provide an effect size, eta-squared (η²) can be used as an estimate.

Post-Hoc Analysis:

1. Perform Post-Hoc Tests:  If the Kruskal-Wallis test is significant, you may need to perform post-hoc tests to identify which groups differ. The pairwise.wilcox.test() function with a Bonferroni correction can be used for this purpose.

2. Interpret Post-Hoc Results : This will provide pairwise comparisons between groups, highlighting significant differences.

Interpreting the Results of Kruskal-Wallis Test

Understanding the results of the  Kruskal-Wallis Test  involves dissecting several crucial components, including the  H statistic ,  p-values , and  effect sizes . Additionally, when significant differences are identified,  post-hoc analyses  are essential for pinpointing specific group differences. This section aims to clarify these elements, providing a comprehensive overview of the analysis outcomes.

H Statistic and P-values

The  H statistic  is the core outcome of the Kruskal-Wallis Test, signifying the variance among the ranks across different groups. A larger H value suggests a more pronounced difference between group medians. To decipher this statistic:

  • The H value is compared against a critical value from the Chi-square distribution, factoring in the degrees of freedom (number of groups minus one).
  • The  p-value  associated with the H statistic indicates the probability of observing the given result, or more extreme, under the null hypothesis. A p-value below the predefined alpha level (usually 0.05) indicates a statistically significant difference among at least one pair of group medians.

Effect Sizes

Effect sizes  quantify the magnitude of differences observed, offering a dimension of interpretation beyond statistical significance. For the Kruskal-Wallis Test,  eta squared (η²)  is a commonly utilized measure, reflecting the variance in ranks attributable to group differences. The interpretation of eta-squared values is as follows:

  • Small effect : η² ≈ 0.01
  • Medium effect : η² ≈ 0.06
  • Large effect : η² ≈ 0.14

Multiple Comparisons and Post-Hoc Tests

Significant findings from the Kruskal-Wallis Test necessitate further examination through  post-hoc tests  to identify distinct group differences. These tests include  Dunn’s ,  Nemenyi’s , and  Conover’s , each tailored for specific conditions and data types. Critical points for conducting posthoc analyses are:

  • Choose a post-hoc test that aligns with the study’s objectives and data attributes.
  • These tests inherently adjust for the risk of Type I errors due to multiple comparisons, ensuring the integrity of the inferential process.

Common Pitfalls and Avoidance Strategies

  • Overemphasis on Significance : A significant p-value doesn’t automatically imply a meaningful or large effect. It’s vital to integrate effect size considerations for a balanced interpretation.
  • Distribution Assumptions : Although the Kruskal-Wallis Test is less assumption-bound than its parametric counterparts, it ideally requires comparable distribution shapes across groups, barring median differences. Ensuring this similarity enhances the test’s validity.

By precisely navigating these components, researchers can draw accurate and meaningful conclusions from the Kruskal-Wallis Test, enriching the understanding of their data’s underlying patterns and relationships.

Case Studies and Applications

The  Kruskal-Wallis Test  is a powerful non-parametric method for comparing three or more independent groups. This section presents real-world applications and hypothetical case studies to illustrate the efficacy and insights derived from utilizing the Kruskal-Wallis Test.

Real-World Application: Environmental Science

In an environmental study, researchers aimed to assess the impact of industrial pollution on the growth rates of specific plant species across multiple sites. The sites were categorized into three groups based on their proximity to industrial areas: high pollution, moderate pollution, and low pollution zones. Given the non-normal distribution of growth rates and the ordinal nature of the data, the Kruskal-Wallis Test was employed.

The test revealed a significant difference in median growth rates among the three groups ( H statistic  significant at p < 0.05), indicating that pollution levels significantly affect plant growth. This insight led to targeted environmental policies focusing on reducing industrial emissions in critical areas.

Hypothetical Example: Healthcare Research

Consider a hypothetical study in  healthcare  where researchers investigate the effectiveness of three different treatment protocols for chronic disease. Patients are randomly assigned to one of the three treatment groups, and the outcome measure is the improvement in quality of life, scored on an ordinal scale.

Utilizing the Kruskal-Wallis Test, researchers find a statistically significant difference in the median improvement scores across the treatment groups. Further post-hoc analysis identifies which specific treatments differ significantly, guiding medical professionals toward more effective treatment protocols.

Throughout this article, we have explored the  Kruskal-Wallis Test , emphasizing its critical role in statistical analysis when dealing with non-parametric data across multiple groups. This test’s value lies in its ability to handle data that do not meet the assumptions of normality, providing a robust alternative to traditional ANOVA. Its versatility is demonstrated through various applications, from environmental science to healthcare, where it aids in deriving meaningful insights that guide decision-making and policy development. The Kruskal-Wallis Test stands as a testament to the pursuit of truth, enabling researchers to uncover the underlying patterns in data, thereby contributing to the greater good by informing evidence-based practices.

Recommended Articles

Discover more cutting-edge statistical techniques and their applications by exploring our collection of in-depth articles on our blog.

  • Mastering One-Way ANOVA: A Comprehensive Guide for Beginners
  • Mastering the Mann-Whitney U Test: A Comprehensive Guide
  • Common Mistakes to Avoid in One-Way ANOVA Analysis
  • Non-Parametric Statistics: A Comprehensive Guide
  • MANOVA: A Practical Guide for Data Scientists

Frequently Asked Questions (FAQs)

Q1: What is the Kruskal-Wallis Test?  The Kruskal-Wallis Test is a non-parametric statistical method used to compare medians across three or more independent groups. It’s beneficial when data do not meet the assumptions required for parametric tests like the one-way ANOVA.

Q2: When should the Kruskal-Wallis Test be used?  This test is suitable for non-normal distributions, ordinal data, heterogeneous variances, and small sample sizes where traditional parametric assumptions cannot be met.

Q3: How does the Kruskal-Wallis Test differ from ANOVA?  Unlike ANOVA, the Kruskal-Wallis Test does not assume a normal data distribution or variance homogeneity. It ranks the data and compares the sums of these ranks between groups, making it ideal for non-normal distributions and ordinal data.

Q4: What are the assumptions of the Kruskal-Wallis Test?  The main assumptions include the dependent variable being continuous or ordinal, the independent variable consisting of two or more categorical, independent groups, and the observations across groups being independent.

Q5: Can the Kruskal-Wallis Test be used for post-hoc analysis?  Yes, upon finding significant results, post-hoc tests like Dunn’s Test, Nemenyi Test, Conover’s Test, Dwass-Steel-Critchlow-Fligner Test, and Mann-Whitney U Test (with adjustments) can be conducted to identify specific group differences.

Q6: How are effect sizes calculated in the Kruskal-Wallis Test?  Effect sizes can be quantified using adapted Eta Squared (η²), Epsilon Squared (ε²), an adapted version of Cohen’s d for non-parametric use, and Rank-Biserial Correlation, providing insights into the magnitude of group differences.

Q7: What are some practical applications of the Kruskal-Wallis Test?  This test is widely used in clinical research, environmental science, marketing studies, and educational research, mainly when dealing with ordinal data, non-normal distributions, or small sample sizes.

Q8: How is the data analyzed in the Kruskal-Wallis Test?  Data is ranked across all groups, and the test evaluates whether the distribution of ranks differs significantly across the groups, focusing on median differences rather than mean differences.

Q9: What should be considered when interpreting the results of the Kruskal-Wallis Test?  While the test indicates whether group differences are statistically significant, it does not specify where they lie. Post-hoc tests are necessary for detailed pairwise comparisons.

Q10: Are there limitations to the Kruskal-Wallis Test?  Yes, the test does not provide information on mean differences and requires subsequent post-hoc analyses for detailed insights. It also does not accommodate paired data or repeated measures.

Similar Posts

Understanding Distributions of Generalized Linear Models

Understanding Distributions of Generalized Linear Models

Dive into “Distributions of Generalized Linear Models” to master the core concepts and applications of statistical modeling.

Generate a Random Number

Generate a Random Number

Generate a Random Number with our user-friendly generator! The generated random numbers will be displayed below the button as a list.

Coefficient of Determination vs. Coefficient of Correlation in Data Analysis

Coefficient of Determination vs. Coefficient of Correlation in Data Analysis

Uncover the differences between the coefficient of determination vs coefficient of correlation and their crucial roles in data analysis.

What is the T-Statistic? Mastering the Basics

What is the T-Statistic? Mastering the Basics

What Is the T-Test Statistic? Master the basics of inferential statistics, enhancing your data analysis skills and decision-making abilities.

Florence Nightingale: How Data Visualization in the Form of Pie Charts Saved Lives

Florence Nightingale: How Data Visualization in the Form of Pie Charts Saved Lives

Discover how Florence Nightingale used data visualization and pie charts to revolutionize healthcare during the Crimean War.

Understanding Sampling Error: A Foundation in Statistical Analysis

Understanding Sampling Error: A Foundation in Statistical Analysis

Understand the concept of sampling error, its impacts, and strategies to mitigate it in statistical analysis and data science.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

kruskal wallis test null and alternative hypothesis

Open topic with navigation

Kruskal-Wallis Test

Menu location: Analysis_Analysis of Variance_Kruskal-Wallis .

This is a method for comparing several independent random samples and can be used as a nonparametric alternative to the one way ANOVA.

The Kruskal-Wallis test statistic for k samples, each of size n i is:

- where N is the total number (all n i ) and R i is the sum of the ranks (from all samples pooled) for the ith sample and:

The null hypothesis of the test is that all k distribution functions are equal. The alternative hypothesis is that at least one of the populations tends to yield larger values than at least one of the other populations.

Assumptions:

  • random samples from populations
  • independence within each sample
  • mutual independence among samples
  • measurement scale is at least ordinal
  • either k population distribution functions are identical, or else some of the populations tend to yield larger values than other populations

If the test is significant, you can make multiple comparisons between the samples. You may choose the level of significance for these comparisons (default is a = 0.05). All pairwise comparisons are made and the probability of each presumed "non-difference" is indicated (Conover, 1999; Critchlow and Fligner, 1991; Hollander and Wolfe, 1999) . Two alternative methods are used to make all possible pairwise comparisons between groups; these are Dwass-Steel-Critchlow-Fligner and Conover-Iman. In most situations, you should use the Dwass-Steel-Critchlow-Fligner result.

By the Dwass-Steel-Critchlow-Fligner procedure, a contrast is considered significant if the following inequality is satisfied:

- where q is a quantile from the normal range distribution for k groups, n i is size of the ith group, n j is the size of the jth group, t b is the number of ties at rank b and W ij is the sum of the ranks for the ith group where observations for both groups have been ranked together. The values either side of the greater than sign are displayed in parentheses in StatsDirect results.

The Conover-Iman procedure is simply Fisher's least significant difference method performed on ranks. A contrast is considered significant if the following inequality is satisfied:

- where t is a quantile from the Student t distribution on N-k degrees of freedom. The values either side of the greater than sign are displayed in parentheses in StatsDirect results.

An alternative to Kruskal-Wallis is to perform a one way ANOVA on the ranks of the observations.

StatsDirect also gives you an homogeneity of variance test option with Kruskal-Wallis; this is marked as "Equality of variance (squared ranks)". Please refer to homogeneity of variance for more details.

Technical Validation

The test statistic is an extension of the Mann-Whitney test and is calculated as above. In the presence of tied ranks the test statistic is given in adjusted and unadjusted forms, (opinion varies concerning the handling of ties). The test statistic follows approximately a chi-square distribution with k-1 degrees of freedom; P values are derived from this. For small samples you may wish to refer to tables of the Kruskal-Wallis test statistic but the chi-square approximation is highly satisfactory in most cases ( Conover, 1999 ).

From Conover (1999, p. 291) .

Test workbook (ANOVA worksheet: Method 1, Method 2, Method 3, Method 4).

The following data represent corn yields per acre from four different fields where different farming methods were used.

To analyse these data in StatsDirect you must first prepare them in four workbook columns appropriately labelled. Alternatively, open the test workbook using the file open function of the file menu. Then select Kruskal-Wallis from the Nonparametric section of the analysis menu. Then select the columns marked "Method 1", "Method 2", "Method 3" and "Method 4" in one selection action.

For this example:

Adjusted for ties: T = 25.62883 P < 0.0001

All pairwise comparisons (Dwass-Steel-Chritchlow-Fligner)

Method 1 and Method 2 , P = 0.1529

Method 1 and Method 3 , P = 0.0782

Method 1 and Method 4 , P = 0.0029

Method 2 and Method 3 , P = 0.0048

Method 2 and Method 4 , P = 0.0044

Method 3 and Method 4 , P = 0.0063

All pairwise comparisons (Conover-Iman)

Method 1 and Method 2, P = 0.0078

Method 1 and Method 3, P = 0.0044

Method 1 and Method 4, P < 0.0001

Method 2 and Method 3, P < 0.0001

Method 2 and Method 4, P = 0.0001

Method 3 and Method 4, P < 0.0001

From the overall T we see a statistically highly significant tendency for at least one group to give higher values than at least one of the others. Subsequent contrasts show a significant separation of all groups with the Conover-Iman method and all but method 1 vs. methods 2 and 3 with the Dwass-Steel-Chritchlow-Fligner method. In most situations, it is best to use only the Dwass-Steel-Chritchlow-Fligner result.

analysis of variance

Copyright © 2000-2016 StatsDirect Limited, all rights reserved. Download a free trial here .

Example of Kruskal-Wallis Test

A health administrator wants to compare the number of unoccupied beds for three hospitals in the same city. The administrator randomly selects 11 different days from the records of each hospital and enters the number of unoccupied beds for each day.

To determine whether the median number of unoccupied beds differs, the administrator uses the Kruskal-Wallis test.

  • Open the sample data, HospitalBeds.MTW .
  • Choose Stat > Nonparametrics > Kruskal-Wallis .
  • In Response , enter Beds .
  • In Factor , enter Hospital .

Interpret the results

The sample medians for the three hospitals are 16.00, 31.00, and 17.00. The average ranks show that hospital 2 differs the most from the average rank for all observations and that this hospital is higher than the overall median.

Both p-values are less than 0.05. The p-values indicate that the median number of unoccupied beds differs for at least one hospital.

Descriptive Statistics

  • Minitab.com
  • License Portal
  • Cookie Settings

You are now leaving support.minitab.com.

Click Continue to proceed to:

Kruskal-Wallis-Test

What is the kruskal-wallis test.

The Kruskal-Wallis test (H-test) is a hypothesis test for multiple independent samples , which is used when the assumptions for a one factor analysis of variance are not met.

Since the Kruskal-Wallis test is a nonparametric test (also called a distribution-free test), the data used do not have to be normally distributed, in contrast to analysis of variance. The only requirement is that the data be ordinal scale .

Kruskal-Wallis-Test vs ANOVA

In the Kruskal-Wallis test, ordinal variables are sufficient, since non-parametric tests do not use the differences of the values, but the ranks (which value is larger, which is smaller). Therefore, the Kruskal-Wallis test is also often called "Kruskal-Wallis one-way ANOVA by ranks test".

Examples for the Kruskal-Wallis test

For the Kruskal-Wallis test, of course, the same examples can be used as for the single factor analysis of variance, but with the addition that the data need not be normally distributed.

Medical example:

For a pharmaceutical company you want to test whether a drug XY has an influence on body weight. For this purpose, the drug is administered to 20 test persons, 20 test persons receive a placebo and 20 test persons receive no drug or placebo.

Social science example:

Do 3 age groups differ in terms of daily television consumption?

Research Question and Hypotheses

The research question for the Kruskal-Wallis test may be: Is there a difference in the central tendency of several independent samples? This question position then results in the null and alternative hypothesis .

Null hypothesis

The independent samples all have the same central tendency and therefore come from the same population.

Alternative hypothesis

At least one of the independent samples does not have the same central tendency as the other samples and therefore originates from a different population.

Median vs. Rank Sums

The Kruskal-Wallis test actually tests for differences in the rank sums of the groups, not directly the medians. The distinction is important and worth clarifying:

The Kruskal-Wallis test ranks all the data from all groups together. Each value is replaced by its rank in the combined dataset. The test then sums these ranks for each group. The null hypothesis of the Kruskal-Wallis test is that the mean rank of the groups is the same. This is a bit different from saying that the medians are equal, although there is a relationship between the two.

While the test is often used as an indicator of differences in medians (especially when the distributions are similar), strictly speaking, it does not directly test the medians. The rationale is that if the distributions are similar, differences in mean ranks imply differences in medians.

In summary, the Kruskal-Wallis test is a non-parametric method for testing whether samples originate from the same distribution. It tests whether the mean ranks are the same across groups, which is often interpreted as a test of differences in medians, especially when the shapes of the distributions are similar across groups.

Assumptions for the Kruskal-Wallis test

To compute a Kruskal-Wallis test, only several independent random samples with at least ordinally scaled characteristics must be available. The variables do not have to satisfy a distribution curve.

Assumptions Kruskal-Wallis-Test

If you have a dependent sample, then you just use the Friedman test .

Calculate Kruskal-Wallis-Test

The calculation of the Kruskal and Wallis rank variance analysis is similar to that of the Mann-Whitney U-Test , which is the nonparametric counterpart of the t-test for independent samples .

Let's say the null hypothesis is true and thus there is no difference between the independent samples. Then high and low ranks are randomly distributed across the samples and should be equally distributed across the groups. Therefore, the probability that a rank is assigned to a group is the same for all groups.

If there is no difference between the groups, the mean value of the ranks should also be the same in all groups. The expected value of the ranks for each group is then given by

Kruskal-Wallis-Test Expected value

Each sample has the same expected value of the ranks, which corresponds to the expected value of the population. Furthermore, the variance of the ranks is needed, the variance can be calculated with the following formula:

Kruskal-Wallis-Test Variance

In the Kruskal-Wallis test, the test variable H is calculated. The H value corresponds to the χ2 value. The H value results from:

Calculate Kruskal-Wallis-Test

The critical H value can be read from the table of critical χ2 values.

Calculation with example data

Let's say you have measured the reaction time of three groups and you want to know if there is a difference between them. To find out, you now use the H-test (Kruskal-Wallis test)

First we assign a rank to each person, then we calculate the rank sum and the mean rank sum.

Calculate Kruskal-Wallis test

We measured reaction time in twelve people, so the number of cases is twelve. The degrees of freedom are given by the number of groups minus one, so we have two degrees of freedom.

Kruskal-Wallis-Test

Now we have calculated all values to calculate the test quantity H.

H test and the test statistic H

After the H-value or the chi-square value has been calculated, the critical chi-square value can be read from the table of critical chi-square values .

Kruskal-Wallis-Test critical H value

At a significance level of 5%, the critical chi-square value is therefore 5.991. This critical value is therefore greater than the calculated chi-square or H value. Thus, the null hypothesis is maintained and there is no difference in reaction time in the three groups.

Post-hoc-Test

The Kruskal-Wallis test can be used to determine whether at least two groups differ from each other. The Kruskal-Wallis test does not provide an answer to the question of which of the groups differed; a post-hoc test is required for this.

For this purpose, the Dunn test is the appropriate nonparametric test for the pairwise multiple comparison.

Dunn-Bonferroni-Tests

To find out which of the pairs differ, the individual groups can be compared pairwise. Dunn's test is used to calculate the p-value of each pair. To compare group A and B, the z-value is calculated using the following formula.

where i is one of the groups and y i = W A - W B is the difference of the mean rank sums. The standard error is given by

Where N is the number of all cases, r is the number of connected ranks, and τ s is the number of cases at that rank.

The calculated p-value can then be adjusted using the Bonferroni correction. The Bonferroni correction is the simplest method to counteract the problem of multiple comparisons. Here, the calculated p-value is multiplied by the number of groups.

If the adjusted p-value in a pairwise comparison is smaller than the significance level (usually 0.05) , the null hypothesis that there is no difference is rejected. So, if the adjusted p-value is smaller than 0.05, it is assumed that the respective two groups differ.

DATAtab automatically outputs the Dunn-Bonferroni test when calculating a Kruskal-Wallis test.

Calculate Kruskal-Wallis test online with DATAtab

Calculate the example directly with DATAtab for free:

Of course you can calculate the Kruskal-Wallis test online with DATAtab. Just go to the statistics calculator, copy your data into the table in the statistics calculator and select the tab "Hypothesis tests". Then you just have to select the variables you want to analyze and uncheck "Parametric test".

Kruskal-Wallis Test Calculator

DATAtab then gives you the results including interpretation in the following form:

Kruskal-Wallis Test Result

Kruskal-Wallis test interpretation

As with any statistical hypothesis test, the calculated p-value is of interest at the end. The question is whether the calculated p-value is smaller or larger than the significance level usually set at 0.05. If the p-value is larger, the null hypothesis is not rejected, otherwise it is rejected.

In the example above, the p-value is 0.779 and thus greater than 0.05. The null hypothesis is thus not rejected and it is assumed that there is no difference between the different groups in terms of reaction time.

Kruskal-Wallis test reporting

How are the results from a Kruskal-Wallis test reported?

A Kruskal-Wallis test was calculated to test whether groups A, B, and C have an effect on reaction time. The Kruskal-Wallis test revealed that there is no significant difference between categories A, B, and C of the independent variable with respect to the dependent variable reaction time, p=0.779. Thus, with the available data, the null hypothesis is not rejected.

Statistics made easy

  • many illustrative examples
  • ideal for exams and theses
  • statistics made easy on 301 pages
  • 4rd revised edition (February 2024)
  • Only 6.99 €

Datatab

"Super simple written"

"It could not be simpler"

"So many helpful examples"

Statistics Calculator

Cite DATAtab: DATAtab Team (2024). DATAtab: Online Statistics Calculator. DATAtab e.U. Graz, Austria. URL https://datatab.net

Six Sigma Study Guide

Six Sigma Study Guide

Study notes and guides for Six Sigma certification tests

Ted Hessing

Kruskal–Wallis Non Parametric Hypothesis Test

Posted by Ted Hessing

Kruskal-Wallis Test

The Kruskal–Wallis Non Parametric Hypothesis Test (1952) is a nonparametric analog of the one-way analysis of variance . It is generally used when the measurement variable does not meet the normality assumptions of one-way ANOVA . It is also a popular nonparametric test to compare outcomes among three or more independent (unmatched) groups.  

Consider the Mann–Whitney test for just two groups instead of the Kruskal–Wallis test. Like the Mann-Whitney test, this test may also evaluate the differences between the groups by estimating the differences in ranks among the groups.

Generally in the ANOVA test, the assumption is that the dependent variable is drawn from a normally distributed population and also assumes that common variance across groups.  But, in Kruskal-Wallis Test, there is no necessity for these assumptions. Therefore, this test is the best option for both continuous as well as ordinal types of data .

Assumptions of the Kruskal-Wallis Test

  • All samples are randomly drawn from their respective population.
  • Independence within each sample.
  • The measurement scale is at least ordinal .
  • Mutual independence among the various samples

Uses of Kruskal-Wallis Non Parametric Hypothesis Test Test

The Kruskal-Wallis test can be used for any industry to understand the dependent variable when it has three or more independent groups. For example, this test helps to understand the student’s performance in exams. While the scores are measured on a scale from 0-100, the scores may vary based on the exam anxiety levels (low, medium, high, and severe -in this case, four different groups) of the students.

Procedure to conduct Kruskal-Wallis Test

  • First pool all the data across the groups.
  • Rank the data from 1 for the smallest value of the dependent variable and the next smallest variable rank 2 and so on… (if any value ties, in that case, it is advised to use mid-point), N being the highest variable.
  • Compute the test statistic
  • Determine critical value from the Chi-Square distribution table
  • Finally, formulate a decision and conclusion

Most of the teams lose track when they exercise the ranks for the original variables. Hence this can make Kruskal–Wallis test a bit less powerful than a one-way ANOVA test.

Calculation of the Kruskal-Wallis Non Parametric Hypothesis Test

The Kruskal–Wallis Non Parametric Hypothesis Test compares medians among k groups (k > 2). The null and alternative hypotheses for the Kruskal-Wallis test are as follows:

  • Null Hypothesis H 0 : Population medians are equal
  • Alternative Hypothesis H 1 : Population medians are not all equal

As explained above, the procedure for the Kruskal-Wallis test pools the observations from the k groups into one combined sample, and then ranks from lowest to highest value (1 to N), where N is the total number of values in all the groups.

The test statistic for the Kruskal Wallis test (mostly denoted as H) is defined as follows: 

Kruskal-Wallis Non Parametric Hypothesis Test

Where T i = rank sum for the ith sample i = 1, 2,…,k

In the Kruskal-Wallis test, the H value will not have any impact on any two groups in which the data values have the same ranks. Either increasing the largest value or decreasing the smallest value will have zero effect on H.  Hence, the extreme outliers (higher and lower sides) will not impact this test.

Example of Kruskal-Wallis Non Parametric Hypothesis Test

In a manufacturing unit, four teams of operators were randomly selected and sent to four different facilities for machining techniques training. After the training, the supervisor conducted the exam and recorded the test scores. At 95% confidence level does the scores are same in all four facilities?

kruskal wallis test null and alternative hypothesis

  • Null Hypothesis H 0 : The distribution of operator scores are same
  • Alternative Hypothesis H 1 : The scores may vary in four facilities

Rank the score in all the facilities

kruskal wallis test null and alternative hypothesis

While for a right-tailed chi-square test with a 95% confidence level, and df =3, the critical χ 2 value is 7.81

Critical values of Chi-Square Distribution

kruskal wallis test null and alternative hypothesis

The calculated χ 2 value is greater than the critical value of χ 2 for a 0.05 significance level. χ 2 calculated >χ 2 critical hence, you reject the null hypotheses

So, there is enough evidence to conclude that difference in test scores exists for four teaching methods at different facilities.

Six Sigma Black Belt Certification Kruskal-Wallis Test Questions:

Question 1: In an organization, management conducted a study comparing Purchase, Marketing, Quality, and Production groups on a measure of leadership skills. Which of the following test would an organization choose?

(A) Mood’Median test (B) Kruskal-Wallis test (C) Mann-Whitney U test (D) Friedman Rank Test

Unlock Additional Members-only Content!

Thank you for being a member.

Answer B: It is independent data and there are more than two conditions, hence Kruskal-Wallis test is the best option.

Question 2: Which of the following nonparametric test use the rank sum?

(A) Runs test (B)  Mood’Median test (C) Sign test (D) Kruskal-Wallis test

Answer D: Kruskal-Wallis test pools the observations from the k groups into one combined sample, and then ranks from lowest to the highest value.

Comments (12)

The Kruskal-Wallis test is not about the equality of medians. It’s about the stochastic dominance. If the distributions within groups are IID, then indeed (and ONLY then) such interpretation holds. Otherwise, the difference may be caused either difference in locations or scales. Kindly please correct it, as people then use the KW or MW(W) tests to detect shift in locations and get totally surprised, how that’s possible to have numerically equal medians and H0 rejected. Both tests fail in general (appropriate sources available over the internet).

Independent and identically distributed.

N should be 16 not 12.

The N in the example is 16. The 12 is a constant of sorts after reduction in this circumstance ( see example here. )

what is the difference between the kruksal walistest and themood median test , Both of them treat more than 2 non parametric variable

Hi Youssef Boudoudouh,

When the data are non normal or the data points are very few to check if the data are normal or not and have more than two populations then we have to use Moods Median or Kruskal-Wallis test , the key difference is Moods median handles the outliers but Kruskal-Wallis test is more powerful than Moods Median.

In the example that is worked out on this page, why is it considered a right-tailed test and not a two-tailed test?

I’m having trouble understanding why the X2 critical is 7.815 and not 9.348.

Critical values for the Kruskal-Wallis test follow χ2 . The χ2 test is one-sided tests because we never have negative values of χ2. For χ2, the sum of the difference of observed and expected squared is divided by the expected ( a proportion), thus chi-square is always a positive number or it may be close to zero on the right side when there is no difference. Thus, this test is always a right-sided one-sided test.

That makes much more sense now. Thank you!

In both the videos that was attached as an example has calculated test statistic less than critical value. In Mann-Whitney test video, hypothesis is rejected whereas in Kruskal test video, outcome is cannot reject hypothesis. Can you please explain?

https://www.youtube.com/watch?v=BT1FKd1Qzjw&ab_channel=EugeneO%27Loughlin

https://www.youtube.com/watch?v=q1D4Di1KWLc&ab_channel=EugeneO%27Loughlin

its reverse in case of only mann whitney..always remember that and author mentioned same in the video.

There are two versions of the Mann-Whitney U test, one for small samples (i.e., when n https://psych.unl.edu/psycrs/handcomp/hcmann.PDF

https://sphweb.bumc.bu.edu/otlt/mph-modules/bs/bs704_nonparametric/bs704_nonparametric4.html

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed .

Insert/edit link

Enter the destination URL

Or link to existing content

LeanScape Logo White

  • Consultancy
  • Online Courses

kruskal wallis test null and alternative hypothesis

SIGN UP TODAY

Kruskal-Wallis Test

  • Lean Training , Lean Wiki , Six Sigma , Tools

A Kruskal-Wallis Test Overview

  • 2 mins to read
  • November 2, 2022
  • By Reagan Pannell

A Kruskal-Wallis Test compares the medians of two or more groups. It is a nonparametric alternative to the ANOVA which means the data sample is not Normally distributed and do not have any obvious outliers.

In statistics, the Kruskal-Wallis test is a non-parametric method used to compare two or more independent groups . This test can be used when the assumptions of normality and homogeneity of variance are not met. The Kruskal-Wallis test is used to determine whether there is a significant difference in the median values of two or more groups. The null hypothesis for this test is that there is no difference in the median values of the groups.

Assumptions behind the Kruskal-Wallis Test

The Kruskal-Wallis test makes the following assumptions:

• The data are ordinal, interval, or ratio

• The dependent variable is continuous

• The independent variable has two or more levels

• The samples are independent

• There are no ties in the ranking of the dependent variable

  • Visit our Consultancy page

GB MASTERCLASS COURSE

Get access to our free gb mastercourse classes, free course previews.

Green Belt Masterclass Course

VISIT OUR FREE COURSE

Ready to level up your career, lean six sigma courses.

LEAN SIX SIGMA TRAINING

Ready to level up your career, get free access to our certified lean six sigma courses.

kruskal wallis test null and alternative hypothesis

Advantages of the Kruskal-Wallis Test

There are several advantages to using the Kruskal-Wallis test over other parametric tests, including:

• The Kruskal-Wallis test does not require the assumptions of normality and homogeneity of variance that other parametric tests do. This makes the Kruskal-Wallis test more robust than other parametric tests.

• The Kruskal- Wallis test can be used with small sample sizes.

Limitations of the Kruskal-Wallis Test

There are also some limitations associated with using the Kruskal-Wallis test, including:

• The Kruskal- Wallis test is not as powerful as other parametric tests, such as ANOVA. As a result, you may need a larger sample size to get an adequate power level when using this test.

How do I calculate a Kruskal-Wallis Test statistic?

The Kruskal-Wallis test statistic is calculated using the following equation:

H = (Σx i – μ)2 / (n – 1)

• H is the Kruskal-Wallis test statistic

• x i is the observed value of the ith observation

• μ is the expected value of the ith observation

• n is the number of observations

What are the null and alternative hypotheses for a Kruskal-Wallis Test?

The null hypothesis for a Kruskal-Wallis Test is that there is no difference in the median values of the groups. The alternative hypothesis is that there is a difference in the median values of the groups.

How do I interpret the results of a Kruskal-Wallis Test

Interpreting the results of a Kruskal-Wallis Test is relatively straightforward. You compare the value of the H statistic to a chi-squared distribution. If the value of the H statistic is greater than the chi-squared distribution, then there is a significant difference in the median values of the groups. If the value of the H statistic is not greater than the chi-squared distribution, then there is no significant difference in the median values of the groups.

Conclusion: 

The Kruskal-Wallis test is a non-parametric method used to compare two or more independent groups. This test can be used when the assumptions of normality and homogeneity of variance are not met and can be useful when working with small sample sizes. However, it is important to keep in mind that this test may not be as powerful as other parametric tests. When deciding whether or not to use this test, consult with a statistician or other knowledgeable individual to ensure that it is the most appropriate method for your data set.

  • Corporate Training
  • Courses for Individuals

Reagan Pannell

Reagan Pannell

Reagan Pannell is a highly accomplished professional with 15 years of experience in building lean management programs for corporate companies. With his expertise in strategy execution, he has established himself as a trusted advisor for numerous organisations seeking to improve their operational efficiency.

Our Training Courses

Fundamentals of lean.

  • Lean Six Sigma White Belt Course

Lean Thinking Business Course

  • Lean Six Sigma Yellow Belt Course
  • Lean Six Sigma Green Belt Course
  • Lean Six Sigma Black Belt Course

Yellow Belt Course

Online Lean Six Sigma Yellow Belt Course

View all courses

Download | learn more, recent articles.

Strategy Execution & Planning

The Difference Between Strategy and Strategic Execution

incremental change - driving continuous improvement

Small Steps, Big Gains: The Case for Incremental Improvement

Lean Consultancy to Drive Change

Maximising Efficiency and Profitability: Exploring the Benefits of Lean Consultancy

Problem-solving to drive change

Empowering Leaders: The Imperative for Problem-Solving Training

the importance of online business management courses

Importance of Free Online Courses in Business Management

kruskal wallis test null and alternative hypothesis

Marrying Online Courses with Real-World Projects

View all articles, green belt course.

kruskal wallis test null and alternative hypothesis

Lean Six Sigma Courses

Lean Thinking Online Course

Lean Six Sigma Black Belt Certification Online

Fundamentals of Lean Free Course

Free Lean Six Sigma Certification | Fundamentals of Lean

Lean Six Sigma Yellow Belt

Lean Six Sigma Yellow Belt Online Certification

Lean Six Sigma Green Belt Course

Lean Six Sigma Green Belt Online Certification

White Belt Lean Six Sigma Course 2

Lean Six Sigma White Belt Online Certification

Other articles.

Facilitation Skills for Project Managers

Facilitation Skills for Project Managers: Learning to Lead Change Management

Priortisation Matrix

What is a Priortisation Matrix

Zebra Crossing

The Power of Lean Thinking to Transform Business Performance

5S Workshop Image

5S Lean Principles | Workplace organisation for maximum productivity

Launch rocket spaceship startup business

The benefits of adopting a continuous improvement approach

Importance of Total Preventative Maintenance

The Importance of Total Preventative Maintenance (TPM)

Operational Excellence failures

10 Reasons Operational Excellence Deployments Fail

Make the decision at the lowest level possible

Delegate Decision Making to the Lowest Level Possible

Affinity Diagram Introduction

What is the Affinity Diagram?

Lean Six Sigma Courses

Accelerate Your Professional Growth with Lean Six Sigma Courses

kruskal wallis test null and alternative hypothesis

16th June 2023 | 5-Bullet Friday Newsletter from Leanscape

Cost of Poor Quality

An Introduction to the Cost of Poor Quality

  • | six sigma , statistics , toolkit , tools

Related Articles

kruskal wallis test null and alternative hypothesis

Harnessing the Wisdom of Lee Kuan Yew for Personal and Professional Growth

Lean Six Sigma Certification in the Middle East

Best Recognized Lean Six Sigma Certification in the Middle East

Data Collection Plan

Factors to consider when developing a data collection plan

Learn to Add Value

04 – Am I Adding Value?

Logistics Lean Case Study Dark

An Operational Excellence Training Program Delivers $4M in Costs Savings

Lean six sigma online courses.

FREE COURSE | YELLOW BELT | GREEN BELT | BLACK BELT | MASTERCLASS | WORKSHOPS

Ready to start your journey into the world of Lean with this free course?

FREE COURSE

LSS White Belt

Looking to get your first recognised Lean Six Sigma Certificate

Lean Thinking

A Lean focused continious improvement certification course

LSS Yellow Belt

Propel your career forward, tackle complex problems and drive change

LSS Green Belt

The ultimate fast-track for future leadership

LSS Black Belt

Become an expert in change management and complex problem-solving.

Subscribe to Newsletter

Keep up to date to the latest insights, courses, training, webinars and more. Join our newsletter today.

Take Our Business Quiz

Ready to test your business improvement knowledge and level up?

IMAGES

  1. Kruskal Wallis Test with Minitab

    kruskal wallis test null and alternative hypothesis

  2. SPSS Kruskal-Wallis Test

    kruskal wallis test null and alternative hypothesis

  3. How to Perform a Kruskal-Wallis Test in SAS

    kruskal wallis test null and alternative hypothesis

  4. How to Perform a Kruskal-Wallis Test in SPSS

    kruskal wallis test null and alternative hypothesis

  5. The Kruskal–Wallis Test

    kruskal wallis test null and alternative hypothesis

  6. Kruskal Wallis Test by Pharmaceutical Biostatistics

    kruskal wallis test null and alternative hypothesis

VIDEO

  1. KRUSKAL WALLIS-TEST

  2. Analyse Kruskal Wallis Data

  3. How to solve Kruskal Wallis H Test

  4. Statistics_Advanced Lecture: The Kruskal-Wallis Test

  5. 8 The Kruskal Wallis H Test

  6. AQA S3 KRUSKAL-WALLIS TESTING

COMMENTS

  1. Kruskal-Wallis Test: Definition, Formula, and Example

    We can use the following steps to perform the Kruskal-Wallis Test: Step 1. State the hypotheses. The null hypothesis (H0): The median knee-pain ratings across the three groups are equal. The alternative hypothesis: (Ha): At least one of the median knee-pain ratings is different from the others. Step 2.

  2. Kruskal Wallis Test Explained

    The Kruskal Wallis test is a nonparametric hypothesis test that compares three or more independent groups. Statisticians also refer to it as one-way ANOVA on ranks. This analysis extends the Mann Whitney U nonparametric test that can compare only two groups. If you analyze data, chances are you're familiar with one-way ANOVA that compares the ...

  3. 12.11: Kruskal-Wallis Test

    Null hypothesis. The null hypothesis of the Kruskal-Wallis test is that the mean ranks of the groups are the same. The expected mean rank depends only on the total number of observations (for \(n\) observations, the expected mean rank in each group is (\(\frac{n+1}{2}\)), so it is not a very useful description of the data; it's not something you would plot on a graph.

  4. Kruskal-Wallis Test

    Steps for Kruskal-Wallis Test; 1. Define Null and Alternative Hypotheses. 2. State Alpha ... Calculate Test Statistic. 6. State Results. 7. State Conclusion. 1. Define Null and Alternative Hypotheses. Figure 2. 2. State Alpha. alpha = 0.05. 3. Calculate Degrees of Freedom ... Do not reject the null hypothesis. 7. State Conclusion. There is no ...

  5. Interpret all statistics for Kruskal-Wallis Test

    The alternative hypothesis states that a population parameter is smaller, larger, or different from the hypothesized value in the null hypothesis. The alternative hypothesis is what you might believe to be true or hope to prove true. ... H is the test statistic for the Kruskal-Wallis test. Under the null hypothesis, the chi-square distribution ...

  6. Getting Started with the Kruskal-Wallis Test

    The alternative hypothesis is that at least one of the groups has a different median, meaning at least one comes from a different distribution than the others. ... We have relatively small sample sizes so we cannot well-determine if the data is normally distributed, so we use the Kruskal-Wallis test. Step 1: Null Hypothesis \(H_0 =\) ...

  7. Kruskal-Wallis test

    The Kruskal-Wallis test by ranks, Kruskal-Wallis test [1] (named after William Kruskal and W. Allen Wallis ), or one-way ANOVA on ranks [1] is a non-parametric method for testing whether samples originate from the same distribution. [2] [3] [4] It is used for comparing two or more independent samples of equal or different sample sizes.

  8. Kruskal-Wallis Test

    The Kruskal-Wallis test is a distribution free alternative for an ANOVA: we basically want to know if 3+ populations have equal means on some variable. However, ... The null hypothesis for a Kruskal-Wallis test is that the mean ranks on some outcome variable are equal across 3+ populations.

  9. Kruskal-Wallis test

    The null hypothesis of the Kruskal-Wallis test is often said to be that the medians of the groups are equal, but this is only true if you assume that the shape of the distribution in each group is the same. If the distributions are different, the Kruskal-Wallis test can reject the null hypothesis even though the medians are the same.

  10. Kruskal‐Wallis Test: Basic

    The nonparametric Kruskal‐Wallis test is an extension of the Wilcoxon‐Mann‐Whitney test. The null hypothesis is that the k populations sampled have the same average (median). The alternative hypothesis is that at least one sample is from a distribution with a different average (median). This test is an alternative to the parametric one ...

  11. Kruskal Wallis Test

    A non-parametric alternative is the Kruskal-Wallis test which is based on ranks rather than the trait values themselves. ... Under the null hypothesis of no genotype-phenotype association, the test statistic follows a chi-squared distribution with 2 degrees of freedom (assuming three genotypes), and a significantly higher value indicates that ...

  12. Kruskal-Wallis test

    Several different formulations of the null hypothesis can be found in the literature, and we do not agree with all of them. Make sure you (also) learn the one that is given in your text book or by your teacher. Alternative hypothesis. The kruskal-wallis test tests the above null hypothesis against the following alternative hypothesis (H 1 or H a):

  13. Kruskal-Wallis Test: Mastering Non-Parametric Analysis

    The Kruskal-Wallis Test is a non-parametric alternative to the one-way ANOVA and is used to determine if there are statistically significant differences between two or more groups of an independent variable on a continuous or ordinal dependent variable. It's particularly noteworthy for its application across multiple groups where the ...

  14. Kruskal-Wallis Test

    However, like most non-parametric tests, the Kruskal-Wallis Test is not as powerful as the ANOVA. Null hypothesis: Null hypothesis assumes that the samples (groups) are from identical populations. Alternative hypothesis: Alternative hypothesis assumes that at least one of the samples (groups) comes from a different population than the others.

  15. Kruskal Wallis H Test: Definition, Examples, Assumptions, SPSS

    The Kruskal Wallis H test uses ranks instead of actual data. The Kruskal Wallis test is the non parametric alternative to the One Way ANOVA. Non parametric means that the test doesn't assume your data comes from a particular distribution. The H test is used when the assumptions for ANOVA aren't met (like the assumption of normality).It is sometimes called the one-way ANOVA on ranks, as the ...

  16. Kruskal-Wallis Test

    The Kruskal-Wallis test is one of the non parametric tests that is used as a generalized form of the Mann Whitney U test. It is used to test the null hypothesis which states that 'k' number of samples has been drawn from the same population or the identical population with the same or identical median. If Sj is the population median for the ...

  17. Kruskal-Wallis Test (Nonparametric One-way ANOVA)

    The null hypothesis of the test is that all k distribution functions are equal. The alternative hypothesis is that at least one of the populations tends to yield larger values than at least one of the other populations. ... An alternative to Kruskal-Wallis is to perform a one way ANOVA on the ranks of the observations. ...

  18. Example of Kruskal-Wallis Test

    Choose Stat > Nonparametrics > Kruskal-Wallis. In Response, enter Beds. In Factor, enter Hospital. Click OK. ... Test Null hypothesis H₀: All medians are equal Alternative hypothesis H₁: At least one median is different Method DF H-Value P-Value Not adjusted for ties 2 7.05 0.029 Adjusted for ties 2 7.05 0.029 ...

  19. Kruskal-Wallis-Test • Simply explained

    What is the Kruskal-Wallis test. The Kruskal-Wallis test (H-test) is a hypothesis test for multiple independent samples, which is used when the assumptions for a one factor analysis of variance are not met. Since the Kruskal-Wallis test is a nonparametric test (also called a distribution-free test), the data used do not have to be normally distributed, in contrast to analysis of variance.

  20. Kruskal-Wallis Non Parametric Hypothesis Test

    Uses of Kruskal-Wallis Non Parametric Hypothesis Test Test. The Kruskal-Wallis test can be used for any industry to understand the dependent variable when it has three or more independent groups. For example, this test helps to understand the student's performance in exams. ... The null and alternative hypotheses for the Kruskal-Wallis test ...

  21. Using Kruskal-Wallis to Detect Seasonality in Time Series

    The Kruskal-Wallis test has a null hypothesis that the mean of each group is the same. The idea for seasonality detection is the following: if the null hypothesis is true when the time series is broken into groups of a certain lag, then the data is probably seasonal for that given lag. However, this strikes me as the opposite of what we want.

  22. What is a Kruskal-Wallis Test? A Kruskal-Wallis Test Overview

    A Kruskal-Wallis Test compares the medians of two or more groups. It is a nonparametric alternative to the ANOVA which means the data sample is not Normally distributed and do not have any obvious outliers.. In statistics, the Kruskal-Wallis test is a non-parametric method used to compare two or more independent groups.This test can be used when the assumptions of normality and homogeneity of ...