gpt4 book ai didi

r - 为什么 Cohen 的 kappa 计算在此列联表上的不同包之间失败?

转载 作者:行者123 更新时间:2023-12-03 18:58:50 24 4
gpt4 key购买 nike

我有一个列联表,我想为其计算 Cohens 的 kappa - 一致性水平。我尝试使用三种不同的软件包,但似乎都在某种程度上失败了。包裹e1071有一个专门用于列联表的功能,但这似乎也失败了。下面是可重现的代码。您将需要安装软件包 concord , e1071 , 和 irr .

# Recreate my contingency table, output with dput
conf.mat<-structure(c(810531L, 289024L, 164757L, 114316L), .Dim = c(2L,
2L), .Dimnames = structure(list(landsat_2000_bin = c("0", "1"
), MOD12_2000_binForest = c("0", "1")), .Names = c("landsat_2000_bin",
"MOD12_2000_binForest")), class = "table")

library(concord)
cohen.kappa(conf.mat)
library(e1071)
classAgreement(conf.mat, match.names=TRUE)
library(irr)
kappa2(conf.mat)

我从运行中得到的输出是:
> cohen.kappa(conf.mat)
Kappa test for nominally classified data
4 categories - 2 methods
kappa (Cohen) = 0 , Z = NaN , p = NaN
kappa (Siegel) = -0.333333 , Z = -0.816497 , p = 0.792892
kappa (2*PA-1) = -1

> classAgreement(conf.mat, match.names=TRUE)
$diag
[1] 0.6708459
$kappa
[1] NA
$rand
[1] 0.5583764
$crand
[1] 0.0594124
Warning message:
In ni[lev] * nj[lev] : NAs produced by integer overflow

> kappa2(conf.mat)
Cohen's Kappa for 2 Raters (Weights: unweighted)
Subjects = 2
Raters = 2
Kappa = 0
z = NaN
p-value = NaN

谁能建议为什么这些可能会失败?我有一个很大的数据集,但由于这个表很简单,我认为这不会导致这样的问题。

最佳答案

在第一个函数中,cohen.kappa ,您需要指定您使用的是计数数据,而不仅仅是 n*m n的矩阵主题和 m评分者。

# cohen.kappa(conf.mat,'count')
cohen.kappa(conf.mat,'count')

第二个函数要复杂得多。出于某种原因,您的 matrix满满的 integer而不是 numeric . integer无法存储非常大的数字。因此,当您将两个大数字相乘时,它会失败。例如:
i=975288 
j=1099555
class(i)
# [1] "numeric"
i*j
# 1.072383e+12
as.integer(i)*as.integer(j)
# [1] NA
# Warning message:
# In as.integer(i) * as.integer(j) : NAs produced by integer overflow

因此,您需要将矩阵转换为整数。
# classAgreement(conf.mat)
classAgreement(matrix(as.numeric(conf.mat),nrow=2))

最后看看 ?kappa2 的文档.它需要一个 n*m矩阵如上所述。它不适用于您的(高效)数据结构。

关于r - 为什么 Cohen 的 kappa 计算在此列联表上的不同包之间失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11881819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com