Rのクラスカル=ウォリス検定でエラー”all group levels must be finite”

正規分布ではない多群について検定するために krsukal-wallis test を行ったところ、表題のエラーが出た

> kruskal.test(value~label)
Error in kruskal.test.default(c(0.55, 0.62, 0.58, 0.51, 0.5, 0.6, 0.58,  : 
  all group levels must be finite

ここで公式ドキュメントを眺めてみると

kruskal.test(x, g, …)
x : a numeric vector of data values, or a list of numeric data vectors. Non-numeric elements of a list will be coerced, with a warning.
g : a vector or factor object giving the group for the corresponding elements of x. Ignored with a warning if x is a list.

https://www.rdocumentation.org/packages/stats/versions/3.6.1/topics/kruskal.test

どうやら factor を引数に取るらしい

> value <- as.factor(value)
> label <- as.factor(label)
> kruskal.test(value~label) Kruskal-Wallis rank sum test data: value by label Kruskal-Wallis chi-squared = 8.1137, df = 3, p-value = 0.04372

これで解決

参考

kruskal.test shows "All group levels must be finite" error. What is the problem?
I have a data set having a value and a group, e.g., Val Grp 123 "A" 231 "A" 132 "A" 234 "A" 445 "B" 345 "B" 235 "B" 345 "B" (The original dataset would be too...

コメント

タイトルとURLをコピーしました