Tomczak and Tomczak's (2014) formula to calculate the eta squared for the Kruskal-Wallis H-test using the following code:
x <- Data$text
H <- unname(kruskal.test(x ~ Data$group)$statistic)
n <- sum(table(x, Data$group))
k <- unname(res$parameter)+1
eta_squared <- (H-k+1)/(n - k)
print(eta_squared)
For reproducibility purposes here is the data:
x <- c(2,2,3,3,3,3,3,4,5,6,6,6,7,7,8,8,9,10,11,11,13,9,10,11,12,19,19,23,26,30,8,14,16,24,26,43,46)
group1 <- rep("group1", 21)
group2 <- rep("group2", 9)
group3 <- rep("group3", 7)
df <- data.frame(group = c(group1, group2, group3), result = c(x))
However, when comparing the findings with the results from the package rstatix, it sometimes gives different results so I am not sure which one I should report. I looked at the source code and I cannot tell what might be the difference. What is the source of the difference?
library(rstatix)
kruskal_effsize(
Data,
x ~ group,
ci = FALSE,
conf.level = 0.95,
ci.type = "perc",
nboot = 1000
)
I'm not getting your results. First revising your initial code to use df:
Now the other computation: