An error in the coin pack or an incorrectly posed problem?

I get some inconsistent results when using the weight argument in a coin pack. In particular, for the kruskal_test and spearman_test functions.

With regular data, everything works fine and is consistent with kruskal.test in the statistics package:

> x <- xtabs( ~gear + vs,data=mtcars) > df <- as.data.frame.table(x) > kruskal_test(gear ~ as.factor(vs),data=mtcars) Asymptotic Kruskal-Wallis Test data: gear by as.factor(vs) (0, 1) chi-squared = 2.4768, df = 1, p-value = 0.1155 > kruskal.test(gear ~ as.factor(vs),data=mtcars) Kruskal-Wallis rank sum test data: gear by as.factor(vs) Kruskal-Wallis chi-squared = 2.4768, df = 1, p-value = 0.1155 

But, when the same data is transmitted to kruskal_test with weighting coefficients of the frequency, I get the wrong result.

 > kruskal_test(as.numeric(df[[1]]) ~ df[[2]], + weights=~as.integer(df[[3]])) Asymptotic Kruskal-Wallis Test data: as.numeric(df[[1]]) by df[[2]] (0, 1) chi-squared = 1.3158, df = 1, p-value = 0.2513 

Is there a problem with the way I configure this function call?

+4
source share
1 answer

That really was a mistake. Torsten replied that the rank conversion does not take weight into account. The following code demonstrates a non-ranking version of the test giving identical results:

 > oneway_test(as.integer(gear) ~ vs, data = df, weights = ~ Freq) Asymptotic 2-Sample Permutation Test data: as.integer(gear) by vs (0, 1) Z = -1.1471, p-value = 0.2513 alternative hypothesis: true mu is not equal to 0 

Hope this will be fixed in the future.

+1
source

All Articles