Agreement between annotators: weighted kappa, Krippendorff's alpha and confidence intervals

Study time
≈ 2 h (estimate)
Needs
L2-M05-L01
Updated
2026-11-04

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L2-M05 · Duration: ~120 min (estimate, including the independent exercise) · Previous: L01 · Next: L03

1. Introduction

The lessons L2-M01-L03, L2-M02-L03, L2-M03-L03 and L2-M04-L04 all promised to teach kappa in this lesson. L2-M04-L04 already defined Cohen's kappa for pass or fail labels (raw agreement p_o, chance agreement p_e, κ = (p_o − p_e) / (1 − p_e)) and extended it without weights to five levels. This lesson does not repeat that part and goes further: an ordered scale needs weighted kappa; many raters with missing labels need Krippendorff's alpha (in the same family as Scott's pi and Fleiss's kappa); a single number needs a confidence interval; and when labels are skewed, high agreement can come with a low coefficient.

A note on a word used in two senses: in L2-M04, "agreement" was between a judge and humans; here it is between humans. The formulas are in the same family, the subject is different. Every annotator in the lab is simulated, so the coefficients in this lesson describe the simulation. The output of this lesson is an agreement report: a pairwise table, an overall coefficient with its interval, and the correct reading of both.

2. Learning objectives

  1. Write the coefficients kappa, pi and alpha under one common formula 1 − D_o / D_e and choose the distance (nominal, linear, quadratic). Practice: §8.3, §8.4.
  2. Compute weighted kappa for an ordered scale and explain why it tells a one-point gap from a four-point gap. Practice: §8.2 part B, §8.3.
  3. Compute alpha when each item has a different number of labels or labels are missing, and compare it with pairwise kappa and Fleiss. Practice: §8.2 parts B, C, §9 (TODO 2).
  4. Report a bootstrap interval for a coefficient and read it correctly. Practice: §8.2 part D, §9 (TODO 3).
  5. Explain why raw agreement of 0.9 can come with a negative kappa and state what a threshold should rest on. Practice: §8.2 part E, §9 (TODO 1).

3. Prerequisites and tools

  • L2-M04-L04: the confusion matrix, p_o, p_e, binary kappa. L2-M02-L03: raw and chance agreement. L2-M05-L01: the data and the protocol.
  • The code lab code-labs/l2-m05 (self-contained, needs only pytest). Round 1 data: 60 items, five annotators A1 to A5 (simulated), three per item, scale 1 to 5.

4. Concepts

4.1 One common formula: 1 − D_o / D_e

Every coefficient in this lesson has the form 1 − D_o / D_e. D_o (observed disagreement) is the mean distance between the labels given to the same item; D_e (expected disagreement) is the mean distance if labels were paired at random in proportion to the label frequencies. A coefficient of 1 is perfect agreement, 0 is chance level, and it can be negative. Artstein and Poesio present alpha and weighted kappa in exactly this form [R1, §2.6, §2.7.2]; the coefficients differ in how they define "chance" and in the distance.

The distance d(x, y) decides how different two labels are. Nominal: 0 if equal, 1 if different (for the binary kappa of L2-M04, exactly the p_o and p_e already learned). Linear: |x − y|. Quadratic: (x − y)², which punishes a large gap more heavily; this is Krippendorff's interval distance, so krippendorff_alpha_interval of L01 is the quadratic alpha. Linear is not a standard distance in that family. Krippendorff's ordinal distance also exists [R1, §2.6.1] but the lab does not implement it. The last two kinds apply only to integer labels (the lab rejects bool and strings). When D_e = 0 (all labels the same) the coefficient is undefined: None, not 0 or 1.

Decision diagram for choosing a coefficient: are the human labels ordered? No: nominal distance. Yes: linear or quadratic distance. Then, with two annotators and no missing labels use kappa (weighted if the scale is ordered); otherwise use Krippendorff's alpha.
Diagram: One common formula: 1 − D_o / D_e

4.2 Weighted kappa for an ordered scale

On a scale of 1 to 5, giving 4 to a reply that the other person gave 5 is a mild disagreement, giving 1 is a severe one; unweighted kappa treats the two the same. Artstein and Poesio write that the serious limitation of π and κ is that all disagreements are treated alike, and they introduce Cohen's (1968) weighted kappa: each pair of labels has a weight, and a large weight is a severe disagreement [R1, §2.6]. cohen_kappa(a, b, weights) accepts "linear", "quadratic" or a distance function.

