Kruskal–Wallis one-way analysis of variance

Short description: Non-parametric method for testing whether samples originate from the same distribution

Difference between ANOVA and Kruskal-Wallis test with ranks

The Kruskal–Wallis test by ranks, Kruskal–Wallis H 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. It extends the Mann–Whitney U test, which is used for comparing only two groups. The parametric equivalent of the Kruskal–Wallis test is the one-way analysis of variance (ANOVA).

A significant Kruskal–Wallis test indicates that at least one sample stochastically dominates one other sample. The test does not identify where this stochastic dominance occurs or for how many pairs of groups stochastic dominance obtains. For analyzing the specific sample pairs for stochastic dominance, Dunn's test,[5] pairwise Mann–Whitney tests with Bonferroni correction,[6] or the more powerful but less well known Conover–Iman test[6] are sometimes used.

It is supposed that the treatments significantly affect the response level and then there is an order among the treatments: one tends to give the lowest response, another gives the next lowest response is second, and so forth.[7] Since it is a nonparametric method, the Kruskal–Wallis test does not assume a normal distribution of the residuals, unlike the analogous one-way analysis of variance. If the researcher can make the assumptions of an identically shaped and scaled distribution for all groups, except for any difference in medians, then the null hypothesis is that the medians of all groups are equal, and the alternative hypothesis is that at least one population median of one group is different from the population median of at least one other group. Otherwise, it is impossible to say, whether the rejection of the null hypothesis comes from the shift in locations or group dispersions. This is the same issue that happens also with the Mann-Whitney test.[8][9][10] If the data contains potential outliers, if the population distributions have heavy tails, or if the population distributions are significantly skewed, the Kruskal-Wallis test is more powerful at detecting differences among treatments than ANOVA F-test. On the other hand, if the population distributions are normal or are light-tailed and symmetric, then ANOVA F-test will generally have greater power which is the probability of rejecting the null hypothesis when it indeed should be rejected.[11][12]

## Contents

* 1 Method
* 2 Exact probability tables
* 3 Exact distribution of H
* 4 Example
* 4.1 Test for differences in ozone levels by month
* 5 Implementation
* 6 See also
* 7 References
* 8 Further reading
* 9 External links

## Method

An illustration of how to assign any tied values the average of the rank

1. Rank all data from all groups together; i.e., rank the data from 1 to N ignoring group membership. Assign any tied values the average of the ranks they would have received had they not been tied.
2. The test statistic is given by

H=(N−1)∑i=1gni(r¯i⋅−r¯)2∑i=1g∑j=1ni(rij−r¯)2, where
* N is the total number of observations across all groups
* g is the number of groups
* ni is the number of observations in group i
* rij is the rank (among all observations) of observation j from group i
* r¯i⋅=∑j=1nirijni is the average rank of all observations in group i
* r¯=12(N+1) is the average of all the rij.
3. If the data contain no ties the denominator of the expression for H is exactly (N−1)N(N+1)/12 and r¯=N+12. Thus

H=12N(N+1)∑i=1gni(r¯i⋅−N+12)2=12N(N+1)∑i=1gnir¯i⋅2− 3(N+1)
The last formula only contains the squares of the average ranks.
4. A correction for ties if using the short-cut formula described in the previous point can be made by dividing H by 1−∑i=1G(ti3−ti)N3−N, where G is the number of groupings of different tied ranks, and ti is the number of tied values within group i that are tied at a particular value. This correction usually makes little difference in the value of H unless there are a large number of ties.
5. When performing multiple sample comparisons, the type I error tends to become inflated. Therefore, Bonferroni procedure is used to adjust the significance level, that is, a¯=αk, where a¯ is the adjusted significance level, α is the initial significance level, and k is the number of the contrasts.[13]
6. Finally, the decision to reject or not the null hypothesis is made by comparing H to a critical value Hc obtained from a table or a software for a given significance or alpha level. If H is bigger than Hc, the null hypothesis is rejected. If possible (no ties, sample not too big) one should compare H to the critical value obtained from the exact distribution of H. Otherwise, the distribution of H can be approximated by a chi-squared distribution with g-1 degrees of freedom. If some ni values are small (i.e., less than 5) the exact probability distribution of H can be quite different from this chi-squared distribution. If a table of the chi-squared probability distribution is available, the critical value of chi-squared, χα:g−12, can be found by entering the table at g − 1 degrees of freedom and looking under the desired significance or alpha level.[14]
7. If the statistic is not significant, then there is no evidence of stochastic dominance between the samples. However, if the test is significant then at least one sample stochastically dominates another sample. Therefore, a researcher might use sample contrasts between individual sample pairs, or post hoc tests using Dunn's test, which (1) properly employs the same rankings as the Kruskal–Wallis test, and (2) properly employs the pooled variance implied by the null hypothesis of the Kruskal–Wallis test in order to determine which of the sample pairs are significantly different.[5] When performing multiple sample contrasts or tests, the Type I error rate tends to become inflated, raising concerns about multiple comparisons.

