Skip to content

GAgreement & reliability · agreement.fleiss

Fleiss' kappa (several raters)

Do several raters assign the same categories more often than chance?

Chance-corrected agreement among two or more raters who classify every subject into nominal categories (Fleiss 1971). Reports the overall κ with the Fleiss–Nee–Landis test, a jackknife confidence interval, and κ for each category.

Verified in Python and R Python and R agree to 10 decimals

A real result

Example “Five raters”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Fleiss' kappaRecorded · Python and R agreeRecorded 2026-11-17 · 28 values compared
R

κ = .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

Category use by raterWhat do the values of a square or rectangular result matrix look like at a glance?
View data
CategoryShareRaterShare of subjects
none38%rater_a0.3758
mild30%rater_a0.2953
moderate22%rater_a0.2215
severe11%rater_a0.1074
none36%rater_b0.3624
mild31%rater_b0.3087
moderate20%rater_b0.2013
severe13%rater_b0.1275
none37%rater_c0.3691
mild34%rater_c0.3356
moderate18%rater_c0.1812
severe11%rater_c0.1141
none37%rater_d0.3691
mild36%rater_d0.3557
moderate17%rater_d0.1745
severe10%rater_d0.1007
none38%rater e0.3758
mild30%rater e0.2953
moderate21%rater e0.2148
severe11%rater e0.1141

Assumptions

  • Sample size — 149 subjects rated by 5 raters.
  • Category use — Every category has at least 5% of the ratings.

Agreement by category

CategoryShare of ratingsκzp
none37.0%0.654725.271< .001
mild31.8%0.412115.909< .001
moderate19.9%0.468818.096< .001
severe11.3%0.671325.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.
Python

κ = .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

CategoryShare of ratingsκzp
none37.0%0.654725.271< .001
mild31.8%0.412115.909< .001
moderate19.9%0.468818.096< .001
severe11.3%0.671325.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.

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Five ratersratings_sim · raters: rater_a, rater_b, rater_c, rater_d, rater e
  • Three ratersratings_sim · raters: rater_a, rater_b, rater_d
  • Two booleanratings_sim · raters: yes_a, yes_b
  • Degenerate n1ratings_sim · raters: rater_a, rater_b, rater_c, rater_d, rater e
  • Degenerate n2ratings_sim · raters: rater_a, rater_b, rater_c, rater_d, rater e

In the guides

Tests from the statistics guide this method runs

Where it sits in the decision guides

  • Categorical (> 2 raters): Fleiss' κ · Statistics Guide · G — Agreement / reliability

What you need

Raterscategorical / boolean · 2–50 columns · 2–30 levels
One column per rater with the category given to each subject (rows). Rows with a missing rating are left out.

Choices you make

hypothesis

Confidence leveldefault 0.95

How sure the intervals should be: 0.95 gives 95% confidence intervals. Higher confidence means wider intervals.

Checks and remedies

CodeSplash checks each testable assumption on every run and shows the result on the card; premises the data can’t test are marked. If a check fails, these are the ways forward.

  • Sample size

    The z test and jackknife interval need enough subjects.

  • Category use

    κ for a rarely used category is unstable.

What it reports

  • Tests: Agreement beyond chance (κ > 0)
kappa
Agreement between raters beyond what chance would produce; 0 is chance level, 1 is perfect.
ci_low
A range of effect values compatible with your data at the chosen confidence level.
ci_high
A range of effect values compatible with your data at the chosen confidence level.
se
The typical size of the error in an estimate, the standard deviation of its sampling distribution.
se0
The typical size of the error in an estimate, the standard deviation of its sampling distribution.
z
An estimate in standard-error units, compared with the standard normal distribution.
p
How surprising your data would be if the null hypothesis were true, as a probability.
po
Observed agreement is the share of ratings that match; chance agreement is the share expected to match anyway.
pe
Observed agreement is the share of ratings that match; chance agreement is the share expected to match anyway.
n
How many independent units the analysis used; it sets precision and power.
m
How many independent groups the result rests on, such as the studies in a multilevel meta-analysis.
k
How many groups, studies or clusters the analysis used. Many methods are less reliable when k is small.

Per group, level or term: kappa[<category>], z[<category>], p[<category>], prop[<category>]

Python and R

Python and R agree to 10 decimals (relative tolerance 1e-10). Python uses pandas, numpy, scipy, codesplash; R uses stats, nanoparquet, codesplashr.

Default traps between the two languages

  • Both engines use the same closed form (codesplash.stats.agreement.fleiss ↔ cs_fleiss): κ and the null SE as irr::kappam.fleiss; the interval uses a jackknife SE over subjects.
Python

The exact script CodeSplash ran for example “Five raters” · 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,
})
R

The exact script CodeSplash ran for example “Five raters” · 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
))

Sources

  • Fleiss, J. L. (1971). Measuring nominal scale agreement among many raters. Psychological Bulletin, 76, 378–382.
  • Fleiss, J. L., Nee, J. C. M., & Landis, J. R. (1979). Large sample variance of kappa in the case of different sets of raters. Psychological Bulletin, 86, 974–977.

From the CodeSplash method registry · agreement.fleiss v1.0.1.