calc_ac: Calculate Agreement Coefficients

View source: R/calc-ac_all.R

calc_acR Documentation

Calculate Agreement Coefficients

Description

This function computes various agreement coefficients based on the type of input data provided, including raw data, contingency tables, or distributions. It automatically selects the appropriate calculation method based on whether data, table, or distribution is provided.

Usage

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

Arguments

data

A data frame containing raw ratings data. Only used if table and distribution are NULL.

...

Columns within the data for calculating agreement coefficients. Used only with data.

table

A contingency table of ratings. Only used if data and distribution are NULL.

distribution

A distribution matrix of ratings. Only used if data and table are NULL.

weights

The weighting method for agreement calculation. Default is "unweighted".

categ

A vector of category names, optional.

conf_lev

Confidence level for confidence intervals. Default is 0.95.

N

Population size for finite population correction. Default is Inf.

test_value

The null hypothesis value for hypothesis testing. Default is 0.

alternative

The alternative hypothesis to test: "two.sided", "less", or "greater". Default is "two.sided".

show_weights

Logical, whether to include the weights matrix in the output. Default is FALSE.

Value

A list containing the summary of the input, agreement coefficient table, and hypothesis text. If show_weights is TRUE, the weights matrix is included in the output.

Examples

library(tidyverse)
library(janitor)

#### Example 1 --------------------------------

# two radiologists who classify 85 xeromammograms into one of four categories
# (Altman p. 403)
radiologist

radiologist |>
  janitor::tabyl(radiologist_a, radiologist_b) |>
  janitor::adorn_totals(where = c("row", "col")) |>
  janitor::adorn_title(placement = "combined")

## With a raw data frame ----------------

calc_ac(data = radiologist,
        radiologist_a, radiologist_b)

## With a table ----------------

(tab <- with(radiologist,
             table(radiologist_a, radiologist_b)))

calc_ac(table = tab)

## With a distribution ----------------

ex_dist <- radiologist |>
  mutate(subject = dplyr::row_number()) |>
  calc_agree_mat(dplyr::starts_with("radiologist"),
                 subject_id = subject)

ex_dist

calc_ac(distribution = ex_dist)


#### Example 5 --------------------------------

#  5 raters classify 10 subjects into 1 of 3 rating categories
rvary2


## With a raw data frame ----------------

calc_ac(data = rvary2,
        dplyr::starts_with("rater"))

## With a table ----------------

# Only works for 2x2 tables. This example has more than 2 raters.

## With a distribution ----------------

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

ex_dist

calc_ac(distribution = ex_dist)


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