I am slightly puzzled by the behaviour of the weighted kappa in the R psych package. I have data with five classes (1,2,3,4,5) and three annotators. It seems that whenever a particular class (say, 1) was only used by one annotator (resulting in a null value along the diagonal of the agreement matrix for that class), psych complains:
library(psych);
df2 <- read.table('classes/WB/mcrae.quants.features.time.numeric', sep='\t');
cohen.weights <- matrix(c(0,5,35,95,100,5,0,30,90,95,35,5,0,60,65,95,90,60,0,5,100,95,65,5,0),ncol=5);
cohen.kappa(df2,cohen.weights)
Error in `rownames<-`(`*tmp*`, value = c("2", "3", "4", "5")) :
length of 'dimnames' [1] not equal to array extent
Calls: cohen.kappa -> cohen.kappa1 -> rownames<-
Execution halted
My data looks like this:
5 3 3
5 3 3
5 4 3
5 4 3
3 3 3
5 4 4
3 4 4
3 3 3
2 3 2
...
1 3 4
Can someone tell me whether I'm doing anything wrong? The code above works when all classes are used by at least two annotators. Thanks!
Output of dput(df2):
structure(list(V1 = c(5L, 5L, 5L, 5L, 3L, 5L, 3L, 3L, 2L, 4L,
3L, 4L, 3L, 4L, 5L, 3L, 5L, 5L, 3L, 5L, 3L, 5L, 3L, 5L, 4L, 5L,
5L, 5L, 5L, 3L, 4L, 4L, 5L, 5L, 5L, 3L, 3L, 5L, 5L, 5L, 5L, 3L,
3L, 5L, 5L, 3L, 4L, 3L, 4L, 3L, 5L, 5L, 4L, 3L, 5L, 5L, 5L, 5L,
5L, 3L, 3L, 5L, 5L, 5L, 5L, 5L, 4L, 3L, 5L, 5L, 5L, 5L, 4L, 4L,
4L, 5L, 4L, 4L, 3L, 3L, 5L, 3L, 4L, 3L, 5L, 1L), V2 = c(3L, 3L,
4L, 4L, 3L, 4L, 4L, 3L, 3L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 4L, 4L,
3L, 5L, 4L, 4L, 5L, 5L, 3L, 3L, 3L, 4L, 4L, 3L, 4L, 3L, 3L, 4L,
4L, 3L, 4L, 5L, 4L, 4L, 3L, 4L, 3L, 3L, 4L, 3L, 4L, 3L, 4L, 4L,
5L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