Many raters and missing ratings: Fleiss and Krippendorff
Beyond two raters, use Fleiss' kappa when every subject has every rater, and Krippendorff's alpha when ratings are missing or the scale isn't nominal.
What runs in CodeSplash
- STAT307Cohen kappa significance test Runs in CodeSplash
- Fleiss' kappa (several raters) Verified in Python and R
- Krippendorff's alpha (any number of raters, missing ratings) Verified in Python and R
- Gwet's AC1/AC2 and other agreement coefficients Verified in Python and R
You will be able to
- Choose between Fleiss' kappa and Krippendorff's alpha
- Set the level of measurement for Krippendorff's alpha
- Read alpha's bootstrap interval and its threshold probabilities
Read first
Beyond two raters
In the appFleiss' kappaFleiss' kappaChance-corrected agreement for several raters on a category, where different raters may judge each item. extends chance-corrected agreement to any number of raters assigning nominal categories. Each subject should have the same number of ratings, though not necessarily from the same people.
With 5 raters and 4 categories across 149 subjects, = 0.54 (95% interval 0.48 to 0.60).
κ = .54, 95% CI [0.48, 0.60], z = 33.95, p < .001
- κ
- 0.5411
- 95% CI
- [0.4791, 0.6032]
- p
- < .001
Effect size
- Fleiss' κ 0.5411 95% CI [0.4791, 0.6032]
Plots
View data
| Category | Share | Rater | Share of subjects |
|---|---|---|---|
| none | 38% | rater_a | 0.3758 |
| mild | 30% | rater_a | 0.2953 |
| moderate | 22% | rater_a | 0.2215 |
| severe | 11% | rater_a | 0.1074 |
| none | 36% | rater_b | 0.3624 |
| mild | 31% | rater_b | 0.3087 |
| moderate | 20% | rater_b | 0.2013 |
| severe | 13% | rater_b | 0.1275 |
| none | 37% | rater_c | 0.3691 |
| mild | 34% | rater_c | 0.3356 |
| moderate | 18% | rater_c | 0.1812 |
| severe | 11% | rater_c | 0.1141 |
| none | 37% | rater_d | 0.3691 |
| mild | 36% | rater_d | 0.3557 |
| moderate | 17% | rater_d | 0.1745 |
| severe | 10% | rater_d | 0.1007 |
| none | 38% | rater e | 0.3758 |
| mild | 30% | rater e | 0.2953 |
| moderate | 21% | rater e | 0.2148 |
| severe | 11% | rater e | 0.1141 |
Assumptions
- Sample size — 149 subjects rated by 5 raters.
- Category use — Every category has at least 5% of the ratings.
Agreement by category
| Category | Share of ratings | κ | z | p |
|---|---|---|---|---|
| none | 37.0% | 0.6547 | 25.271 | < .001 |
| mild | 31.8% | 0.4121 | 15.909 | < .001 |
| moderate | 19.9% | 0.4688 | 18.096 | < .001 |
| severe | 11.3% | 0.6713 | 25.911 | < .001 |
- 1 of 150 rows were left out because a value was missing.
- z test with the null SE of Fleiss, Nee & Landis (1979); interval from a jackknife SE. Categories: none, mild, moderate, severe.
The exact R script · R R version 4.5.1 (2025-06-13)
# Fleiss' kappa (several raters)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method agreement.fleiss 1.0.1 · spec c346f434f1807a55
# Dataset: ratings_sim (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/ratings_sim.parquet", col_select = c("rater_a", "rater_b", "rater_c", "rater_d", "rater e")))
n_input <- nrow(df)
df[["rater_a"]] <- factor(df[["rater_a"]], levels = c("none", "mild", "moderate", "severe")) # stored level order
df[["rater_b"]] <- factor(df[["rater_b"]], levels = c("none", "mild", "moderate", "severe")) # stored level order
df[["rater_c"]] <- factor(df[["rater_c"]], levels = c("none", "mild", "moderate", "severe")) # stored level order
df[["rater_d"]] <- factor(df[["rater_d"]], levels = c("none", "mild", "moderate", "severe")) # stored level order
df[["rater e"]] <- factor(df[["rater e"]], levels = c("none", "mild", "moderate", "severe")) # stored level order
df <- df[stats::complete.cases(df[c("rater_a", "rater_b", "rater_c", "rater_d", "rater e")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("rater_a", "rater_b", "rater_c", "rater_d", "rater e")) # infinite values stop the run (registry/errors.yaml)
# %% Category counts per subject
raters <- c("rater_a", "rater_b", "rater_c", "rater_d", "rater e")
cats <- unique(unlist(lapply(raters, function(r) levels(df[[r]])))) # stored order
k <- length(cats)
if (k < 2) cs_error("CS_E_UNDEFINED", what = "Fleiss' κ", reason = "the raters used only one category")
codes <- sapply(raters, function(r) match(as.character(df[[r]]), cats))
codes <- matrix(codes, ncol = length(raters))
n <- nrow(codes)
m <- ncol(codes)
counts <- t(apply(codes, 1, function(x) tabulate(x, k)))
counts <- matrix(counts, nrow = n)
# %% Fleiss' kappa
conf <- 0.95
res <- cs_fleiss(counts, conf) # twin of codesplash.stats.agreement.fleiss
values <- res[c("kappa", "ci_low", "ci_high", "se", "se0", "z", "p", "po", "pe")]
values$n <- n
values$m <- m
values$k <- k
fin <- function(x) if (!is.finite(x)) NA else unname(x)
# The jackknife interval is undefined when leaving a subject out leaves one category (tiny samples): null.
for (key in c("se", "ci_low", "ci_high")) values[key] <- list(fin(values[[key]]))
rows <- list()
for (i in seq_along(cats)) {
c0 <- cats[i]
values[[sprintf("prop[%s]", c0)]] <- res$pj[i]
values[[sprintf("kappa[%s]", c0)]] <- fin(res$kappa_j[i])
values[[sprintf("z[%s]", c0)]] <- fin(res$z_j[i])
values[[sprintf("p[%s]", c0)]] <- fin(res$p_j[i])
rows[[i]] <- list(category = c0, prop = res$pj[i], kappa = fin(res$kappa_j[i]), z = fin(res$z_j[i]), p = fin(res$p_j[i]))
}
# %% Assumptions
rare <- cats[res$pj < 0.05]
assumptions <- list(
list(key = "sample_size", label = "Sample size", status = if (n < 30) "warn" else "pass",
detail = paste0(sprintf("%d subjects rated by %d raters", n, m), if (n < 30) " — the interval is approximate." else ".")),
list(key = "category_use", label = "Category use", status = if (length(rare)) "warn" else "pass",
detail = if (length(rare)) sprintf("Rarely used (< 5%% of ratings): %s.", paste(rare, collapse = ", ")) else "Every category has at least 5% of the ratings.")
)
# %% Result
pct <- sprintf("%.0f%%", conf * 100)
share <-as.vector(vapply(seq_len(m), function(j) vapply(seq_len(k), function(i) mean(codes[, j] == i), numeric(1)), numeric(k)))
cs_publish(list(
method = "agreement.fleiss",
methodVersion = "1.0.1",
title = "Fleiss' kappa",
engine = cs_engine_info("stats", "codesplashr"),
n = n,
summary = sprintf("Fleiss' κ = %.3f, %s CI [%.3f, %.3f] for %d raters and %d subjects.", res$kappa, pct, res$ci_low, res$ci_high, m, n),
apa = sprintf("κ = %s, %s CI [%s, %s], z = %s, %s", cs_fmt_num(res$kappa, 2, leading_zero = FALSE), pct, cs_fmt_num(res$ci_low),
cs_fmt_num(res$ci_high), cs_fmt_num(res$z), cs_fmt_p(res$p)),
statistics = list(list(key = "kappa", label = "κ", value = res$kappa), list(key = "ci", label = paste(pct, "CI"), value = c(res$ci_low, res$ci_high)),
list(key = "p", label = "p", value = res$p, format = "p")),
tables = list(list(key = "categories", title = "Agreement by category", columns = list(
list(key = "category", label = "Category", type = "string"), list(key = "prop", label = "Share of ratings", type = "percent"),
list(key = "kappa", label = "κ", type = "number"), list(key = "z", label = "z", type = "number"), list(key = "p", label = "p", type = "pvalue")
), rows = rows)),
effectSizes = list(list(key = "kappa", label = "Fleiss' κ", value = res$kappa, ciLow = res$ci_low, ciHigh = res$ci_high,
ciLevel = conf, method = "jackknife SE over subjects")),
assumptions = assumptions,
warnings = warnings,
notes = list(sprintf("z test with the null SE of Fleiss, Nee & Landis (1979); interval from a jackknife SE. Categories: %s.", paste(cats, collapse = ", "))),
charts = list(cs_chart("use", "matrix-heatmap", "Category use by rater", list(
row = cs_col("Rater", rep(raters, each = k), "categorical", levels = raters),
col = cs_col("Category", rep(cats, times = m), "categorical", levels = cats),
value = cs_col("Share of subjects", share, "numeric"),
label = cs_col("Share", sprintf("%.0f%%", 100 * share), "categorical")
), controls = list(scale = "sequential"))),
values = values
))
κ = .54, 95% CI [0.48, 0.60], z = 33.95, p < .001
- κ
- 0.5411
- 95% CI
- [0.4791, 0.6032]
- p
- < .001
Effect size
- Fleiss' κ 0.5411 95% CI [0.4791, 0.6032]
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Sample size — 149 subjects rated by 5 raters.
- Category use — Every category has at least 5% of the ratings.
Agreement by category
| Category | Share of ratings | κ | z | p |
|---|---|---|---|---|
| none | 37.0% | 0.6547 | 25.271 | < .001 |
| mild | 31.8% | 0.4121 | 15.909 | < .001 |
| moderate | 19.9% | 0.4688 | 18.096 | < .001 |
| severe | 11.3% | 0.6713 | 25.911 | < .001 |
- 1 of 150 rows were left out because a value was missing.
- z test with the null SE of Fleiss, Nee & Landis (1979); interval from a jackknife SE. Categories: none, mild, moderate, severe.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Fleiss' kappa (several raters)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method agreement.fleiss 1.0.1 · spec c346f434f1807a55
# Dataset: ratings_sim (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.stats import agreement as ag # Fleiss' κ (twin of R's cs_fleiss)
# %% Data
df = pd.read_parquet("tests/parity/fixtures/ratings_sim.parquet", columns=["rater_a", "rater_b", "rater_c", "rater_d", "rater e"])
n_input = len(df)
df["rater_a"] = pd.Categorical(df["rater_a"], categories=["none", "mild", "moderate", "severe"]) # stored level order
df["rater_b"] = pd.Categorical(df["rater_b"], categories=["none", "mild", "moderate", "severe"]) # stored level order
df["rater_c"] = pd.Categorical(df["rater_c"], categories=["none", "mild", "moderate", "severe"]) # stored level order
df["rater_d"] = pd.Categorical(df["rater_d"], categories=["none", "mild", "moderate", "severe"]) # stored level order
df["rater e"] = pd.Categorical(df["rater e"], categories=["none", "mild", "moderate", "severe"]) # stored level order
df = df.dropna(subset=["rater_a", "rater_b", "rater_c", "rater_d", "rater e"]) # listwise deletion over the analysis columns
df["rater_a"] = df["rater_a"].cat.remove_unused_categories()
df["rater_b"] = df["rater_b"].cat.remove_unused_categories()
df["rater_c"] = df["rater_c"].cat.remove_unused_categories()
df["rater_d"] = df["rater_d"].cat.remove_unused_categories()
df["rater e"] = df["rater e"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["rater_a", "rater_b", "rater_c", "rater_d", "rater e"]) # infinite values stop the run (registry/errors.yaml)
# %% Category counts per subject
raters = ["rater_a", "rater_b", "rater_c", "rater_d", "rater e"]
cats = list(dict.fromkeys(str(x) for r in raters for x in df[r].cat.categories)) # stored order
k = len(cats)
if k < 2:
cs.cs_error("CS_E_UNDEFINED", what="Fleiss' κ", reason="the raters used only one category")
codes = np.column_stack([[cats.index(x) for x in df[r].astype(str)] for r in raters])
n, m = codes.shape
counts = np.zeros((n, k))
for j in range(m):
np.add.at(counts, (np.arange(n), codes[:, j]), 1)
# %% Fleiss' kappa
conf = 0.95
res = ag.fleiss(counts, conf)
values = {key: float(res[key]) for key in ("kappa", "ci_low", "ci_high", "se", "se0", "z", "p", "po", "pe")}
values.update({"n": float(n), "m": float(m), "k": float(k)})
rows = []
nan = lambda x: None if not np.isfinite(x) else float(x) # noqa: E731
# The jackknife interval is undefined when leaving a subject out leaves one category (tiny samples): null.
for key in ("se", "ci_low", "ci_high"):
values[key] = nan(values[key])
for i, c in enumerate(cats):
values[f"prop[{c}]"] = float(res["pj"][i])
values[f"kappa[{c}]"], values[f"z[{c}]"], values[f"p[{c}]"] = nan(res["kappa_j"][i]), nan(res["z_j"][i]), nan(res["p_j"][i])
rows.append({"category": c, "prop": float(res["pj"][i]), "kappa": values[f"kappa[{c}]"], "z": values[f"z[{c}]"], "p": values[f"p[{c}]"]})
# %% Assumptions
rare = [c for i, c in enumerate(cats) if res["pj"][i] < 0.05]
assumptions = [
{"key": "sample_size", "label": "Sample size", "status": "warn" if n < 30 else "pass",
"detail": f"{n} subjects rated by {m} raters" + (" — the interval is approximate." if n < 30 else ".")},
{"key": "category_use", "label": "Category use", "status": "warn" if rare else "pass",
"detail": f"Rarely used (< 5% of ratings): {', '.join(rare)}." if rare else "Every category has at least 5% of the ratings."},
]
# %% Result
pct = f"{conf:.0%}"
share = [float(np.mean(codes[:, j] == i)) for j in range(m) for i in range(k)]
cs.publish({
"method": "agreement.fleiss",
"methodVersion": "1.0.1",
"title": "Fleiss' kappa",
"engine": cs.engine_info("numpy", "scipy", "codesplash"),
"n": int(n),
"summary": f"Fleiss' κ = {res['kappa']:.3f}, {pct} CI [{res['ci_low']:.3f}, {res['ci_high']:.3f}] for {m} raters and {n} subjects.",
"apa": f"κ = {cs.fmt_num(res['kappa'], 2, leading_zero=False)}, {pct} CI [{cs.fmt_num(res['ci_low'])}, {cs.fmt_num(res['ci_high'])}], z = {cs.fmt_num(res['z'])}, {cs.fmt_p(res['p'])}",
"statistics": [{"key": "kappa", "label": "κ", "value": res["kappa"]}, {"key": "ci", "label": f"{pct} CI", "value": [res["ci_low"], res["ci_high"]]},
{"key": "p", "label": "p", "value": res["p"], "format": "p"}],
"tables": [{"key": "categories", "title": "Agreement by category", "columns": [
{"key": "category", "label": "Category", "type": "string"}, {"key": "prop", "label": "Share of ratings", "type": "percent"},
{"key": "kappa", "label": "κ", "type": "number"}, {"key": "z", "label": "z", "type": "number"}, {"key": "p", "label": "p", "type": "pvalue"},
], "rows": rows}],
"effectSizes": [{"key": "kappa", "label": "Fleiss' κ", "value": res["kappa"], "ciLow": res["ci_low"], "ciHigh": res["ci_high"],
"ciLevel": conf, "method": "jackknife SE over subjects"}],
"assumptions": assumptions,
"warnings": warnings,
"notes": [f"z test with the null SE of Fleiss, Nee & Landis (1979); interval from a jackknife SE. Categories: {', '.join(cats)}."],
"charts": [cs.chart("use", "matrix-heatmap", "Category use by rater", {
"row": cs.col("Rater", [r for r in raters for _ in cats], "categorical", levels=raters),
"col": cs.col("Category", [c for _ in raters for c in cats], "categorical", levels=cats),
"value": cs.col("Share of subjects", share, "numeric"),
"label": cs.col("Share", [f"{x:.0%}" for x in share], "categorical"),
}, controls={"scale": "sequential"})],
"values": values,
})
When Fleiss doesn't fit
PredictPredict first
Four coders each rated a dozen documents, but not every coder rated every document. Which approach uses all the ratings you have?
Reveal
Krippendorff's alpha. It works from pairs of values within each unit, so a unit needs only two ratings. Here 11 of 12 units qualify, giving = 0.74. Dropping incomplete rows would throw away information, and possibly the difficult cases.
How alpha works
ReadKrippendorff's alphaKrippendorff's alphaChance-corrected agreement for any number of raters and any scale, and it tolerates missing ratings. compares observed disagreement with the disagreement expected by chance:
What counts as disagreement depends on the Level of measurement:
- Nominal: any difference counts the same.
- Ordinal: larger rank distances count more.
- Interval: squared differences.
- Ratio: differences relative to size.
Choosing the level changes the answer, so choose it from the scale, not from the result.
Read a threshold, not a star
In the appKrippendorff suggested relying on data with and drawing only tentative conclusions from between and 0.8. The method's bootstrap estimates the chance that the true falls below each.
In this interval-scale example, = 0.85. The bootstrap puts 33.4% of its resamples below 0.8 and 14.4% below 0.667. With 11 units, you can't rule out low reliability, even though the estimate looks fine.
Krippendorff's α = .85, 90% CI [0.54, 0.99]
- α
- 0.8491
- 90% CI
- [0.5404, 0.9854]
- Observed disagreement Do
- 0.4333
- Expected disagreement De
- 2.872
Effect size
- Krippendorff's α 0.8491 90% CI [0.5404, 0.9854]
Plots
View data
| Paired with | Count | Value | Coincidences |
|---|---|---|---|
| 1 | 7.0 | 1 | 7 |
| 2 | 1.3 | 1 | 1.333 |
| 3 | 0.3 | 1 | 0.3333 |
| 4 | 0.3 | 1 | 0.3333 |
| 5 | 0.0 | 1 | 0 |
| 1 | 1.3 | 2 | 1.333 |
| 2 | 10.0 | 2 | 10 |
| 3 | 1.3 | 2 | 1.333 |
| 4 | 0.3 | 2 | 0.3333 |
| 5 | 0.0 | 2 | 0 |
| 1 | 0.3 | 3 | 0.3333 |
| 2 | 1.3 | 3 | 1.333 |
| 3 | 8.0 | 3 | 8 |
| 4 | 0.3 | 3 | 0.3333 |
| 5 | 0.0 | 3 | 0 |
| 1 | 0.3 | 4 | 0.3333 |
| 2 | 0.3 | 4 | 0.3333 |
| 3 | 0.3 | 4 | 0.3333 |
| 4 | 4.0 | 4 | 4 |
| 5 | 0.0 | 4 | 0 |
| 1 | 0.0 | 5 | 0 |
| 2 | 0.0 | 5 | 0 |
| 3 | 0.0 | 5 | 0 |
| 4 | 0.0 | 5 | 0 |
| 5 | 3.0 | 5 | 3 |
Assumptions
- Units with two or more ratings — 11 of 12 units have two or more ratings (40 pairable values) — α is unstable with so few pairable values.
- Level of measurement — Interval difference function over 5 distinct values.
Coincidence matrix (pairable values)
| Value | 1 | 2 | 3 | 4 | 5 | Total |
|---|---|---|---|---|---|---|
| 1 | 7 | 1.333 | 0.3333 | 0.3333 | 0 | 9 |
| 2 | 1.333 | 10 | 1.333 | 0.3333 | 0 | 13 |
| 3 | 0.3333 | 1.333 | 8 | 0.3333 | 0 | 10 |
| 4 | 0.3333 | 0.3333 | 0.3333 | 4 | 0 | 5 |
| 5 | 0 | 0 | 0 | 0 | 3 | 3 |
- Interval α from the coincidence matrix (Krippendorff 2011); units with fewer than two ratings are left out.
- Percentile bootstrap over 11 units, 500 resamples, seed 42 (the same resamples in Python and R). P(α < .667) = 0.144; P(α < .800) = 0.334.
The exact R script · R R version 4.5.1 (2025-06-13)
# Krippendorff's alpha (any number of raters, missing ratings)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method agreement.krippendorff 1.0.1 · spec eef779cdcc0f4084
# Dataset: s3_kripp (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# irr::kripp.alpha(t(x), method = level) computes the same alpha; the twin cs_agree_kripp adds the
# coincidence matrix and a bootstrap over units drawn from the shared seed.
# %% Data (missing ratings are kept: alpha uses every unit with two or more ratings)
raters <- c("rater_1", "rater_2", "rater_3", "rater 4")
kinds <- c(
"rater_1" = "numeric",
"rater_2" = "numeric",
"rater_3" = "numeric",
"rater 4" = "numeric"
)
stored <- list(
"rater_1" = NULL,
"rater_2" = NULL,
"rater_3" = NULL,
"rater 4" = NULL
)
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/s3_kripp.parquet", col_select = raters))
warnings <- list()
cs_check_finite_columns(df, raters) # infinite ratings stop the run (registry/errors.yaml)
if (length(unique(kinds)) > 1) stop("All raters must use the same kind of value (all numbers or all categories)")
numeric <- kinds[[1]] == "numeric"
cats <- NULL
if (numeric) {
x <- sapply(raters, function(r) as.double(df[[r]]))
x <- matrix(x, ncol = length(raters))
} else {
text <- function(v) ifelse(is.na(v), NA_character_, if (is.logical(v)) tolower(as.character(v)) else as.character(v))
cols <- lapply(raters, function(r) text(df[[r]]))
names(cols) <- raters
cats <- character(0)
for (r in raters) {
lv <- if (!is.null(stored[[r]])) stored[[r]] else sort(unique(stats::na.omit(cols[[r]])), method = "radix")
for (v in lv) if (!(v %in% cats)) cats <- c(cats, v) # stored order across raters
}
x <- sapply(raters, function(r) match(cols[[r]], cats) - 1)
x <- matrix(as.double(x), ncol = length(raters))
}
level <- "interval"
if (level == "auto") level <- if (numeric) "interval" else "nominal"
if (level %in% c("interval", "ratio") && !numeric) {
stop(sprintf("%s alpha needs numeric ratings; choose nominal or ordinal for categories", tools::toTitleCase(level)))
}
if (level == "ratio" && min(x, na.rm = TRUE) < 0) stop("Ratio alpha needs non-negative values")
# %% Krippendorff's alpha
conf <- 0.9
boot <- as.integer(500)
seed <- 42 # portable Wichmann–Hill stream: Python draws the same resamples for this seed
res <- cs_agree_kripp(x, level, boot = boot, seed = seed, conf = conf)
vals <- res$values
label <- function(v) {
if (!is.null(cats)) return(cats[v + 1])
if (v == round(v)) sprintf("%.0f", v) else formatC(v, digits = 15, format = "g")
}
labels <- vapply(vals, label, character(1))
units_total <- sum(rowSums(!is.na(x)) > 0)
has_ci <- boot > 0 && is.finite(res$ci_low)
na_unless <- function(v) if (has_ci) v else NA
values <- list(
alpha = res$alpha, do = res$do, de = res$de, ci_low = na_unless(res$ci_low), ci_high = na_unless(res$ci_high),
units = res$units, units_total = units_total, pairable = res$pairable, n_values = length(vals), raters = length(raters),
q_667 = na_unless(if (has_ci) unname(res$q[1]) else NA), q_800 = na_unless(if (has_ci) unname(res$q[2]) else NA)
)
n_c <- rowSums(res$o)
for (i in seq_along(vals)) values[[sprintf("n_value[%s]", labels[i])]] <- n_c[i]
# %% Assumptions
few <- res$pairable < 50 || res$units < 10
assumptions <- list(
list(key = "units", label = "Units with two or more ratings", status = if (few) "warn" else "pass",
detail = paste0(sprintf("%d of %d units have two or more ratings (%.0f pairable values)", res$units, units_total, res$pairable),
if (few) " — α is unstable with so few pairable values." else ".")),
list(key = "level", label = "Level of measurement", status = "info",
detail = paste0(sprintf("%s difference function over %d distinct values", tools::toTitleCase(level), length(vals)),
if (level == "ordinal") sprintf(" (category order: %s).", paste(labels, collapse = ", ")) else "."))
)
# %% Result
pct <- sprintf("%.0f%%", conf * 100)
k <- length(vals)
rows <- lapply(seq_len(k), function(i) {
r <- list(value = labels[i])
for (j in seq_len(k)) r[[sprintf("v%d", j - 1)]] <- res$o[i, j]
r$n <- n_c[i]
r
})
cols <- c(list(list(key = "value", label = "Value", type = "string")),
lapply(seq_len(k), function(j) list(key = sprintf("v%d", j - 1), label = labels[j], type = "number")),
list(list(key = "n", label = "Total", type = "number")))
flat_o <- as.vector(t(res$o))
stats_list <- list(list(key = "alpha", label = "α", value = res$alpha))
if (has_ci) stats_list <- c(stats_list, list(list(key = "ci", label = paste(pct, "CI"), value = c(res$ci_low, res$ci_high))))
stats_list <- c(stats_list, list(list(key = "do", label = "Observed disagreement Do", value = res$do),
list(key = "de", label = "Expected disagreement De", value = res$de)))
notes <- list(sprintf("%s α from the coincidence matrix (Krippendorff 2011); units with fewer than two ratings are left out.", tools::toTitleCase(level)))
if (has_ci) {
notes <- c(notes, sprintf("Percentile bootstrap over %d units, %d resamples, seed %s (the same resamples in Python and R). P(α < .667) = %.3f; P(α < .800) = %.3f.",
res$units, boot, seed, res$q[1], res$q[2]))
}
cs_publish(list(
method = "agreement.krippendorff",
methodVersion = "1.0.1",
title = "Krippendorff's alpha",
engine = cs_engine_info("stats", "codesplashr"),
n = res$units,
summary = paste0(sprintf("Krippendorff's α (%s) = %.3f", level, res$alpha),
if (has_ci) sprintf(", %s CI [%.3f, %.3f]", pct, res$ci_low, res$ci_high) else "",
sprintf(" for %d raters and %d units.", length(raters), res$units)),
apa = paste0(sprintf("Krippendorff's α = %s", cs_fmt_num(res$alpha, 2, leading_zero = FALSE)),
if (has_ci) sprintf(", %s CI [%s, %s]", pct, cs_fmt_num(res$ci_low), cs_fmt_num(res$ci_high)) else ""),
statistics = stats_list,
tables = list(list(key = "coincidences", title = "Coincidence matrix (pairable values)", columns = cols, rows = rows)),
effectSizes = list(list(key = "alpha", label = "Krippendorff's α", value = res$alpha, ciLow = na_unless(res$ci_low), ciHigh = na_unless(res$ci_high),
ciLevel = conf, method = if (has_ci) sprintf("percentile bootstrap over units (%d resamples)", boot) else "no interval")),
assumptions = assumptions,
warnings = warnings,
notes = notes,
charts = list(cs_chart("coincidences", "matrix-heatmap", "Coincidences of values", list(
row = cs_col("Value", rep(labels, each = k), "categorical", levels = labels),
col = cs_col("Paired with", rep(labels, times = k), "categorical", levels = labels),
value = cs_col("Coincidences", flat_o, "numeric"),
label = cs_col("Count", sprintf("%.1f", flat_o), "categorical")
), controls = list(scale = "sequential"))),
values = values
))
Krippendorff's α = .85, 90% CI [0.54, 0.99]
- α
- 0.8491
- 90% CI
- [0.5404, 0.9854]
- Observed disagreement Do
- 0.4333
- Expected disagreement De
- 2.872
Effect size
- Krippendorff's α 0.8491 90% CI [0.5404, 0.9854]
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Units with two or more ratings — 11 of 12 units have two or more ratings (40 pairable values) — α is unstable with so few pairable values.
- Level of measurement — Interval difference function over 5 distinct values.
Coincidence matrix (pairable values)
| Value | 1 | 2 | 3 | 4 | 5 | Total |
|---|---|---|---|---|---|---|
| 1 | 7 | 1.333 | 0.3333 | 0.3333 | 0 | 9.000 |
| 2 | 1.333 | 10 | 1.333 | 0.3333 | 0 | 13.000 |
| 3 | 0.3333 | 1.333 | 8 | 0.3333 | 0 | 10 |
| 4 | 0.3333 | 0.3333 | 0.3333 | 4 | 0 | 5 |
| 5 | 0 | 0 | 0 | 0 | 3 | 3 |
- Interval α from the coincidence matrix (Krippendorff 2011); units with fewer than two ratings are left out.
- Percentile bootstrap over 11 units, 500 resamples, seed 42 (the same resamples in Python and R). P(α < .667) = 0.144; P(α < .800) = 0.334.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Krippendorff's alpha (any number of raters, missing ratings)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method agreement.krippendorff 1.0.1 · spec eef779cdcc0f4084
# Dataset: s3_kripp (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import json
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.stats import agreement_adv as ag # Krippendorff's α (twin of R's cs_agree_kripp)
# krippendorff.alpha(reliability_data=x.T, level_of_measurement=level) computes the same α; the twin
# adds the coincidence matrix and a bootstrap over units drawn from the shared seed.
# %% Data (missing ratings are kept: α uses every unit with two or more ratings)
raters = ["rater_1", "rater_2", "rater_3", "rater 4"]
kinds = {"rater 4":"numeric","rater_1":"numeric","rater_2":"numeric","rater_3":"numeric"}
stored = json.loads("{\"rater 4\":null,\"rater_1\":null,\"rater_2\":null,\"rater_3\":null}")
df = pd.read_parquet("tests/parity/fixtures/s3_kripp.parquet", columns=raters)
warnings = []
cs.check_finite_columns(df, raters) # infinite ratings stop the run (registry/errors.yaml)
if len({kinds[r] for r in raters}) > 1:
raise ValueError("All raters must use the same kind of value (all numbers or all categories)")
numeric = kinds[raters[0]] == "numeric"
if numeric:
x = df[raters].to_numpy(dtype=float)
cats = None
else:
def text(s):
return [None if pd.isna(v) else (str(v).lower() if isinstance(v, (bool, np.bool_)) else str(v)) for v in s]
cols = {r: text(df[r]) for r in raters}
cats = []
for r in raters:
for v in stored[r] or sorted({v for v in cols[r] if v is not None}):
if v not in cats:
cats.append(v) # stored order across raters
pos = {c: i for i, c in enumerate(cats)}
x = np.column_stack([[pos[v] if v is not None else np.nan for v in cols[r]] for r in raters]).astype(float)
level = "interval"
if level == "auto":
level = "interval" if numeric else "nominal"
if level in ("interval", "ratio") and not numeric:
raise ValueError(f"{level.capitalize()} α needs numeric ratings; choose nominal or ordinal for categories")
if level == "ratio" and np.nanmin(x) < 0:
raise ValueError("Ratio α needs non-negative values")
# %% Krippendorff's alpha
conf = 0.9
boot = int(500)
seed = 42 # portable Wichmann–Hill stream: R draws the same resamples for this seed
res = ag.kripp_alpha(x, level, boot=boot, seed=seed, conf=conf)
vals = res["values"]
def label(v):
if cats is not None:
return cats[int(v)]
return f"{v:.0f}" if float(v).is_integer() else f"{v:.15g}"
labels = [label(v) for v in vals]
units_total = int(np.sum(np.sum(~np.isnan(x), axis=1) > 0))
has_ci = boot > 0 and np.isfinite(res["ci_low"])
values = {
"alpha": res["alpha"], "do": res["do"], "de": res["de"],
"ci_low": res["ci_low"] if has_ci else None, "ci_high": res["ci_high"] if has_ci else None,
"units": float(res["units"]), "units_total": float(units_total), "pairable": res["pairable"],
"n_values": float(len(vals)), "raters": float(len(raters)),
"q_667": res["q"][0.667] if has_ci else None, "q_800": res["q"][0.8] if has_ci else None,
}
n_c = res["o"].sum(axis=1)
for lb, nc in zip(labels, n_c):
values[f"n_value[{lb}]"] = float(nc)
# %% Assumptions
assumptions = [
{"key": "units", "label": "Units with two or more ratings", "status": "warn" if res["pairable"] < 50 or res["units"] < 10 else "pass",
"detail": f"{res['units']} of {units_total} units have two or more ratings ({res['pairable']:.0f} pairable values)"
+ (" — α is unstable with so few pairable values." if res["pairable"] < 50 or res["units"] < 10 else ".")},
{"key": "level", "label": "Level of measurement", "status": "info",
"detail": f"{level.capitalize()} difference function over {len(vals)} distinct values" + (f" (category order: {', '.join(labels)})." if level == "ordinal" else ".")},
]
# %% Result
pct = f"{conf:.0%}"
rows = [{"value": labels[i], **{f"v{j}": float(res["o"][i, j]) for j in range(len(vals))}, "n": float(n_c[i])} for i in range(len(vals))]
flat_o = [float(res["o"][i, j]) for i in range(len(vals)) for j in range(len(vals))]
stats_list = [{"key": "alpha", "label": "α", "value": res["alpha"]}]
if has_ci:
stats_list.append({"key": "ci", "label": f"{pct} CI", "value": [res["ci_low"], res["ci_high"]]})
stats_list += [{"key": "do", "label": "Observed disagreement Do", "value": res["do"]}, {"key": "de", "label": "Expected disagreement De", "value": res["de"]}]
notes = [f"{level.capitalize()} α from the coincidence matrix (Krippendorff 2011); units with fewer than two ratings are left out."]
if has_ci:
notes.append(f"Percentile bootstrap over {res['units']} units, {boot} resamples, seed {seed} (the same resamples in Python and R). "
f"P(α < .667) = {res['q'][0.667]:.3f}; P(α < .800) = {res['q'][0.8]:.3f}.")
cs.publish({
"method": "agreement.krippendorff",
"methodVersion": "1.0.1",
"title": "Krippendorff's alpha",
"engine": cs.engine_info("numpy", "codesplash"),
"n": int(res["units"]),
"summary": f"Krippendorff's α ({level}) = {res['alpha']:.3f}" + (f", {pct} CI [{res['ci_low']:.3f}, {res['ci_high']:.3f}]" if has_ci else "")
+ f" for {len(raters)} raters and {res['units']} units.",
"apa": f"Krippendorff's α = {cs.fmt_num(res['alpha'], 2, leading_zero=False)}" + (f", {pct} CI [{cs.fmt_num(res['ci_low'])}, {cs.fmt_num(res['ci_high'])}]" if has_ci else ""),
"statistics": stats_list,
"tables": [{"key": "coincidences", "title": "Coincidence matrix (pairable values)", "columns": [
{"key": "value", "label": "Value", "type": "string"},
*[{"key": f"v{j}", "label": labels[j], "type": "number"} for j in range(len(vals))],
{"key": "n", "label": "Total", "type": "number"},
], "rows": rows}],
"effectSizes": [{"key": "alpha", "label": "Krippendorff's α", "value": res["alpha"],
"ciLow": res["ci_low"] if has_ci else None, "ciHigh": res["ci_high"] if has_ci else None,
"ciLevel": conf, "method": f"percentile bootstrap over units ({boot} resamples)" if has_ci else "no interval"}],
"assumptions": assumptions,
"warnings": warnings,
"notes": notes,
"charts": [cs.chart("coincidences", "matrix-heatmap", "Coincidences of values", {
"row": cs.col("Value", [labels[i] for i in range(len(vals)) for _ in vals], "categorical", levels=labels),
"col": cs.col("Paired with", [labels[j] for _ in vals for j in range(len(vals))], "categorical", levels=labels),
"value": cs.col("Coincidences", flat_o, "numeric"),
"label": cs.col("Count", [f"{v:.1f}" for v in flat_o], "categorical"),
}, controls={"scale": "sequential"})],
"values": values,
})
Same statistic, two dialects
Readimport numpy as np
import pandas as pd
import krippendorff
df = pd.read_csv("s3_kripp.csv")
ratings = df[["rater_1", "rater_2", "rater_3", "rater 4"]]
print(krippendorff.alpha(reliability_data=ratings.to_numpy(dtype=float).T,
level_of_measurement="nominal"))library(irr)
df <- read.csv("s3_kripp.csv", check.names = FALSE)
m <- t(as.matrix(df[, c("rater_1", "rater_2", "rater_3", "rater 4")]))
kripp.alpha(m, method = "nominal")Check your understanding
CheckpointCheck yourself
Six clinicians rate 40 patients on a 5-point ordered scale. A few ratings are missing. Which method fits best?
Show the answer
Answer: b
Fleiss' kappa treats categories as nominal and expects the same number of ratings per subject. Krippendorff's alpha handles both order and missing ratings. Gwet's AC2 is a good alternative.
Check yourself
A team reports at the interval level for Likert ratings because it's higher than the ordinal value. What's the problem?
Show the answer
Answer: a
Choosing the level by result is a forking path. If the distances between points aren't equal, use ordinal.
Check yourself
= 0.85, with 35% of bootstrap resamples below 0.8. What should you say?
Show the answer
Answer: b
The estimate and its uncertainty both matter. A small study can't support a confident claim, whatever the point estimate.
Recap
Recap- Fleiss' kappa: several raters, nominal categories, the same number of ratings per subject.
- Krippendorff's alpha: any number of raters, missing ratings, any level of measurement.
- Choose the level from the scale, and report the interval, not only the estimate.
Concepts in this lesson