# Agreement between raters (Cohen's or Fleiss' kappa)

`stats_agreement_kappa` · Runs: On the server · Level: Checked against a reference: exact rational arithmetic and mpmath at 50 digits on the transcribed formulas, and statsmodels 0.15.0 cohens\_kappa and fleiss\_kappa run as a black box

Works out Cohen's kappa, unweighted or weighted, for two raters, or Fleiss' kappa for two or more.

Research and education software; not medical advice, and not for diagnosis or treatment decisions. It computes from the inputs it receives. It does not check the person's data, design or sample.

[Catalogue](https://www.drybench.com/mcp/catalogue) / [Statistics](https://www.drybench.com/mcp/catalogue/statistics)

[Ask your assistant](https://www.drybench.com/mcp/connect)

```cite
Agreement between raters (Cohen's or Fleiss' kappa) (stats_agreement_kappa), Drybench MCP server 1.0.0; stats-agreement-kappa@1.1.1 (Checked against a reference); https://www.drybench.com/mcp/tools/stats-agreement-kappa
```

## What it is

Returns Cohen's kappa, unweighted or weighted, for two raters, or Fleiss' kappa for two or more. Use when raters put each subject in one stated category, for agreement beyond chance. Not for continuous measurements: use \`relate\_method\_comparison\`; for association: use \`stats\_contingency\_table\`; against a reference standard: use \`stats\_diagnostic\_accuracy\`. Method, categories, weights and replicates are required with no default, and level for Cohen's kappa; Fleiss' kappa is a point estimate only. Kappa depends on prevalence and the number of categories; no verbal scale or threshold is applied.

Field: [Statistics and design](https://www.drybench.com/mcp/catalogue/statistics).

## What it does

**You give**

- `method` (required): 'cohen' (exactly two raters, every subject rated by both) or 'fleiss' (the same number of raters, two or more, on every subject; raters need not be the same people).
- `input` (required): 'counts' (a table of counts) or 'labels' (one row per subject, one category label per rater).
- `categories` (required): Every category a rater could choose, each once, including unused ones; never inferred from the data. For linear or quadratic weights, in order, lowest first.
- `weights` (required): 'unweighted' (any disagreement counts fully), 'linear' or 'quadratic' (partial credit by distance in the category order; this declares the categories ordered and evenly spaced). Cohen only; Fleiss takes 'unweighted'. Required, no default.
- `replicates` (required): What one subject is: 'independent' (independent subjects, for example one biopsy per patient; opens the SE and interval), 'technical' (not independent, for example several lesions, eyes or wells from one source) or 'unspecified'. Required: never inferred.
- `counts`: Counts only. Cohen: a k × k table, rows the first rater's category and columns the second's, both in the order of categories. Fleiss: one row per subject, the number of raters who chose each category, in the order of categories; every row sums to the same number of raters. Cohen: the table totals 2 to 10,000 subjects. Fleiss: 2 to 3,000 rows and at most 6,000 cells (rows × categories); each row sums to 2 to 100 raters. Optional.

and 2 more, listed below

No request is recorded for this tool.

**Limits**

- Research statistics and experimental-design arithmetic on the data, margins, prevalence and settings you supply.
- Not for diagnosis or treatment decisions and not a regulatory analysis.
- It does not choose a design, a margin, a cut-off or a sample size for you.
- Categories you list, 2 to 20, each name at most 60 characters of printable text.
- Subjects: 2 to 10,000 in a Cohen table of counts (the table total), 2 to 5,000 as rows of labels and 2 to 3,000 as rows of Fleiss counts; over one form's cap, send the other (for Fleiss, subjects × raters at most 10,000 as labels, subjects × categories at most 6,000 as counts); not for corpora above 10,000 subjects.
- Cohen's kappa: exactly two raters on every subject, unweighted or with linear or quadratic weights over ordered, evenly spaced categories.
- Fleiss' kappa: raters 2 to 100, the same number on every subject, unweighted, point estimate only: no SE, interval or test.
- With two raters, Fleiss' kappa is not Cohen's kappa: its chance agreement uses the pooled category proportions.
- Labels: at most 10,000 labels in all (subjects × raters) and 60,000 bytes of label text as written in JSON.
- Fleiss counts: at most 6,000 cells (subjects × categories).
- SE, interval, z and p for Cohen's kappa only, with at least 30 subjects you declare independent; they are large-sample (Wald) approximations, and the test is against kappa = 0.
- Raters are assumed to rate without seeing each other's ratings.
- No missing ratings, per-category kappa, Krippendorff's alpha, ICC, weighted Fleiss, Light's kappa or PABAK.
- Kappa is never compared with a threshold.
- Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.

**It will not answer when**

- a label that is not in categories.
- subjects rated by different numbers of raters (labels rows of different lengths, or Fleiss counts rows with different sums).
- a counts row without one entry per category, or a Cohen table that is not k × k.
- a category listed twice.

### Every input, with its units

8 inputs

- `method` (required): 'cohen' (exactly two raters, every subject rated by both) or 'fleiss' (the same number of raters, two or more, on every subject; raters need not be the same people).
- `input` (required): 'counts' (a table of counts) or 'labels' (one row per subject, one category label per rater).
- `categories` (required): Every category a rater could choose, each once, including unused ones; never inferred from the data. For linear or quadratic weights, in order, lowest first.
- `weights` (required): 'unweighted' (any disagreement counts fully), 'linear' or 'quadratic' (partial credit by distance in the category order; this declares the categories ordered and evenly spaced). Cohen only; Fleiss takes 'unweighted'. Required, no default.
- `replicates` (required): What one subject is: 'independent' (independent subjects, for example one biopsy per patient; opens the SE and interval), 'technical' (not independent, for example several lesions, eyes or wells from one source) or 'unspecified'. Required: never inferred.
- `counts`: Counts only. Cohen: a k × k table, rows the first rater's category and columns the second's, both in the order of categories. Fleiss: one row per subject, the number of raters who chose each category, in the order of categories; every row sums to the same number of raters. Cohen: the table totals 2 to 10,000 subjects. Fleiss: 2 to 3,000 rows and at most 6,000 cells (rows × categories); each row sums to 2 to 100 raters. Optional.
- `labels`: Labels only: one row per subject, 2 to 5,000 rows; Cohen exactly two labels per row, Fleiss 2 to 100. At most 10,000 labels and 60,000 bytes of label text in all, counted as written in JSON. No missing ratings. Optional.
- `level`: Confidence level of the Wald intervals: 0.9, 0.95 or 0.99 (or 90, 95, 99 %). Cohen only; omit for Fleiss. Must be above 0 and below 1. Optional.

### Every refusal, with its code

12 refusals

| Code | When |
| --- | --- |
| `UNKNOWN_CATEGORY` | a label that is not in categories. |
| `RATERS_PER_SUBJECT_DIFFER` | subjects rated by different numbers of raters (labels rows of different lengths, or Fleiss counts rows with different sums). |
| `LENGTHS_DIFFER` | a counts row without one entry per category, or a Cohen table that is not k × k. |
| `DUPLICATE_NAME` | a category listed twice. |
| `INVALID_STRING` | a category name with a non-printing character, U+0000 to U+001F, U+007F to U+009F, U+2028 or U+2029 (tab, line break and the other C0 and C1 controls, and the line and paragraph separators), looked for after leading and trailing white space (as JavaScript's trim) is removed from every name and label, so a leading or trailing tab or line break is removed, not refused; or a name or label empty once trimmed. A label is not looked at for these characters: one that matches no category is UNKNOWN\_CATEGORY. |
| `INVALID_OPTION` | Fleiss' kappa with weights other than 'unweighted'; method, input, weights or replicates outside its listed values (replicates 'biological', for one); a level inside 0 to 1 that is not 0.9, 0.95 or 0.99 (0.8, or 80 %). |
| `CONFLICTING_ARGUMENT` | level with Fleiss' kappa, or the form not sent being sent. |
| `MISSING_ARGUMENT` | Cohen's kappa without level, the form named by input not sent, or method, input, categories, weights or replicates not sent. |
| `OUT_OF_RANGE` | a Cohen table total outside 2 to 10000 subjects (a total of 0 or 1 is OUT\_OF\_RANGE, not TOO\_FEW\_VALUES: a Cohen table's subjects are its total), a Fleiss counts row summing outside 2 to 100 raters (a row above 100 is OUT\_OF\_RANGE; rows checked from the first, after the 6000-cell cap and ahead of RATERS\_PER\_SUBJECT\_DIFFER), a negative count, or a level of 0 or 1 or beyond. |
| `TOO_MANY_VALUES` | more than 5000 rows of labels, 3000 rows of Fleiss counts, 100 raters or 20 categories; labels over 10000 in all; Fleiss counts over 6000 cells; or more than two labels per subject for Cohen's kappa (checked row by row from the first, ahead of RATERS\_PER\_SUBJECT\_DIFFER, so a Cohen row of three labels is TOO\_MANY\_VALUES). |
| `TOO_FEW_VALUES` | fewer than two subjects as rows (rows of labels, or rows of Fleiss counts; a Cohen table of 0 or 1 subjects in all is OUT\_OF\_RANGE), fewer than two labels per subject, or fewer than two categories. |
| `TOO_LONG` | a category name or label over 60 characters, counted in UTF-16 code units once trimmed (a character beyond U+FFFF counts 2); or labels over 60000 bytes of text in all: every label in every row, once trimmed, counted as the UTF-8 bytes of its JSON string as JavaScript's JSON.stringify writes it, less the two quotes (a quote or backslash 2 bytes, a control character 2 or 6, other characters unescaped). |

## The calculation

The method's equations, constants and worked example.

### [Agreement between raters beyond chance: Cohen's kappa (unweighted, linear or quadratic) and Fleiss' kappa](https://www.drybench.com/methods/m/stats-agreement-kappa/1.1.1)

`stats-agreement-kappa@1.1.1`

**Equation 1**

```text
κ̂ = (P_o − P_e)/(1 − P_e), P_o = Σᵢ pᵢᵢ, P_e = Σᵢ pᵢ· p·ᵢ, pᵢⱼ = nᵢⱼ/n (as given in SAS/STAT documentation, which cites Cohen 1960, not read)
```

| Symbol | Meaning |
| --- | --- |
| `pᵢⱼ` | proportion of subjects put in category i by the first rater and j by the second: nᵢⱼ/n, nᵢⱼ the count in row i and column j of \`counts\` (rows the first rater, columns the second, both in the order of \`categories\`) |
| `pᵢ·` | Σⱼ pᵢⱼ, the first rater's proportion in category i (the reply's proportionFirst) |
| `p·ᵢ` | Σⱼ pⱼᵢ, the second rater's proportion in category i (the reply's proportionSecond) |
| `P_o` | observed agreement (the reply's observedAgreement) |
| `P_e` | chance agreement (the reply's expectedAgreement) |
| `n` | subjects |

Source 1.

**Equation 2**

```text
Var(κ̂) = (A + B − C)/((1 − P_e)² n), A = Σᵢ pᵢᵢ(1 − (pᵢ· + p·ᵢ)(1 − κ̂))², B = (1 − κ̂)² ΣΣ_{i≠j} pᵢⱼ(p·ᵢ + pⱼ·)², C = (κ̂ − P_e(1 − κ̂))²
standardError = √Var(κ̂)
interval κ̂ ± z₍₁₊ₗ₎/₂ √Var(κ̂), the reply's interval with method 'wald' and coverage l
with one rater constant (RATER_CONSTANT) Var(κ̂) is exactly 0 in every weighting, as Var₀(κ̂) is: an SE of 0 and an interval of 0 to 0 would describe no sampling uncertainty, which is false (the delta method breaking down at a boundary, not a measurement), so standardError and the interval are withheld with z and p, and nullStandardError is served as the exact 0 (as given in SAS/STAT documentation, which cites Fleiss, Cohen and Everitt 1969, not read)
```

| Symbol | Meaning |
| --- | --- |
| `κ̂` | Cohen's kappa |
| `A, B, C` | the three terms of the large-sample variance, as defined in the text |
| `l` | the caller's level (0.9, 0.95 or 0.99), the interval's coverage |
| `z₍₁₊ₗ₎/₂` | the standard normal quantile Φ⁻¹((1 + l)/2) |

Source 1.

**Equation 3**

```text
Var₀(κ̂) = (P_e + P_e² − Σᵢ pᵢ· p·ᵢ(pᵢ· + p·ᵢ))/((1 − P_e)² n)
z = κ̂/√Var₀(κ̂), the reply's nullStandardError being √Var₀(κ̂)
p = 2(1 − Φ(|z|)), Φ the standard normal distribution function (as given in SAS/STAT documentation, which cites Fleiss, Levin and Paik 2003, not read)
```

| Symbol | Meaning |
| --- | --- |
| `z` | standardized test statistic against kappa = 0 |
| `Φ` | the standard normal distribution function |

Source 1.

**Equation 4**

```text
κ̂_w = (P_o(w) − P_e(w))/(1 − P_e(w)), P_o(w) = ΣΣ wᵢⱼ pᵢⱼ, P_e(w) = ΣΣ wᵢⱼ pᵢ· p·ⱼ
Var(κ̂_w) = (ΣΣ pᵢⱼ(wᵢⱼ − (w̄ᵢ· + w̄·ⱼ)(1 − κ̂_w))² − (κ̂_w − P_e(w)(1 − κ̂_w))²)/((1 − P_e(w))² n)
Var₀(κ̂_w) = (ΣΣ pᵢ· p·ⱼ(wᵢⱼ − (w̄ᵢ· + w̄·ⱼ))² − P_e(w)²)/((1 − P_e(w))² n), w̄ᵢ· = Σⱼ p·ⱼ wᵢⱼ, w̄·ⱼ = Σᵢ pᵢ· wᵢⱼ The reply's observedAgreement and expectedAgreement are then P_o(w) and P_e(w), and kappa, standardError, nullStandardError, z and p are those of κ̂_w (as given in SAS/STAT documentation)
```

| Symbol | Meaning |
| --- | --- |
| `wᵢⱼ` | agreement weight of categories i and j, i and j indexing the categories in the order listed |
| `w̄ᵢ·, w̄·ⱼ` | the margin-weighted mean weights of row i and column j, as defined in the text |

Source 1.

**Equation 5**

```text
linear (Cicchetti–Allison weights, as given in SAS): wᵢⱼ = 1 − |i − j|/(k − 1)
quadratic (Fleiss–Cohen weights, as given in SAS): wᵢⱼ = 1 − (i − j)²/(k − 1)², the categories scored 1 to k (ordered, evenly spaced)
no caller-supplied scores or weights
```

| Symbol | Meaning |
| --- | --- |
| `k` | categories |

Source 1.

**Equation 6**

```text
π̂ₖ = (1/n) Σᵢ rᵢₖ/r
p_a = (1/n) Σᵢ Σₖ rᵢₖ(rᵢₖ − 1)/(r(r − 1))
p_e = Σₖ π̂ₖ²
κ̂ = (p_a − p_e)/(1 − p_e) (as given in Gwet 2021, which cites Fleiss 1971, not read)
a point estimate only
the reply's observedAgreement is p_a, expectedAgreement p_e and perCategory[].proportion π̂ₖ. Labels are tallied into rᵢₖ
for Cohen's kappa the first label of a row is the first rater (the table's row) and the second the second rater (its column)
```

| Symbol | Meaning |
| --- | --- |
| `rᵢₖ` | raters putting subject i in category k |
| `r` | raters per subject |
| `π̂ₖ` | pooled proportion of ratings in category k |
| `p_a, p_e` | observed and chance agreement |
| `n` | subjects |

Source 2.

**Conventions**

- method = cohen: Two raters, every subject rated by both: chance agreement from each rater's own category totals.
- method = fleiss: The same number of raters on every subject, who need not be the same people: chance agreement from the pooled category proportions. With two raters, Fleiss' kappa is not Cohen's kappa. A point estimate only.
- weights = unweighted: Only exact agreement counts.
- weights = linear: Partial credit falling linearly with distance in the category order (Cicchetti–Allison weights, as given in SAS); the categories are declared ordered and evenly spaced.
- weights = quadratic: Partial credit falling with the squared distance in the category order (Fleiss–Cohen weights, as given in SAS); the categories are declared ordered and evenly spaced.

A definition, not a model: the equation states what the quantity means. A different convention gives a different number.

**Worked example**

Worked example: one case of stats-agreement-kappa\@1.1.1, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

**Inputs**

- method = cohen
- input = counts
- counts\[0\]\[0\] = 20
- counts\[0\]\[1\] = 3
- counts\[0\]\[2\] = 0
- counts\[1\]\[0\] = 2
- counts\[1\]\[1\] = 10
- counts\[1\]\[2\] = 2
- counts\[2\]\[0\] = 0
- counts\[2\]\[1\] = 3
- counts\[2\]\[2\] = 10
- categories\[0\] = benign
- categories\[1\] = atypical
- categories\[2\] = malignant
- weights = unweighted
- replicates = independent
- level = 0.95

**Steps**

1. po = 0.8, from counts; by equation 1; gives observedAgreement.
2. pe = 0.3544, from counts; by equation 1; gives expectedAgreement.
3. kappa = 0.69021066, from po, pe; by equation 1; gives kappa.
4. se = 0.086165651, from counts, kappa, pe; by equation 2; gives standardError.
5. se0 = 0.10106907, from counts, pe; by equation 3; gives nullStandardError.
6. z = 6.829099, from kappa, se0; by equation 3; gives z.

The working, as the case writes it:

```text
Margins rows 23, 14, 13 and columns 22, 16, 12 of 50. P_o = 40/50 = 4/5
P_e = (23·22 + 14·16 + 13·12)/2500 = 886/2500 = 443/1250
κ = (4/5 − 443/1250)/(1 − 443/1250) = 557/807. The SEs and z from the SAS variance and null variance (worked by hand by Drybench on 11 November 2026 to five figures
this is not an independent check).
```

**Answer**

- observedAgreement = 0.8
- expectedAgreement = 0.3544
- kappa = 0.69021066
- standardError = 0.086165651
- nullStandardError = 0.10106907
- z = 6.829099

Where these values came from: an outside program, Python fractions and mpmath Python 3.13.18; mpmath 1.4.1; stored reference values: exact rationals and mpmath at 50 digits.

At build the tool returned this answer within the tolerance the file states: agreements, kappa and proportions absolute 1e-14 (Drybench ruling, 11 November 2026, K4); SEs, z and interval limits relative 1e-12; p relative 1e-10 (1e-300 absolute below 1e-290); counts, names, codes and statuses exact.

Who worked this case: not recorded.

## Sources

1. SAS Institute Inc. SAS/STAT 14.1 User's Guide, The FREQ Procedure, Details: Tests and Measures of Agreement Used for: Agreement between raters beyond chance: Cohen's kappa (unweighted, linear or quadratic) and Fleiss' kappa. At: section Simple Kappa Coefficient: the coefficient; section Simple Kappa Coefficient: the asymptotic variance and the confidence limits; section Simple Kappa Coefficient: the test, the variance under the null hypothesis; section Weighted Kappa Coefficient; section Weights: Cicchetti–Allison and Fleiss–Cohen weights from the column scores, with the printed weights for scores 0, 2, 4 and 10. **Read in full, 11 November 2026**
2. Gwet KL. Large-Sample Variance of Fleiss Generalized Kappa. Educational and Psychological Measurement 2021;81(4):781–790 Used for: Agreement between raters beyond chance: Cohen's kappa (unweighted, linear or quadratic) and Fleiss' kappa. At: section Notation, eq. 1, and 'Fleiss' Kappa and Its Variance', eq. 2. **Read in full, 11 November 2026**

Read by AI-assisted sessions. No person has checked these readings.

## How it is checked

**Level:** Checked against a reference.

**Checked against:** An outside program, Python fractions and mpmath, Python 3.13.18; mpmath 1.4.1; an outside program, statsmodels inter\_rater; SciPy, statsmodels 0.15.0; scipy 1.18.1; a reference program this project wrote itself, second implementation (Python 3.13; NumPy, SciPy distribution functions and mpmath only), 2026-11-14, exact rationals for the agreements, kappa and both variances; square roots, the normal quantile and the p value in mpmath at 400 bits, each rounded once to a double; not an outside program; a reference program this project wrote itself, second implementation (Python 3.13; NumPy, SciPy distribution functions and mpmath only), 2026-11-14, exact rationals for the agreements, kappa and both variances; square roots, the normal quantile and the p value in mpmath at 80 digits, each rounded once to a double; not an outside program.

**Cases:** No case set is linked to this version.

**Not checked:** Cohen 1960, Cohen 1968, Fleiss, Cohen and Everitt 1969, Fleiss 1971, Fleiss, Nee and Landis 1979 and Fleiss, Levin and Paik 2003 are not read; no published table with its printed kappa and SE is reproduced. The Fleiss SE, interval and test are not offered (Drybench ruling, 11 November 2026, S4), nor Gwet's 2021 variance, per-category kappa, missing ratings, caller-supplied scores or weights, Krippendorff's alpha, ICC, weighted Fleiss, Light's kappa or PABAK.

No independent scientist has yet reviewed this.

### What was not checked, in full

from the method records

- Cohen 1960, Cohen 1968, Fleiss, Cohen and Everitt 1969, Fleiss 1971, Fleiss, Nee and Landis 1979 and Fleiss, Levin and Paik 2003 are not read; no published table with its printed kappa and SE is reproduced.
- The Fleiss SE, interval and test are not offered (Drybench ruling, 11 November 2026, S4), nor Gwet's 2021 variance, per-category kappa, missing ratings, caller-supplied scores or weights, Krippendorff's alpha, ICC, weighted Fleiss, Light's kappa or PABAK.
- The 30-subject threshold is Drybench's judgement.

### Changes to its methods

0 changes

No change is logged for these method versions.