A hand example (§8.3): a = [1, 1, 2, 3], b = [1, 2, 2, 1]. Unweighted κ = 1/5; linear 0; quadratic −1/4. Three different numbers because the last item is two levels apart. Choosing the weights is a decision, not something measured: Artstein and Poesio note that determining suitable weights makes interpretation harder [R1, §4.1.3]. The distance is computed on the label values, so a level that is never used does not change the result; the test checks against an independent computation from the confusion matrix.

4.3 Many raters, missing labels: alpha, Fleiss, and kappa versus pi

With more than two raters there are two routes. Pairwise kappa (pairwise): computed for every pair on the items they both labelled; a pair with fewer than 10 shared items gets None (the threshold of 10 is the lab's choice). A single coefficient: Fleiss's kappa (every item has the same number of labels; A&P call it multi-π) or Krippendorff's alpha, which suits many raters, many distances and missing labels [R1, §2.5, §2.6]. The lab drops items with fewer than two labels from alpha and counts them (alpha_with_report). With the nominal distance, alpha nearly coincides with multi-π, differing only in a small-sample correction [R1, §2.6.1].

Kappa differs from pi and alpha in where "chance" comes from: π and α use the pooled label distribution, κ uses each rater's own distribution [R1, §3.1]. A&P conclude: choose by the interpretation of "chance" you want, not by the gap between raters; when measuring the reliability of a procedure, use a single-distribution coefficient such as π or α; and the empirical difference between the two kinds is small, smaller still as raters are added [R1, §3.1]. This lesson uses kappa for pairs (as in L2-M04) and alpha for the whole group.

5. Technical deep dive

5.1 The lab's round 1: the pairwise table and the overall coefficient

The data ratings_round1.jsonl: 60 items, each with three of five annotators (simulated), 36 labels per annotator; ten pairs sharing 12 or 24 items. In the simulation A3 scores strictly, A4 leniently, A5 changes how they score in the second half (L03). On the pairs: A1–A2 have a nominal kappa of 0.575 and a quadratic one of 0.883; A2–A5 only 0.008 and 0.250; A1–A4 0.000 and 0.442. Weighted kappa is much higher because most disagreements are one point apart.

For the whole round: nominal alpha 0.279, linear 0.513, quadratic 0.665, Fleiss 0.275 (close to nominal alpha, as the source says). Three different stories: "barely matches level by level", "about one level apart on average", "most disagreements are mild". Each number answers one question, so report it together with the chosen distance and the reason.

5.2 Confidence intervals by bootstrap

Artstein and Poesio cite Cohen (1960): knowing that κ exceeds chance level is "trivial" [R1, §4.1.2]. According to Krippendorff (2004a), what needs measuring is the degree of departure from perfect agreement, so the meaningful notion is a confidence interval; for α the distribution is unknown, so the interval is obtained by bootstrap [R1, §4.1.2]. This lesson relies only on A&P; it has not been checked against Krippendorff's original.

bootstrap_ci resamples items (not individual labels) with replacement, recomputes the coefficient, and takes the 2.5% and 97.5% percentiles of the defined replicates. The resampling uses SHA-256 of (seed, replicate, position), not random, so it is identical on every Python version. Round 1 (1000 replicates, seed "demo"): quadratic alpha 0.665, interval 0.534 to 0.765 (another seed gives a slightly different interval: L03 uses the seed "rounds" and gets 0.528 to 0.767), with no undefined replicate; the interval is wide because there are only 60 items. A resample where the coefficient is undefined is dropped and counted; if fewer than 90% of the replicates are defined, no interval is reported (None). Bootstrap does not fix a biased or too-small sample.

5.3 Skewed labels: high raw agreement, low coefficient

A&P describe the "paradox" (the prevalence paradox) raised by Feinstein and Cicchetti: when most items belong to one class, the expected agreement is very high, so even higher observed agreement is needed to demonstrate reliability [R1, §3.2] (the original paper was not checked). If 95% of items belong to one class, random assignment gives two raters the same label there on about 90.25% of items; the test of reliability is the ability to agree on the rare class [R1, §3.2].

The lab's example (§8.2 part E): 100 items, both give "P" on 90 items, and disagree on 5 and 5 of the remaining items. Raw agreement is 0.900 but kappa and pi are both −0.053. Like the judge example that caught no bad answer in L2-M04-L04, the low coefficient is right: when the rare class is what matters, raw agreement hides it. Report the confusion matrix or the per-group results next to the coefficient, as A&P recommend [R1, §5.3]. The §9 exercise (TODO 1) asks for the largest kappa that two label proportions allow, that is, the part of the limit caused by the label proportions themselves.

6. The QA perspective

6.1 Reading the number: what a threshold should rest on

McHugh calls the table of verbal labels Cohen's interpretation (A&P record it as Landis and Koch's) and writes that it allows very low agreement to be called "substantial"; he proposes a stricter table and says kappa below 0.60 is not enough [R3] (quoted from the page-reading tool's automatic summary). A&P record two major conventions: Landis and Koch (common in medicine) and Krippendorff's convention as cited by Carletta (α above 0.8 is good, 0.67 to 0.8 allows tentative conclusions) [R1, §4.1.3]; they find 0.8 reasonable if a threshold must be set, but "doubt that a single cutoff point is appropriate for all purposes" [R1, §5.3], and call deciding what level suffices for a purpose "little more than a black art" [R1, §4.1.3].

This lesson follows that spirit, consistent with L2-M04-L04: do not apply a table of verbal labels; choose the threshold by the consequences of the decision and record it in the protocol before labelling (L01). The 0.8 or 0.6 in the lab is only an illustrative choice.

6.2 What the coefficients do not check, and the minimum report

  • High agreement does not mean the labels are correct: two people who misread the guideline in the same way still agree. A&P recommend an additional independent evaluation on the task the labels serve [R1, §5.1].
  • A coefficient does not know whether people worked independently (L01), and one overall coefficient hides subgroups (borderline cases deviate more, L03). Nor does it predict whether machine learning on those labels will succeed [R1, §4.1.4].
  • A sufficient report states: the number of raters and how they were assigned, the number of items, the coefficient and its distance, the bootstrap interval with the number of replicates, the pairwise table with the shared item counts, the per-group results, and the threshold set in advance.

7. Real-world scenarios

Scenario 1 (fictional): "90% agreement". Two reviewers flagged "the hint reveals the answer" on 100 replies; 95% of replies do not reveal it, and they agree 90% of the time. Kappa is only −0.053: they almost never flag the same reply. The team reported the confusion matrix and added flagged replies to the sample.

Scenario 2 (fictional): "Kappa 0.28 means people disagree?". On a scale of 1 to 5, a team reported a nominal coefficient of 0.279 and concluded that the guideline was useless. Recomputed with a distance, quadratic alpha is 0.665: most disagreement is one point apart. They recorded both numbers with their distances and read which groups deviated most (L03).

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l2-m05
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 71 passed

8.2 Run the demo

python -m lab.demo l02

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-04; the two versions give identical output). Every annotator is simulated:

