Skip to content
Snippets Groups Projects
Commit 31b33ea4 authored by Matthias Kuhn's avatar Matthias Kuhn
Browse files

code simplification, comment

parent 4ad66f76
Branches
Tags
No related merge requests found
......@@ -105,6 +105,7 @@ kappa2 <- function (ratings, robust = FALSE, ratingScale = NULL) {
#' Setting `variant='conger'` gives the variant of Conger (1980) that reduces to Cohen's kappa when m=2 raters.
#' It assumes identical raters for the different subjects (two-way ANOVA setting). The chance agreement is based on the category proportions of each rater separately.
#' Typically, the Conger variant yields slightly higher values than Fleiss kappa.
#' Variant robust assumes a chance agreement of two raters to be simply 1/q, where q is the number of categories (uniform model).
#'
#' @param ratings matrix (dimension nxr), containing the ratings as subjects by raters
#' @param variant Which variant of kappa? Default is Fleiss (1971). Other options are Conger (1980) or robust variant.
......@@ -155,9 +156,11 @@ kappam.fleiss <- function (ratings, variant = c("fleiss", "conger", "robust", "u
sj_cnt_tab <- apply(ratings, 1,
FUN = function(ro) tabulate(factor(ro, levels = ratingScale), nbins = nCat))
cat_cnt <- rowSums(sj_cnt_tab)
cat_ssq <- crossprod(cat_cnt)[1]
cat_ssq <- crossprod(cat_cnt)[1L]
# sum((colSums(sj_cnt_tab^2) - nr) / (nr * (nr - 1) * nSj))
agreeP <- mean((colSums(sj_cnt_tab^2) - nr)) / (nr * (nr - 1))
agreeP <- sum((colSums(sj_cnt_tab^2) - nr) / (nr * (nr - 1) * nSj))
switch(variant,
fleiss = {
method <- "Fleiss' Kappa for m Raters"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment