Reputation: 1417
How to obtain the exact p-value of a Kruskal-Wallis (e.g. with 3 groups) test in R?
Example of data:
df <- data.frame(
dv = c(0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46,
1.15, 0.88, 0.90, 0.74, 1.21),
group = factor(rep(c("A", "B", "C"), c(5, 5, 5))))
I tried the coin
package using the function kruskal_test
kruskal_test(dv ~ group, data = df,distribution= "exact")
Although an error is produced:
Error in .local(object, ...) : ‘object’ is not a two-sample problem
If I change the "exact"
for "approximate"
it runs, but it is not the exact distribution...
Any thoughts?
Upvotes: 0
Views: 1018
Reputation: 24790
The reason you're getting the error is because you can only exactly calculate the distribtution for a two-sample problem.
From help("kruskal_test")
:
...the distribution can be approximated via Monte Carlo resampling or computed exactly for univariate two-sample problems by setting distribution to "approximate" or "exact" respectively.
Upvotes: 1