## Exact probability tables

A large amount of computing resources is required to compute exact probabilities for the Kruskal–Wallis test. Existing software only provides exact probabilities for sample sizes of less than about 30 participants. These software programs rely on the asymptotic approximation for larger sample sizes.

Exact probability values for larger sample sizes are available. Spurrier (2003) published exact probability tables for samples as large as 45 participants.[15] Meyer and Seaman (2006) produced exact probability distributions for samples as large as 105 participants.[16]

## Exact distribution of H

Choi et al.[17] made a review of two methods that had been developed to compute the exact distribution of H, proposed a new one, and compared the exact distribution to its chi-squared approximation.

## Example

### Test for differences in ozone levels by month

The following example uses data from Chambers et al.[18] on daily readings of ozone for May 1 to September 30, 1973, in New York City. The data are in the R data set airquality, and the analysis is included in the documentation for the R function `kruskal.test`. Boxplots of ozone values by month are shown in the figure.

The Kruskal-Wallis test finds a significant difference (p = 6.901e-06) indicating that ozone differs among the 5 months.

kruskal.test(Ozone ~ Month, data = airquality)

Kruskal-Wallis rank sum test

data:  Ozone by Month
Kruskal-Wallis chi-squared = 29.267, df = 4, p-value = 6.901e-06

To determine which months differ, post-hoc tests may be performed using a Wilcoxon test for each pair of months, with a Bonferroni (or other) correction for multiple hypothesis testing.

pairwise.wilcox.test(airquality$Ozone, airquality$Month, p.adjust.method = "bonferroni")

Pairwise comparisons using Wilcoxon rank sum test

data:  airquality$Ozone and airquality$Month

5      6      7      8
6 1.0000 -      -      -
7 0.0003 0.1414 -      -
8 0.0012 0.2591 1.0000 -
9 1.0000 1.0000 0.0074 0.0325

P value adjustment method: bonferroni

The post-hoc tests indicate that, after Bonferroni correction for multiple testing, the following differences are significant (adjusted p < 0.05).

* Month 5 vs Months 7 and 8
* Month 9 vs Months 7 and 8

## Implementation

The Kruskal-Wallis test can be implemented in many programming tools and languages.

* Mathematica implements the test as LocationEquivalenceTest.[19]
* MATLAB's Statistics Toolbox has kruskalwallis to compute the p-value for a hypothesis test and display ANOVA table.[20]
* SAS has the "NPAR1WAY" procedure for the test.[21]
* SPSS implements the test with the "Nonparametric Tests" procedure.[22]
* Minitab has the implement in the "Nonparametrics" option.[23]
* In Python's SciPy package, the function scipy.stats.kruskal can return the test result and p-value.[24]
* R base-package has an implement of this test using kruskal.test.[25]
* Java has the implement provided by provided by Apache Commons.[26]
* In Julia, the package HypothesisTests.jl has the function KruskalWallisTest(groups::AbstractVector{<:Real}...) to compute the p-value.[27]

## See also

* One-way ANOVA
* Mann–Whitney U tests
* Bonferroni test
* Friedman test
* Jonckheere's trend test
* Mood's Median ttest

## References

