★ R -- ケンドールの一致係数(不具合修正) ★

 394 R -- ケンドールの一致係数  青木繁伸  2002/01/27 (日) 16:09


394. R -- ケンドールの一致係数  青木繁伸  2002/01/27 (日) 16:09
kendall.w <- function(x)
{
    nv <- ncol(x)
    nc <- nrow(x)
    o <- apply(x, 2, rank)
    t <- apply(o, 2, tabulate)
    s1 <- apply(o, 1, sum)
    w <- 12*sum((s1-sum(s1)/nc)^2)/(nv^2*(nc^3-nc)-nv*sum(sapply(1:nv, function(i) {sum(t[[i]]^3-t[[i]])})))
    p <- 1-pchisq((chi <- nv*(nc-1)*w), nc-1)
    result <- c(w, chi, nc-1, p)
    names(result) <- c("Kendall W", "chi sq.", "d.f.", "P value")
    result
}

x <- matrix(c(6,6,2,2,5,4, 1,5,5,4,2,3, 6,3,2,5,4,4), ncol=3)
rownames(x) <- paste("object", 1:6, sep="")
colnames(x) <- paste("rater", 1:3, sep="")

kendall.w(x)

#         rater1 rater2 rater3
# object1      6      1      6
# object2      6      5      3
# object3      2      5      2
# object4      2      4      5
# object5      5      2      4
# object6      4      3      4

# result
# Kendall W   chi sq.      d.f.   P value 
# 0.1221122 1.8316832 5.0000000 0.8719100


● 「統計学関連なんでもあり」の過去ログ--- 017 の目次へジャンプ
● 「統計学関連なんでもあり」の目次へジャンプ
● 直前のページへ戻る