My textbook states the following formula to calculate the H-value of the Kruskal-Wallis test (without tie ranks):
Let's use this formula to compute H for a really simple example dataset:
- group 1 measurements: 10, 20
- group 2 measurements: 30, 40
In the give example dataset the population size $N = 4$. The population consists of two groups each having two members ($n_i = 2$ for all $i$). When we rank the data we see, that group 1 contains rank 1 and 2, while group 2 contains rank 3 and 4. The squared sums of ranks for the groups are therefore $R_1^2=(1+2)^2=9$ and $R_2^2=(3+4)^2=49$. If we fill this into the formula we and up with
$H = \frac{12}{4*3}*(\frac{9}{2}+\frac{49}{2})-3*5 = 14$
So H should be 14. However, if I use the Kruskal-Wallis implementation of scipy I get a H-value of about 2.4.
from scipy.stats import kruskal
res = kruskal(np.array([10, 20]), np.array([30, 40]))
print(res)
What am I doing wrong in my computation?