1. ↑ 1.0 1.1 Kruskal–Wallis H Test using SPSS Statistics, Laerd Statistics
2. ↑ Kruskal; Wallis (1952). "Use of ranks in one-criterion variance analysis". Journal of the American Statistical Association 47 (260): 583–621. doi:10.1080/01621459.1952.10483441.
3. ↑ Corder, Gregory W.; Foreman, Dale I. (2009). Nonparametric Statistics for Non-Statisticians. Hoboken: John Wiley & Sons. pp. 99–105. ISBN 9780470454619. https://archive.org/details/nonparametricsta00cord.
4. ↑ Siegel; Castellan (1988). Nonparametric Statistics for the Behavioral Sciences (Second ed.). New York: McGraw–Hill. ISBN 0070573573.
5. ↑ 5.0 5.1 Dunn, Olive Jean (1964). "Multiple comparisons using rank sums". Technometrics 6 (3): 241–252. doi:10.2307/1266041.
6. ↑ 6.0 6.1 Conover, W. Jay; Iman, Ronald L. (1979). ﻿"On multiple-comparisons procedures"﻿ (Report). Los Alamos Scientific Laboratory. http://library.lanl.gov/cgi-bin/getfile?00209046.pdf. Retrieved 2016-10-28.
7. ↑ Lehmann, E. L., & D'Abrera, H. J. (1975). Nonparametrics: Statistical methods based on ranks. Holden-Day.
8. ↑ Divine; Norton; Barón; Juarez-Colunga (2018). "The Wilcoxon–Mann–Whitney Procedure Fails as a Test of Medians". The American Statistician. doi:10.1080/00031305.2017.1305291.
9. ↑ Hart (2001). "Mann-Whitney test is not just a test of medians: differences in spread can be important". BMJ. doi:10.1136/bmj.323.7309.391.
10. ↑ Bruin (2006). "FAQ: Why is the Mann-Whitney significant when the medians are equal?". UCLA: Statistical Consulting Group.
11. ↑ Higgins, James J.; Jeffrey Higgins, James (2004). An introduction to modern nonparametric statistics. Duxbury advanced series. Pacific Gove, CA: Brooks-Cole; Thomson Learning. ISBN 978-0-534-38775-4.
12. ↑ Berger, Paul D.; Maurer, Robert E.; Celli, Giovana B. (2018) (in en). Experimental Design. Cham: Springer International Publishing. doi:10.1007/978-3-319-64583-4. ISBN 978-3-319-64582-7. http://link.springer.com/10.1007/978-3-319-64583-4.
13. ↑ Corder, G.W. & Foreman, D.I. (2010). Nonparametric Statistics for Non-statisticians: A Step-by-Step Approach. Hoboken, NJ: Wiley.
14. ↑ Montgomery, Douglas C.; Runger, George C. (2018). Applied statistics and probability for engineers. EMEA edition (Seventh ed.). Hoboken, NJ: Wiley. ISBN 978-1-119-40036-3.
15. ↑ Spurrier, J. D. (2003). "On the null distribution of the Kruskal–Wallis statistic". Journal of Nonparametric Statistics 15 (6): 685–691. doi:10.1080/10485250310001634719.
16. ↑ Meyer; Seaman (April 2006). "Expanded tables of critical values for the Kruskal–Wallis H statistic". Paper presented at the annual meeting of the American Educational Research Association, San Francisco. Critical value tables and exact probabilities from Meyer and Seaman are available for download at http://faculty.virginia.edu/kruskal-wallis/ . A paper describing their work may also be found there.
17. ↑ Won Choi, Jae Won Lee, Myung-Hoe Huh, and Seung-Ho Kang (2003). "An Algorithm for Computing the Exact Distribution of the Kruskal–Wallis Test". Communications in Statistics - Simulation and Computation (32, number 4): 1029–1040. doi:10.1081/SAC-120023876.
18. ↑ John M. Chambers, William S. Cleveland, Beat Kleiner, and Paul A. Tukey (1983). Graphical Methods for Data Analysis. Belmont, Calif: Wadsworth International Group, Duxbury Press. ISBN 053498052X.
19. ↑ Wolfram Research (2010), LocationEquivalenceTest, Wolfram Language function, https://reference.wolfram.com/language/ref/LocationEquivalenceTest.html.
20. ↑ "Kruskal-Wallis test - MATLAB kruskalwallis". https://www.mathworks.com/help/stats/kruskalwallis.html?searchHighlight=kruskalwallis test&s_tid=srchtitle_support_results_1_kruskalwallis test.
21. ↑ "The NPAR1WAY Procedure". https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_npar1way_syntax01.htm.
22. ↑ Ruben Geert van den Berg. "How to Run a Kruskal-Wallis Test in SPSS?". https://www.spss-tutorials.com/kruskal-wallis-test-in-spss/.
23. ↑ "Overview for Kruskal-Wallis Test". https://support.minitab.com/en-us/minitab/21/help-and-how-to/statistics/nonparametrics/how-to/kruskal-wallis-test/before-you-start/overview/.
24. ↑ "scipy.stats.kruskal — SciPy v1.11.4 Manual". https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.kruskal.html.
25. ↑ "kruskal.test function - RDocumentation". https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/kruskal.test.
26. ↑ "Math – The Commons Math User Guide - Statistics". https://commons.apache.org/proper/commons-math/userguide/stat.html#a1.8_Statistical_tests.
27. ↑ "Nonparametric tests · HypothesisTests.jl" (in en). https://juliastats.org/HypothesisTests.jl/stable/nonparametric/#Kruskal-Wallis-rank-sum-test.

