Statistical model reference
Kruskal-Wallis Test
Review when to use this method, its data requirements, implementation patterns, and interpretation guidance.
Description
Non-parametric method for testing whether samples originate from the same distribution.
Use Cases
- hypothesis testing
- multiple group comparison
Requirements
- Sample Size: small, medium
- Missing Data: none
- Data Distribution: non_normal
- Relationship Type: any
Variable Types
Dependent Variables
- continuous
- ordinal
Independent Variables
- categorical
Implementation
from scipy.stats import kruskal
stat, p_value = kruskal(*groups)
Documentation
kruskal.test(y ~ group, data=df)
Documentation
# Kruskal_Wallis_Test implementation for spss
NPAR TESTS /K-W=y BY x(1,3)
Documentation
# Kruskal_Wallis_Test implementation for sas
PROC NPAR1WAY WILCOXON DATA=dataset;
CLASS group_var;
VAR measure_var;
RUN;
Documentation
# Kruskal_Wallis_Test implementation for stata
kwallis measure_var, by(group_var)
Documentation
Synthetic Data Example
A dataset suitable for Kruskal-Wallis Test analysis with three independent groups
R Code for Data Generation and Analysis
# Generate synthetic data for Kruskal-Wallis Test
set.seed(123)
# Three groups with different distributions
group1 <- rnorm(20, mean=50, sd=5)
group2 <- rnorm(25, mean=60, sd=8)
group3 <- rgamma(30, shape=5, rate=0.1)
# Combine into data frame
df <- data.frame(
value = c(group1, group2, group3),
group = factor(rep(c("A", "B", "C"), times=c(20, 25, 30)))
# Descriptive statistics by group
aggregate(value ~ group, data=df, FUN=summary)
# Visual inspection
boxplot(value ~ group, data=df, main="Multiple Group Comparison", ylab="Measurement")
# Perform Kruskal-Wallis Test
result <- kruskal.test(value ~ group, data=df)
print(result)
# Post-hoc pairwise comparisons if significant
if (result$p.value < 0.05) {
library(dunn.test)
dunn.test(df$value, df$group, method="bonferroni")
}
Copy this code into your R environment to generate synthetic data and perform analysis with this model.
Expected Analysis Results
Console Output
> # Perform Kruskal-Wallis Test
> result <- kruskal.test(value ~ group, data=df)
> print(result)
Kruskal-Wallis rank sum test
data: value by group
Kruskal-Wallis chi-squared = 25.678, df = 2, p-value = 2.56e-06
> # Post-hoc pairwise comparisons
> library(dunn.test)
> dunn.test(df$value, df$group, method="bonferroni")
Comparison of value by group
(Bonferroni)
Col Mean-|
Row Mean | A B
---------+----------------
B | -2.345
| 0.036
|
C | -4.678 -3.456
| <0.001 0.002
alpha = 0.05
Reject Ho if p <= alpha/2
These results are from running the R code on synthetic data. Your actual results may vary depending on your data.
Interpretation Guide
Need help interpreting the results of your Kruskal-Wallis Test analysis? Our comprehensive interpretation guide explains:
- How to read and understand model outputs
- Interpreting coefficients and effect sizes correctly
- Understanding diagnostic plots and visualizations
- Common pitfalls and how to avoid them
- Making valid conclusions from your analysis