Kruskal-Wallis H Test Calculator

Enter numerical data for each group, separated by commas, spaces, or new lines. The calculator also provides descriptive statistics and performs a Shapiro-Wilk test for normality on each group.

How to Use This Calculator

Follow these simple steps to perform a Kruskal-Wallis test on your data:

1Enter Your Data

For each group, enter numerical data in the text area provided. You can separate values using commas, spaces, or new lines. For example:

12, 15, 18, 14 or 12 15 18 14

2Name Your Groups

Give each group a meaningful name (e.g., "Treatment A", "Control Group") to make your results easier to interpret.

3Add More Groups (Optional)

Click the "Add Another Group" button if you need to compare more than three groups. The calculator supports any number of groups.

4Calculate Results

Click the "Calculate" button to run the analysis. The calculator will display:

5Interpret Your Results

Look at the p-value in the Kruskal-Wallis test results:

💡 Tip: Use the Shapiro-Wilk test results to confirm that the Kruskal-Wallis test is appropriate for your data. If your data shows significant departures from normality (p < 0.05), the Kruskal-Wallis test is the right choice instead of a parametric ANOVA.

6Export Your Report (Optional)

Click "Export to PDF" to save a complete report including all statistics, test results, and visualizations.

Understanding the Kruskal-Wallis H Test

The Kruskal-Wallis H test is a non-parametric (distribution-free) test 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 is considered the non-parametric alternative to the one-way ANOVA and is an extension of the Mann-Whitney U test to allow the comparison of more than two independent groups.

When to Use the Kruskal-Wallis Test

You should use the Kruskal-Wallis test in the following situations:

Assumptions

The Kruskal-Wallis test has a few key assumptions:

  1. Independence of Observations: The observations in each group (and between groups) must be independent of each other.
  2. Ordinal or Continuous Data: The dependent variable should be measured on at least an ordinal scale.
  3. Similar Distribution Shape: For the test to be interpreted as a comparison of medians, the distribution of the data for each group must have a similar shape. The included density plot can help visually assess this.

The Formula

The test statistic, H, is calculated using the following formula:

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

Where:

If there are tied ranks in the data, a correction factor is applied to the H value.


Examples with Step-by-Step Solutions

Example 1: Comparing Teaching Methods

An educator wants to compare the effectiveness of three different teaching methods on student exam scores. The scores for students in each method are recorded.

Step 1: State the Hypotheses

Null Hypothesis (\(H_0\)): The median exam scores are the same for all three teaching methods.

Alternative Hypothesis (\(H_1\)): At least one teaching method has a different median exam score.

Step 2: Combine and Rank the Data

Combine all data points and assign a rank to each one from lowest to highest.

ScoreGroupRank
72C1
74C2
75A3
78A4
79C5
81C6
82A7
85A8
86B9
88B10
90B11
92B12
94B13

Step 3: Calculate the Sum of Ranks for Each Group

Sum the ranks for each teaching method.

Here, \(n_1=4\), \(n_2=5\), \(n_3=4\), and the total N = 13.

Step 4: Calculate the H-Statistic

$$ H = \left[ \frac{12}{13(13+1)} \left( \frac{22^2}{4} + \frac{55^2}{5} + \frac{14^2}{4} \right) \right] - 3(13+1) $$$$ H = \left[ \frac{12}{182} (121 + 605 + 49) \right] - 42 $$$$ H = 51.1 - 42 = 9.1 $$

Step 5: Determine the p-value and Conclude

The degrees of freedom (df) = k - 1 = 3 - 1 = 2. We compare our H value (9.1) to a chi-square distribution with 2 df. The critical value for α = 0.05 is 5.99. Since 9.1 > 5.99, we reject the null hypothesis. The calculated p-value for H=9.1 is approximately 0.0106.

Conclusion: There is a statistically significant difference in exam scores among the three teaching methods.


Example 2: Fertilizer Impact on Crop Yield

A farmer tests three different fertilizers to see if they have a different effect on crop yield (in bushels per acre). The yields are not normally distributed.

Step 4: Apply Correction for Ties

The correction factor (C) is: \( C = 1 - \frac{\sum(t^3 - t)}{N^3 - N} \), where 't' is the number of tied observations in a group of ties. We have one tie group of 2 values (t=2).

$$ C = 1 - \frac{(2^3 - 2)}{13^3 - 13} \approx 0.99725 $$

The corrected H is \(H_{corrected} = H / C \):

$$ H_{corrected} = \frac{8.64}{0.99725} \approx 8.66 $$

Step 5: Conclude

With df=2, H=8.66 is still greater than the critical value of 5.99. The p-value is approximately 0.0132. We reject the null hypothesis and conclude there is a significant difference in crop yield among the fertilizers.

How to Do This in RStudio

R's built-in kruskal.test() function handles ties automatically and matches this calculator's corrected H-statistic:

        
        methodA <- c(78, 82, 85, 75)
        methodB <- c(88, 92, 90, 86, 94)
        methodC <- c(72, 79, 81, 74)
        
        kruskal.test(list(methodA, methodB, methodC))
        
        # For the normality check (Shapiro-Wilk) on each group:
        shapiro.test(methodA)
        shapiro.test(methodB)
        shapiro.test(methodC)
        
        

How to Do This in SPSS

Analyze → Nonparametric Tests → Legacy Dialogs → K Independent Samples. Move your dependent (continuous) variable into the Test Variable List, and your grouping variable into the Grouping Variable box, then define the range of group codes. Make sure Kruskal-Wallis H is checked under Test Type. For the normality check, use Analyze → Descriptive Statistics → Explore, and request the Shapiro-Wilk test under Plots.

How to Do This in JASP

ANOVA → Kruskal-Wallis. Drag your dependent variable into the Dependent Variable box and your grouping variable into Fixed Factors. JASP outputs the H-statistic, df, and p-value directly, with an option to enable pairwise comparisons (Dunn's test) for post-hoc analysis. Normality per group can be checked under ANOVA → One-Way ANOVA → Assumption Checks → Normality, using Shapiro-Wilk.

Related Statistical Calculators