## Further reading

* Daniel, Wayne W. (1990). "Kruskal–Wallis one-way analysis of variance by ranks". Applied Nonparametric Statistics (2nd ed.). Boston: PWS-Kent. pp. 226–234. ISBN 0-534-91976-6. https://books.google.com/books?id=0hPvAAAAMAAJ&pg=PA226.

## External links

* An online version of the test

* v
* t
* e

Statistics

* Outline
* Index

Descriptive statistics

| Continuous data|

| Center|

* Mean
* arithmetic
* geometric
* harmonic
* Median
* Mode

|

Dispersion|

* Variance
* Standard deviation
* Coefficient of variation
* Percentile
* Range
* Interquartile range

Shape|

* Central limit theorem
* Moments
* Skewness
* Kurtosis
* L-moments

Count data|

* Index of dispersion

Summary tables|

* Grouped data
* Frequency distribution
* Contingency table

Dependence|

* Pearson product-moment correlation
* Rank correlation
* Spearman's rho
* Kendall's tau
* Partial correlation
* Scatter plot

Graphics|

* Bar chart
* Biplot
* Box plot
* Control chart
* Correlogram
* Fan chart
* Forest plot
* Histogram
* Pie chart
* Q–Q plot
* Run chart
* Scatter plot
* Stem-and-leaf display
* Radar chart
* Violin plot

Data collection

| Study design|

* Population
* Statistic
* Effect size
* Statistical power
* Optimal design
* Sample size determination
* Replication
* Missing data

|

Survey methodology|

* Sampling
* stratified
* cluster
* Standard error
* Opinion poll
* Questionnaire

Controlled experiments|

* Scientific control
* Randomized experiment
* Randomized controlled trial
* Random assignment
* Blocking
* Interaction
* Factorial experiment

Adaptive Designs|

* Adaptive clinical trial
* Up-and-Down Designs
* Stochastic approximation

Observational Studies|

* Cross-sectional study
* Cohort study
* Natural experiment
* Quasi-experiment

Statistical inference

| Statistical theory|

* Population
* Statistic
* Probability distribution
* Sampling distribution
* Order statistic
* Empirical distribution
* Density estimation
* Statistical model
* Model specification
* Lp space
* Parameter
* location
* scale
* shape
* Parametric family
* Likelihood (monotone)
* Location–scale family
* Exponential family
* Completeness
* Sufficiency
* Statistical functional
* Bootstrap
* U
* V
* Optimal decision
* loss function
* Efficiency
* Statistical distance
* divergence
* Asymptotics
* Robustness

|

Frequentist inference|

| Point estimation|

* Estimating equations
* Maximum likelihood
* Method of moments
* M-estimator
* Minimum distance
* Unbiased estimators
* Mean-unbiased minimum-variance
* Rao–Blackwellization
* Lehmann–Scheffé theorem
* Median unbiased
* Plug-in

|

Interval estimation|

