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:

Drug 1 Drug 2 Drug 3
78 71 57
65 66 88
63 56 58
44 40 78
50 55 65
78 31 61
70 45 62
61 66 44
50 47 48
44 42 77

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 (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. 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:

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

10 Replies to “Kruskal-Wallis Test: Definition, Formula, and Example”

  1. That is not an accurate statement of the null hypothesis. The null hypothesis for the Kruskal-Wallis Test is that the distributions are the same, v the alternative that they are not. It is not specifically a test of equal medians.

  2. By manual calculation H value is not coming. Values applied to test statistic value
    Rj2 value is coming as huge value since the ranking is done in 1 to 100 scale. Kindly through light on this

  3. Question: If I have Likert scale data that in non-numeric, (e.g. Significantly, Moderately, Somewhat, Not at all) can I assign a numeric value to each response? Is there any variance assumption in the test?

    Thanks for the help 🙂

    1. Hi Izzy…Yes, you can assign numeric values to non-numeric Likert scale responses, but there are considerations depending on how you plan to analyze the data. Here’s a detailed explanation:

      —

      ### Assigning Numeric Values to Likert Responses

      For your responses:
      – **Significantly**
      – **Moderately**
      – **Somewhat**
      – **Not at all**

      You can assign numeric values based on the order of intensity. For example:
      – Significantly = 4
      – Moderately = 3
      – Somewhat = 2
      – Not at all = 1

      This assignment is common when converting Likert scale data into a format suitable for statistical analysis.

      —

      ### Assumptions to Consider
      When you assign numeric values, it’s crucial to consider whether your data is:
      1. **Ordinal:** The numeric values represent a rank order, but the intervals between categories may not be equal.
      – Example: The difference between “Significantly” and “Moderately” might not be the same as the difference between “Moderately” and “Somewhat.”

      2. **Interval:** If you assume equal spacing between categories (e.g., the difference between any two consecutive responses is the same), you can analyze the data as interval data.

      —

      ### Variance Assumption in Statistical Tests
      The variance assumption depends on the test you plan to use:

      1. **Non-Parametric Tests:**
      – Use these if you assume the data is ordinal.
      – Examples: Kruskal-Wallis, Mann-Whitney U test, or Spearman’s rank correlation.
      – **Variance assumption:** Non-parametric tests do not assume equal variances.

      2. **Parametric Tests:**
      – Use these if you treat the data as interval.
      – Examples: t-tests, ANOVA, or Pearson correlation.
      – **Variance assumption:** Many parametric tests (e.g., ANOVA, t-test) assume homogeneity of variance across groups (e.g., tested using Levene’s Test).

      —

      ### Recommendation
      1. **Analyze Ordinal Data Cautiously:** If you’re unsure whether the intervals between categories are equal, treat the data as ordinal and use non-parametric methods.
      2. **Check Variance Assumptions:** If using parametric methods, ensure the homogeneity of variance assumption holds by performing tests like Levene’s or Bartlett’s test.
      3. **Consider Data Transformation:** If the categories represent meaningful intervals, you may treat them as interval data. However, this assumption must be justified.

      —

  4. Hello, I want to conduct a mixed MANOVA (with one between-subjects and one within-subjects factor) but the assumption of multivariate normality was violated and my data was not normally distributed. I know that MANOVA can be robust to violations when the sample is over 30 in each group, however, I have only 20 participants in each group. Should I use the Kruskal-Wallis test as a non-parametric equivalent or is there another way to deal with this?

    1. Hi Rachel…Since your data violates the assumption of multivariate normality and you have small sample sizes (n = 20 per group), using MANOVA may not be appropriate due to its sensitivity to normality violations in small samples. However, Kruskal-Wallis is not a direct non-parametric equivalent of MANOVA because it is designed for univariate comparisons rather than multivariate.

      Here are a few alternative approaches you can consider:

      ### 1. **Rank-Based MANOVA (Non-Parametric MANOVA)**
      – A better alternative to MANOVA when normality is violated is **non-parametric MANOVA (PERMANOVA)**. You can use **rank transformation** before conducting MANOVA.
      – You can implement **PERMANOVA (Permutation MANOVA)**, which is based on resampling techniques rather than normality assumptions.
      – In R, you can use the **”vegan”** package (`adonis()` function) for PERMANOVA.

      ### 2. **Separate Non-Parametric Tests for Each Dependent Variable**
      – Instead of using MANOVA, you could conduct **separate non-parametric tests** for each dependent variable:
      – **Kruskal-Wallis test** for between-subjects comparisons.
      – **Wilcoxon signed-rank test** (for within-subjects factor).
      – However, this approach does not account for correlations between dependent variables, which is a major drawback compared to MANOVA.

      ### 3. **Generalized Estimating Equations (GEE) or Robust ANOVA**
      – If your data is non-normal but follows an identifiable distribution (e.g., Poisson, Gamma), using **Generalized Estimating Equations (GEE)** or a **robust ANOVA model** (like a mixed-effects model with robust estimators) might be a better solution.
      – This approach is useful if you have repeated measures and want to model within-subject dependencies.

      ### 4. **Bootstrapping MANOVA**
      – Another option is **bootstrapping**, where you resample your data multiple times to estimate the distribution of the test statistics.
      – Bootstrapped MANOVA can be performed in R using the **”MANOVA.RM”** package.

      ### Recommended Approach:
      – **If you want a multivariate approach:** Use **Rank-Based MANOVA (PERMANOVA)** or **Bootstrapped MANOVA**.
      – **If you are okay with analyzing variables separately:** Use **Kruskal-Wallis for between-subjects** and **Wilcoxon signed-rank for within-subjects**.
      – **If you can assume an alternative distribution:** Consider **Generalized Estimating Equations (GEE) or Mixed Models with robust estimation**.

Leave a Reply

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