コーエンのκ係数(Cohen's kappa)と重みづけκ係数(Weighted kappa)の計算をRのvcdパッケージで行う。 irrパッケージは通常の個票データからの計算が想定されているが、vcdパッケージはクロス表からの計算を想定して作られている。
データ
anxiety <- as.table(
rbind(
c(11, 3, 1, 0), c(1, 9, 0, 1),
c(0, 1, 10, 0 ), c(1, 2, 0, 10)
)
)
dimnames(anxiety) <- list(
Doctor1 = c("Normal", "Moderate", "High", "Very high"),
Doctor2 = c("Normal", "Moderate", "High", "Very high")
)
anxiety
anxietyのデータは次のようなもの。順序尺度である。
Doctor2 Doctor1 Normal Moderate High Very high Normal 11 3 1 0 Moderate 1 9 0 1 High 0 1 10 0 Very high 1 2 0 10
vcdパッケージ
Kappaと重みづけKappaの計算
library("vcd")
# Compute kapa
res01 <- Kappa(anxiety, weights = "Equal-Spacing")
res02 <- Kappa(anxiety, weights = "Fleiss-Cohen")
res01
res02
結果。
Equal-Spacing
value ASE z Pr(>|z|)
Unweighted 0.7335 0.07524 9.748 1.873e-22
Weighted 0.7475 0.07910 9.449 3.409e-21
Fleiss-Cohen
value ASE z Pr(>|z|)
Unweighted 0.7335 0.07524 9.748 1.873e-22
Weighted 0.7664 0.09022 8.494 1.989e-17
信頼区間の計算
# Confidence intervals confint(res01, level = 0.95)
結果。
Kappa lwr upr Unweighted 0.5860073 0.8809436 Weighted 0.5924352 0.9025143
サマリ
summary(res01)
結果。
value ASE z Pr(>|z|)
Unweighted 0.7335 0.07524 9.748 1.873e-22
Weighted 0.7475 0.07910 9.449 3.409e-21
Weights:
[,1] [,2] [,3] [,4]
[1,] 1.0000000 0.6666667 0.3333333 0.0000000
[2,] 0.6666667 1.0000000 0.6666667 0.3333333
[3,] 0.3333333 0.6666667 1.0000000 0.6666667
[4,] 0.0000000 0.3333333 0.6666667 1.0000000
重みづけの比較
Equal-Spacing
Weights:
[,1] [,2] [,3] [,4]
[1,] 1.0000000 0.6666667 0.3333333 0.0000000
[2,] 0.6666667 1.0000000 0.6666667 0.3333333
[3,] 0.3333333 0.6666667 1.0000000 0.6666667
[4,] 0.0000000 0.3333333 0.6666667 1.0000000
Fleiss-Cohen
Weights:
[,1] [,2] [,3] [,4]
[1,] 1.0000000 0.8888889 0.5555556 0.0000000
[2,] 0.8888889 1.0000000 0.8888889 0.5555556
[3,] 0.5555556 0.8888889 1.0000000 0.8888889
[4,] 0.0000000 0.5555556 0.8888889 1.0000000
元ネタ。
https://www.datanovia.com/en/lessons/weighted-kappa-in-r-for-two-ordinal-variables/