* Confidence interval
* Pivot
* Likelihood interval
* Prediction interval
* Tolerance interval
* Resampling
* Bootstrap
* Jackknife

Testing hypotheses|

* 1- & 2-tails
* Power
* Uniformly most powerful test
* Permutation test
* Randomization test
* Multiple comparisons

Parametric tests|

* Likelihood-ratio
* Score/Lagrange multiplier
* Wald

Specific tests|

* Z-test (normal)
* Student's t-test
* F-test

Goodness of fit|

* Chi-squared
* G-test
* Kolmogorov–Smirnov
* Anderson–Darling
* Lilliefors
* Jarque–Bera
* Normality (Shapiro–Wilk)
* Likelihood-ratio test
* Model selection
* Cross validation
* AIC
* BIC

Rank statistics|

* Sign
* Sample median
* Signed rank (Wilcoxon)
* Hodges–Lehmann estimator
* Rank sum (Mann–Whitney)
* Nonparametric anova
* 1-way (Kruskal–Wallis)
* 2-way (Friedman)
* Ordered alternative (Jonckheere–Terpstra)

Bayesian inference|

* Bayesian probability
* prior
* posterior
* Credible interval
* Bayes factor
* Bayesian estimator
* Maximum posterior estimator

* Correlation
* Regression analysis

| Correlation|

* Pearson product-moment
* Partial correlation
* Confounding variable
* Coefficient of determination

|

Regression analysis|

* Errors and residuals
* Regression validation
* Mixed effects models
* Simultaneous equations models
* Multivariate adaptive regression splines (MARS)

Linear regression|

* Simple linear regression
* Ordinary least squares
* General linear model
* Bayesian regression

Non-standard predictors|

* Nonlinear regression
* Nonparametric
* Semiparametric
* Isotonic
* Robust
* Heteroscedasticity
* Homoscedasticity

Generalized linear model|

* Exponential families
* Logistic (Bernoulli) / Binomial / Poisson regressions

Partition of variance|

* Analysis of variance (ANOVA, anova)
* Analysis of covariance
* Multivariate ANOVA
* Degrees of freedom

Categorical / Multivariate / Time-series / Survival analysis

| Categorical|

* Cohen's kappa
* Contingency table
* Graphical model
* Log-linear model
* McNemar's test

|

Multivariate|

* Regression
* Manova
* Principal components
* Canonical correlation
* Discriminant analysis
* Cluster analysis
* Classification
* Structural equation model
* Factor analysis
* Multivariate distributions
* Elliptical distributions
* Normal

Time-series|

| General|

* Decomposition
* Trend
* Stationarity
* Seasonal adjustment
* Exponential smoothing
* Cointegration
* Structural break
* Granger causality

|

Specific tests|

* Dickey–Fuller
* Johansen
* Q-statistic (Ljung–Box)
* Durbin–Watson
* Breusch–Godfrey

Time domain|

* Autocorrelation (ACF)
* partial (PACF)
* Cross-correlation (XCF)
* ARMA model
* ARIMA model (Box–Jenkins)
* Autoregressive conditional heteroskedasticity (ARCH)
* Vector autoregression (VAR)

Frequency domain|

* Spectral density estimation
* Fourier analysis
* Wavelet
* Whittle likelihood

Survival|

| Survival function|

* Kaplan–Meier estimator (product limit)
* Proportional hazards models
* Accelerated failure time (AFT) model
* First hitting time

|

Hazard function|

* Nelson–Aalen estimator

Test|

* Log-rank test

Applications

| Biostatistics|

* Bioinformatics
* Clinical trials / studies
* Epidemiology
* Medical statistics

|

Engineering statistics|

* Chemometrics
* Methods engineering
* Probabilistic design
* Process / quality control
* Reliability
* System identification

Social statistics|

* Actuarial science
* Census
* Crime statistics
* Demography
* Econometrics
* Jurimetrics
* National accounts
* Official statistics
* Population statistics
* Psychometrics

Spatial statistics|

* Cartography
* Environmental statistics
* Geographic information system
* Geostatistics
* Kriging

* Category
* '
* Commons
* WikiProject

0.00

(0 votes)

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Kruskal–Wallis_one-way_analysis_of_variance&oldid=3906999"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template