The Kruskal-Wallis H-test is used to determine whether samples originate from the same distribution without assuming normality. It is therefore considered a nonparametric alternative to the one-way ANOVA (Analysis of Variance).
The null hypothesis and alternative hypothesis are defined as: : The populations have the same distribution (medians are equal), and : At least one population differs from the others.
The data is passed to the procedure as a rank-2 array x
, where each column is a group of observations.
All values are ranked across the entire dataset, with tied values assigned the average rank.
The Kruskal-Wallis H-statistic (h
) is computed as:
where:
- is the total number of observations,
- is the number of groups,
- is the number of observations in group , and
- is the sum of ranks in group .
The degrees of freedom are:
and returned as df
.
The p-value (p
) is computed from the chi-squared distribution:
It is computed using the elemental procedure f_dst_chi2_cdf_core
.
The Kruskal-Wallis test assumes that: a) all groups are independent, b) the response variable is ordinal or continuous, c) the group distributions have the same shape, and d) observations are independent both within and between groups.
Impure wrapper procedure for s_tst_kruskalwallis_core
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | x(:,:) |
2D array, each column is a group |
||
real(kind=wp), | intent(out) | :: | h |
Kruskal-Wallis H-statistic |
||
real(kind=wp), | intent(out) | :: | df |
degrees of freedom (k - 1) |
||
real(kind=wp), | intent(out) | :: | p |
p-value from chi-squared distribution |