A. Artstein and Poesio (2008) Table 4, 100 utterances, 3 categories
   kappa 121/151 0.8013  pi 0.7995  weighted kappa 0.8163  alpha 0.8156
B. round 1: 60 items, 5 simulated annotators, 3 per item (simulated annotators)
   A1-A2 n=24 kappa 0.575  quadratic-weighted 0.883
   A1-A3 n=12 kappa 0.556  quadratic-weighted 0.888
   A1-A4 n=12 kappa 0.000  quadratic-weighted 0.442
   A1-A5 n=24 kappa 0.101  quadratic-weighted 0.410
   A2-A3 n=24 kappa 0.468  quadratic-weighted 0.854
   A2-A4 n=12 kappa 0.150  quadratic-weighted 0.446
   A2-A5 n=12 kappa 0.008  quadratic-weighted 0.250
   A3-A4 n=24 kappa 0.202  quadratic-weighted 0.606
   A3-A5 n=12 kappa 0.207  quadratic-weighted 0.628
   A4-A5 n=24 kappa 0.300  quadratic-weighted 0.787
C. whole round, alpha: nominal 0.279  linear 0.513  quadratic 0.665  Fleiss 0.275
D. bootstrap 95% interval for quadratic alpha: 0.665 (0.534 to 0.765), 0 of 1000 replicates undefined
E. skewed labels: raw agreement 0.900  kappa -0.053  pi -0.053

Reading the output: A is the published example of Artstein and Poesio (Table 4, 100 utterances, three categories): the lab gives κ = 121/151 ≈ 0.8013, π ≈ 0.7995, weighted kappa ≈ 0.8163 and alpha ≈ 0.8156, matching the figures in the paper [R1, §2.7] (weight 1 for Statement against Info-Request, 0.5 for Check against the other two). B is the table of ten pairs; C is the four coefficients for the whole round; D is the bootstrap interval; E is the skewed-label example.

