formula で,~ の右に来る変数は factor でないといけない。よくわからないエラーメッセージでしばらく悩んだ。
> library(coin)
> d <- data.frame(x=c(3,1,2,4,3,2,5,4,3,4,5),
+ g=c(1,1,1,1,1,2,2,2,2,2,2))
> wilcox_test(x~g, data=d)
以下にエラー check(itp) : ‘object’ does not represent a two sample problem
> wilcox_test(x~g, data=d, distribution="exact")
以下にエラー check(itp) : ‘object’ does not represent a two sample problem
> d$g <- factor(d$g)
> wilcox_test(x~g, data=d)
Asymptotic Wilcoxon Mann-Whitney Rank Sum Test
data: x by g (1, 2)
Z = -1.5884, p-value = 0.1122
alternative hypothesis: true mu is not equal to 0
> wilcox_test(x~g, data=d, distribution="exact")
Exact Wilcoxon Mann-Whitney Rank Sum Test
data: x by g (1, 2)
Z = -1.5884, p-value = 0.1515
alternative hypothesis: true mu is not equal to 0
> wilcox.test(x~g, data=d)
Wilcoxon rank sum test with continuity correction
data: x by g
W = 6.5, p-value = 0.1349
alternative hypothesis: true location shift is not equal to 0
警告メッセージ:
In wilcox.test.default(x = c(3, 1, 2, 4, 3), y = c(2, 5, 4, 3, 4, :
タイがあるため、正確な p 値を計算することができません