calc_ac_dist: Calculate Agreement Coefficients (AC) from a distribution

View source: R/calc-ac_dist.R

calc_ac_distR Documentation

Calculate Agreement Coefficients (AC) from a distribution

Description

This function calculates agreement coefficients, including Gwet's AC, Fleiss' kappa, and others, when the input dataset is the distribution of raters by subject and category. It supports various weight types and hypothesis testing options.

Usage

calc_ac_dist(
  distribution,
  weights = "unweighted",
  categ = NULL,
  conf_lev = 0.95,
  N = Inf,
  test_value = 0,
  alternative = "two.sided",
  show_weights = FALSE
)

Arguments

distribution

An nxq matrix / data frame containing the distribution of raters by subject and category. Each cell (i,k) contains the number of raters who classified subject i into category k. An n x q agreement matrix representing the distribution of raters by subjects (n) and category (q) (see calc_agree_mat to convert raw data to distribution).

weights

The type of weighting to apply. One of "unweighted", "quadratic", "linear", "ordinal", "radical", "ratio", "circular", "bipolar", or a custom matrix of weights.

categ

Optional. A vector of category labels. If not provided, the function will extract unique categories from the data.

conf_lev

Confidence level for confidence intervals (default is 0.95).

N

Population size for finite population correction (default is Inf).

test_value

Hypothesis test value (default is 0).

alternative

The type of alternative hypothesis. One of "two.sided", "less", or "greater".

show_weights

Logical whether to show the weights matric with the results. Default is FALSE.

Value

A list containing:

summary

A summary of the subjects, raters, and categories.

ac_table

A table with calculated agreement coefficients.

hypothesis

A string describing the hypothesis test.

Examples

library(tidyverse)
library(irrCAC)

rvary2

ex_dist <- calc_agree_mat(data = rvary2,
                          dplyr::starts_with("rater"),
                          subject_id = subject)

ex_dist

calc_ac_dist(distribution = ex_dist)

# Compare to raw
calc_ac_raw(data = rvary2,
            dplyr::starts_with("rater"))

# Compare to irrCAC package
dplyr::bind_rows(
  irrCAC::pa.coeff.dist(ratings = ex_dist),
  irrCAC::bp.coeff.dist(ratings = ex_dist),
  irrCAC::fleiss.kappa.dist(ratings = ex_dist),
  irrCAC::gwet.ac1.dist(ratings = ex_dist),
  irrCAC::krippen.alpha.dist(ratings = ex_dist)
)

emilelatour/lagree documentation built on Sept. 18, 2024, 5:19 p.m.