8.3 Try it yourself

Save it as try_l02.py in the lab's root folder (next to lab/), run python try_l02.py, then delete the file:

from lab import agreement as A

a, b = [1, 1, 2, 3], [1, 2, 2, 1]
print(A.cohen_kappa(a, b), A.cohen_kappa(a, b, "linear"), A.cohen_kappa(a, b, "quadratic"))
print(A.krippendorff_alpha([[1, 1], [2, 2], [1, 2]]), A.krippendorff_alpha([[1, 1], [2, 2], [1, 2], [1]]))
print(A.cohen_kappa([3, 3, 3], [3, 3, 3]), A.cohen_kappa([1, 2, 1, 2], [3, 3, 3, 3]))

Output (identical on Python 3.14.6 and 3.12.14):

1/5 0 -1/4
4/9 4/9
None 0

Reading: line 1 is the three coefficients of §4.2. Line 2: nominal alpha is 4/9 (D_o = 1/3, D_e = 3/5), and adding an item with only one label does not change the result because it is dropped. Line 3: all labels the same gives None; one rater using a single label gives kappa 0 (chance level), not None.

8.4 Run the lesson's tests

python -m pytest tests/test_l02_agreement.py tests/test_data.py -v

Result: 24 passed (19 tests for this lesson, 5 data checks). Read test_published_worked_example_all_four_coefficients, test_weighted_kappa_hand_computed_three_levels, test_pairwise_quadratic_matches_an_independent_naive_computation, test_prevalence_and_skew_raw_agreement_can_be_high_with_negative_kappa and test_bootstrap_handles_undefined_replicates_and_bad_input. The tests run on hand computations, the published example and simulated data; they do not measure real people.

8.5 Troubleshooting

Symptom Cause Fix
TypeError: numeric distances need int labels Using linear or quadratic with strings or bool Convert the labels to integers or use nominal
Kappa is None All labels are the same (D_e = 0) Add items for the other label; do not report 1 or 0
ValueError: Fleiss needs the same number m >= 2 Each item has a different number of labels Use krippendorff_alpha
pairwise returns kappa: None The pair shares fewer than 10 items Report the shared item count; draw no conclusion about that pair
The bootstrap interval is None Too many undefined replicates Add items or change the coefficient

9. Independent exercise

Problem: Analyse the agreement of a group of five annotators on 40 items (simulated data) and extend the lab with a new quantity.

Requirements: complete exercises/test_l02_agreement.py:

  1. TODO 1: write the function kappa_max(a, b): the largest kappa that two raters with these label proportions can reach (formula in the docstring), returning a Fraction or None; the two lists must have the same length, other than 0 (otherwise ValueError).
  2. TODO 2: fill in WORST_PAIR: the pair of people (a tuple of two names, in alphabetical order) with the lowest quadratic kappa among pairs that share at least 10 items.
  3. TODO 3: fill in REPORT = {"alpha": ..., "lo": ..., "hi": ...}: the quadratic alpha over all items and the 95% bootstrap interval (1000 replicates, seed "ex-l02"), rounded to 3 digits, as floats.

Test data: exercises/ex_ratings.jsonl (40 items, raters R1 to R5; R5 labelled only 8 items).

Deliverable: the function kappa_max and the two variables WORST_PAIR, REPORT in the file exercises/test_l02_agreement.py itself.

Acceptance criteria: python -m pytest exercises/test_l02_agreement.py passes (4 tests): kappa_max is correct on small tables and never smaller than the kappa on the data; WORST_PAIR and REPORT are recomputed from the data. The tests do not check that you understand why that pair is lowest: read that pair's items yourself.

Hint: for TODO 1, think about how the two label proportions limit the maximum match. For TODO 2, look at each pair's shared item count before comparing kappa. For TODO 3, use exactly the distance and seed in the problem.

10. Knowledge check

0/16 done · Results are kept in this browser only.

P02 · True or false

Two annotators label every item 3. cohen_kappa([3, 3, 3], [3, 3, 3]) returns 1 because they agree perfectly.

P04 · Select all that apply

Select every true statement about krippendorff_alpha and pairwise of the lab.

P05 · Put in order

