裏 RjpWiki

Julia ときどき R, Python によるコンピュータプログラム,コンピュータ・サイエンス,統計学

cor.test の method="kendall" で

2019年06月03日 | ブログラミング

> set.seed(1234567)
> n = 200
> x = rnorm(n)
> y = rnorm(n)

n が50 以上のとき,exact を指定しない場合は正規近似が行われる

> cor.test(x, y, method="kendall")

    Kendall's rank correlation tau

data:  x and y
z = 1.2089, p-value = 0.2267
alternative hypothesis: true tau is not equal to 0
sample estimates:
       tau
0.05748744

exact = FALSE を指定しても問題はない。

> cor.test(x, y, exact=FALSE, method="kendall")

    Kendall's rank correlation tau

data:  x and y
z = 1.2089, p-value = 0.2267
alternative hypothesis: true tau is not equal to 0
sample estimates:
       tau
0.05748744

しかし,exact=TRUE を指定すると,暴走する

> cor.test(x, y, exact=TRUE, method="kendall")

    Kendall's rank correlation tau

data:  x and y
T = 10522, p-value = NA
alternative hypothesis: true tau is not equal to 0
sample estimates:
       tau
0.05748744

プログラムでは,

cor.test(x, y, ...., exact=NULL, ...)

  :

                if (is.null(exact))
                  exact <- (n < 50)

となっているので,exact が 50 以上であるにもかかわらず,exact=TRUE を指定すると歯止めが掛からず,プログラムが想定しない事態が生じる。

まあ,ほとんどの人はそんなことをしないのだけど,実装はまずいというしかない。



コメント    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« brunnermunzel.test の異変(... | トップ | Brunner-Munzel 検定(モンテ... »
最新の画像もっと見る

コメントを投稿

ブログラミング」カテゴリの最新記事