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?
source share