Put the steps of bootstrap_ci in order.

  1. Drop the runs where the coefficient is undefined and count them
  2. Repeat many times (for example 1000)
  3. Take the 2.5th and 97.5th percentiles of the defined runs; if fewer than 90% of the runs are defined, report no interval
  4. Recompute the coefficient on the resample
  5. Resample the items with replacement, the same number of items as the original data

P06 · Match

Match the parameter or function of lab/agreement.py with its meaning.

P07 · Spot the bug

The function below is named cohen_kappa but actually computes a different coefficient, so it gives the wrong result when the two people have different label rates. Find the bug.

def cohen_kappa(a, b, weights="nominal"):
    d = _dist(weights)
    n = len(a)
    do = Fraction(sum(d(x, y) for x, y in zip(a, b)), n)
    pooled = Counter(a) + Counter(b)
    de = sum(Fraction(pooled[x] * pooled[y], 4 * n * n) * d(x, y) for x in pooled for y in pooled)
    return None if de == 0 else 1 - do / de

P08 · Short answer

On round 2 of the lab (60 items, five simulated people, three per item), nominal alpha is 0.380, linear 0.641 and quadratic 0.815. A manager asks for "one single number". What should you report, and in what words?

P09 · Essay

Write 5-8 sentences: report the agreement for round 2 of the lab (simulated): five people, three people per item, 60 items; quadratic alpha 0.815, 95% bootstrap interval from 0.737 to 0.873 (1000 runs, seed "p02", no run undefined); pairwise quadratic kappa: A1–A4 0.617 on 12 shared items, A2–A4 0.652 on 12 items, A4–A5 0.672 on 24 items, A2–A3 0.892 on 24 items. State what the numbers do not tell you.

P11 · Recall

Lesson: L2-M04-L04

In L2-M04-L04, p_o is the raw agreement and p_e is the chance agreement. If p_o = 0.86 and p_e = 0.74 (made-up numbers), what is the binary kappa κ = (p_o − p_e) / (1 − p_e)?

P12 · Recall

Lesson: L2-M05-L01

L01 requires setting the reporting.min_agreement threshold before labelling. According to L02, what should that threshold be based on?

P13 · Multiple choice

Four items (made-up numbers) have these human labels: [[1, 1, 2], [3, 3], [2, 3, 3], [1]]. What does nominal krippendorff_alpha return, and how many items are dropped?

P14 · True or false

Choosing quadratic weights instead of linear is something the data decides by itself, so there is no need to record a reason in the report.

P15 · Select all that apply

Round 2 (simulated) gives quadratic alpha 0.815, interval 0.737 to 0.873. Select everything that cannot be concluded from this number.

P16 · Multiple choice

Round 2 (simulated) has Fleiss kappa 0.377 and nominal alpha 0.380, almost equal. Why?

11. Summary

  • Concepts: every coefficient has the form 1 − D_o / D_e; an ordered scale needs a distance; alpha tolerates missing labels; confidence intervals by bootstrap; skewed labels lower the coefficient even when raw agreement is high.
  • Skills: kappa of the various kinds, pi, Fleiss, alpha, the pairwise table, the bootstrap interval.
  • Traps: reporting a coefficient without its distance; applying a table of verbal labels; pairwise kappa on a few items; forgetting the interval; thinking bootstrap fixes a bad sample.
  • You can now: hear "the raters agree at 0.8" and ask: which coefficient, which distance, how many items, what confidence interval, are the labels skewed.

12. References

ID Title Publisher URL Accessed Relevance
R1 Inter-Coder Agreement for Computational Linguistics (Artstein and Poesio, 2008) Computational Linguistics https://aclanthology.org/J08-4004.pdf 2026-11-04 Full-text PDF (extracted with a local tool): §2.5 to §2.7, §3, §4.1, §5; the Table 4 example
R3 Interrater reliability: the kappa statistic (McHugh, 2012) Biochemia Medica (PMC) https://pmc.ncbi.nlm.nih.gov/articles/PMC3900052/ 2026-11-04 WebFetch: the kappa formula, the interpretation table, "below 0.60 is not enough"

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Weighted kappa Kappa có trọng số
Krippendorff's alpha Alpha của Krippendorff
Fleiss's kappa / Scott's pi Kappa của Fleiss / pi của Scott
Observed / expected disagreement Bất đồng quan sát / kỳ vọng (D_o, D_e)
Bootstrap interval Khoảng bootstrap (lấy mẫu lại mục có hoàn lại)
Prevalence Tỷ lệ của một loại nhãn; nhãn lệch (skew) khi một loại chiếm phần lớn