Skip to content

Bland–Altman limits of agreement

Plot the differences against the means, read the bias and the limits, and decide if the methods can be swapped. That last decision isn't a statistical one.

Applied ~11 min8 steps

What runs in CodeSplash

You will be able to

  • Read the bias and limits of agreement from a Bland–Altman plot
  • Decide whether two methods are interchangeable against a pre-set limit
  • Recognize proportional bias and non-constant spread

Read first

01

Look at the differences

Read

Bland and Altman's plot has one idea: for each subject, plot the difference between the methods against their mean.

Three lines summarize it: the mean difference, called the bias, and the limits of agreementLimits of agreementThe range expected to hold 95% of differences between two measurement methods (bias ± 1.96 SD). on either side:

dˉ±1.96 sd\bar d \pm 1.96\, s_d

About 95% of differences should fall inside them, if the differences are roughly normal.

Bland–Altman plotDo two measurement methods agree, is there a bias, and does it change with the level measured?
View data
mean of methods (L/min)Wright − mini (L/min)
485.3035.700
588.8044.700
526.908
374−18.200
428.3050.300
256.3031.800
522.701.600
629.5022.900
332.2053.600
491.60109.90
600.1065.500
585.50−13
472.30−12.100
185.10−19.100
412.7059.500
420.30−6.800
543.2032.700
474.3033.900
230.4025
557.604.100
594.1015.200
243.803.900
601.6057.100
163.70−14.200
468.60−22.700
443.40−6.300
564.6035.300
337.50−7.400
594.6011.800
22456.100
600.5014.400
27241
198−76
264.10−19.200
488.201.300
55444.500
633.1035
525.30−33.900
495.80−18.100
606.9079.100
554.2016.700
622.5011.700
204.30−14.600
615.10−32.500
54542.800
597.5058.900
353.10−76.500
366.20−11.200
244.5052.400
522.5041.500
235.8024
340.606.700
439−26
476.50−2.600
264.70−69.200
301.9024.600
307.9021
331.4011.600
426.4043.200
28713.700

First 60 of 85 rows.

02

Build one

Explore

Add constant bias, then proportional bias, then more noise. See which line moves in each case.

GExplorable · Building a Bland–Altman plot

Why can two methods correlate highly and still disagree?

What is the correlation between the two methods?

0.25
How sure?
3.0
0.00
1.0
20.0
50

Method A against method B: r = 0.999

Difference against mean

meanlower limitupper limit

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

03

Can these meters be swapped?

Predict

Predict first

The Wright and Mini Wright peak-flow meters were used on 17 people. Their mean difference is −2.1 L/min, compared with typical readings around 450.

Would you let clinics swap them?

Yes: the average bias is tinyNo: individual readings differ too muchCan't say without a clinical limit
Reveal

Can't say without a clinical limit, though the numbers invite doubt. The limits run from −78 to 74 L/min. Statistics gives you the range. You need to decide in advance how wide is acceptable. Bias alone can't answer this: a small average can hide large individual gaps.

04

Read the card

In the app

The card gives the bias with its interval, a t test of zero bias, the limits with their own intervals, and a proportional-bias check.

Bland–Altman: wright vs mini wrightRecorded · Python and R agreeRecorded 2026-11-17 · 23 values compared · largest relative difference 1.5e-12
R

bias = −2.12, 95% CI [−22.05, 17.81]; limits of agreement −78.10 to 73.86

Bias (A − B)
−2.118
p (bias = 0)
.825
95% limits of agreement
[−78.096, 73.861]
SD of differences
38.765

Plots

Bland–Altman plotDo two measurement methods agree, is there a bias, and does it change with the level measured?
View data
wright − mini wrightMean of wright and mini wright
−18503
−35412.50
−4518
6431
−24488
−43578.50
49388.50
62411
−8654
−12439
−15424.50
30641
7263.50
1477.50
−81218.50
73386.50
−24439

Assumptions

  • Normal differences — Shapiro–Wilk on A − B: p = .593.
  • No proportional bias — Slope of differences on means = 0.029, p = .749.
  • Sample size — 17 pairs — the limits of agreement are imprecise (wide intervals).

Bias and limits of agreement

Estimate95% CI low95% CI high
Bias (mean difference)−2.118−22.04917.814
Lower limit (bias − 1.96 SD)−78.096−124.16−53.095
Upper limit (bias + 1.96 SD)73.86148.860119.93

Intervals for the limits: exact (Carkeet 2015).

  • Differences are wright − mini wright; means are their average. Whether the limits are acceptable is a clinical judgment.
The exact R script · R R version 4.5.1 (2025-06-13)
# Bland–Altman limits of agreement
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method agreement.bland_altman 1.0.1 · spec 2a6596a4d95bbfd6
# Dataset: pefr (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/pefr.parquet", col_select = c("wright", "mini wright")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("wright", "mini wright")]), , 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("wright", "mini wright"))  # infinite values stop the run (registry/errors.yaml)

# %% Differences
a_name <- "wright"
b_name <- "mini wright"
a <- as.numeric(df[[a_name]])
b <- as.numeric(df[[b_name]])
d <- a - b  # differences A − B
m <- (a + b) / 2
n <- length(d)
cs_check_rows(n, 3, "Bland–Altman analysis")  # needs at least three pairs
loa_level <- 0.95
conf <- 0.95
gam <- 1 - conf
zp <- stats::qnorm(1 - (1 - loa_level) / 2)  # 1.96 for 95% limits

# %% Bias and limits of agreement
tt <- t.test(d, conf.level = conf)
bias <- mean(d)
sd_d <- sd(d)
tq <- stats::qt(1 - gam / 2, n - 1)
se_bias <- sd_d / sqrt(n)
loa_low <- bias - zp * sd_d
loa_high <- bias + zp * sd_d
if ("exact" == "exact") {
  # Carkeet (2015): the limits are normal quantiles; their CIs invert the noncentral t (ncp = z√n)
  lo_q <- stats::qt(gam / 2, n - 1, ncp = zp * sqrt(n))
  hi_q <- stats::qt(1 - gam / 2, n - 1, ncp = zp * sqrt(n))
  up_ci <- c(bias + sd_d * lo_q / sqrt(n), bias + sd_d * hi_q / sqrt(n))
  low_ci <- c(bias - sd_d * hi_q / sqrt(n), bias - sd_d * lo_q / sqrt(n))
  ci_label <- "exact (Carkeet 2015)"
} else {
  se_loa <- sd_d * sqrt(1 / n + zp^2 / (2 * (n - 1)))  # Bland & Altman (1999)
  up_ci <- c(loa_high - tq * se_loa, loa_high + tq * se_loa)
  low_ci <- c(loa_low - tq * se_loa, loa_low + tq * se_loa)
  ci_label <- "approximate (Bland & Altman 1999)"
}

# %% Proportional bias: regression of the differences on the means
slope <- slope_lo <- slope_hi <- slope_p <- intercept <- NA
if (TRUE) {
  fit <- lm(d ~ m)
  cf <- summary(fit)$coefficients
  ci <- confint(fit, level = conf)
  slope <- cf[2, 1]; intercept <- cf[1, 1]; slope_p <- cf[2, 4]
  slope_lo <- ci[2, 1]; slope_hi <- ci[2, 2]
}
sw_p <- if (n >= 3 && n <= 5000) shapiro.test(d)$p.value else NA

values <- list(n = n, bias = bias, bias_low = tt$conf.int[1], bias_high = tt$conf.int[2], sd_diff = sd_d,
               loa_low = loa_low, loa_high = loa_high, loa_low_ci_low = low_ci[1], loa_low_ci_high = low_ci[2],
               loa_high_ci_low = up_ci[1], loa_high_ci_high = up_ci[2], t = unname(tt$statistic), df = n - 1, p = tt$p.value,
               slope = slope, slope_low = slope_lo, slope_high = slope_hi, slope_p = slope_p, intercept = intercept,
               sw_p = sw_p, mean_a = mean(a), mean_b = mean(b), z_loa = zp)

# %% Assumptions
assumptions <- list(
  list(key = "normality", label = "Normal differences", status = if (is.na(sw_p)) "info" else if (sw_p < 0.05) "warn" else "pass", p = sw_p,
       detail = if (is.na(sw_p)) "Too many pairs for Shapiro–Wilk; inspect the histogram of differences."
                else paste0(sprintf("Shapiro–Wilk on A − B: %s", cs_fmt_p(sw_p)),
                            if (sw_p < 0.05) " — consider log-transformed (ratio) differences or nonparametric limits." else ".")),
  list(key = "proportional_bias", label = "No proportional bias", status = if (is.na(slope)) "info" else if (slope_p < 0.05) "warn" else "pass",
       p = slope_p,
       detail = if (is.na(slope)) "Not tested." else paste0(sprintf("Slope of differences on means = %.3f, %s", slope, cs_fmt_p(slope_p)),
                                                          if (slope_p < 0.05) " — the bias changes with the measurement level; consider regression-based limits." else ".")),
  list(key = "sample_size", label = "Sample size", status = if (n < 50) "warn" else "pass",
       detail = paste0(sprintf("%d pairs", n), if (n < 50) " — the limits of agreement are imprecise (wide intervals)." else "."))
)

# %% Result
pct <- sprintf("%.0f%%", conf * 100)
cover <- sprintf("%.0f%%", loa_level * 100)
take <- if (n <= 5000) seq_len(n) else unique(round(seq(1, n, length.out = 5000)))
controls <- list(bias = bias, lower = loa_low, upper = loa_high, biasLow = values$bias_low, biasHigh = values$bias_high,
                 lowerLow = low_ci[1], lowerHigh = low_ci[2], upperLow = up_ci[1], upperHigh = up_ci[2])
if (!is.na(slope) && slope_p < 0.05) controls <- c(controls, list(slope = slope, intercept = intercept))
cs_publish(list(
  method = "agreement.bland_altman",
  methodVersion = "1.0.1",
  title = sprintf("Bland–Altman: %s vs %s", a_name, b_name),
  engine = cs_engine_info("stats"),
  n = n,
  summary = sprintf("Bias (A − B) = %s, %s CI [%s, %s]; %s limits of agreement %s to %s.", format(signif(bias, 3)), pct,
                    format(signif(values$bias_low, 3)), format(signif(values$bias_high, 3)), cover, format(signif(loa_low, 3)), format(signif(loa_high, 3))),
  apa = sprintf("bias = %s, %s CI [%s, %s]; limits of agreement %s to %s", cs_fmt_num(bias), pct, cs_fmt_num(values$bias_low),
                cs_fmt_num(values$bias_high), cs_fmt_num(loa_low), cs_fmt_num(loa_high)),
  statistics = list(list(key = "bias", label = "Bias (A − B)", value = bias), list(key = "p", label = "p (bias = 0)", value = values$p, format = "p"),
                    list(key = "loa", label = paste(cover, "limits of agreement"), value = c(loa_low, loa_high)),
                    list(key = "sd_diff", label = "SD of differences", value = sd_d)),
  tables = list(list(key = "agreement", title = "Bias and limits of agreement", columns = list(
    list(key = "quantity", label = "", type = "string"), list(key = "estimate", label = "Estimate", type = "number"),
    list(key = "lower", label = paste(pct, "CI low"), type = "number"), list(key = "upper", label = paste(pct, "CI high"), type = "number")
  ), rows = list(
    list(quantity = "Bias (mean difference)", estimate = bias, lower = values$bias_low, upper = values$bias_high),
    list(quantity = sprintf("Lower limit (bias − %.2f SD)", zp), estimate = loa_low, lower = low_ci[1], upper = low_ci[2]),
    list(quantity = sprintf("Upper limit (bias + %.2f SD)", zp), estimate = loa_high, lower = up_ci[1], upper = up_ci[2])
  ), note = sprintf("Intervals for the limits: %s.", ci_label))),
  assumptions = assumptions,
  warnings = warnings,
  notes = list(sprintf("Differences are %s − %s; means are their average. Whether the limits are acceptable is a clinical judgment.", a_name, b_name)),
  charts = list(cs_chart("ba", "bland-altman", "Bland–Altman plot", list(
    mean = cs_col(sprintf("Mean of %s and %s", a_name, b_name), m[take], "numeric"),
    diff = cs_col(sprintf("%s − %s", a_name, b_name), d[take], "numeric")
  ), controls = controls)),
  values = values
))
Python

bias = −2.12, 95% CI [−22.05, 17.81]; limits of agreement −78.10 to 73.86

Bias (A − B)
−2.118
p (bias = 0)
.825
95% limits of agreement
[−78.096, 73.861]
SD of differences
38.765

To keep this page light, the plots are shown once, under the R tab.

Assumptions

  • Normal differences — Shapiro–Wilk on A − B: p = .593.
  • No proportional bias — Slope of differences on means = 0.029, p = .749.
  • Sample size — 17 pairs — the limits of agreement are imprecise (wide intervals).

Bias and limits of agreement

Estimate95% CI low95% CI high
Bias (mean difference)−2.118−22.04917.814
Lower limit (bias − 1.96 SD)−78.096−124.16−53.095
Upper limit (bias + 1.96 SD)73.86148.860119.93

Intervals for the limits: exact (Carkeet 2015).

  • Differences are wright − mini wright; means are their average. Whether the limits are acceptable is a clinical judgment.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Bland–Altman limits of agreement
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method agreement.bland_altman 1.0.1 · spec 2a6596a4d95bbfd6
# Dataset: pefr (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import math

import numpy as np
import pandas as pd
from scipy import stats

import codesplash as cs

# %% Data
df = pd.read_parquet("tests/parity/fixtures/pefr.parquet", columns=["wright", "mini wright"])
n_input = len(df)
df = df.dropna(subset=["wright", "mini wright"])  # listwise deletion over the analysis columns
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, ["wright", "mini wright"])  # infinite values stop the run (registry/errors.yaml)

# %% Differences
a_name, b_name = "wright", "mini wright"
a = df[a_name].to_numpy(dtype=float)
b = df[b_name].to_numpy(dtype=float)
d = a - b  # differences A − B
m = (a + b) / 2
n = len(d)
cs.check_rows(n, 3, "Bland–Altman analysis")  # needs at least three pairs
loa_level = 0.95
conf = 0.95
gam = 1 - conf
zp = stats.norm.ppf(1 - (1 - loa_level) / 2)  # 1.96 for 95% limits

# %% Bias and limits of agreement
bias = float(d.mean())
sd = float(d.std(ddof=1))
tq = stats.t.ppf(1 - gam / 2, n - 1)
se_bias = sd / math.sqrt(n)
t_stat = bias / se_bias
p = float(2 * stats.t.sf(abs(t_stat), n - 1))
loa_low, loa_high = bias - zp * sd, bias + zp * sd
if "exact" == "exact":
    # Carkeet (2015): the limits are normal quantiles; their CIs invert the noncentral t (ncp = z√n)
    lo_q = stats.nct.ppf(gam / 2, n - 1, zp * math.sqrt(n))
    hi_q = stats.nct.ppf(1 - gam / 2, n - 1, zp * math.sqrt(n))
    up_ci = (bias + sd * lo_q / math.sqrt(n), bias + sd * hi_q / math.sqrt(n))
    low_ci = (bias - sd * hi_q / math.sqrt(n), bias - sd * lo_q / math.sqrt(n))
    ci_label = "exact (Carkeet 2015)"
else:
    se_loa = sd * math.sqrt(1 / n + zp**2 / (2 * (n - 1)))  # Bland & Altman (1999)
    up_ci = (loa_high - tq * se_loa, loa_high + tq * se_loa)
    low_ci = (loa_low - tq * se_loa, loa_low + tq * se_loa)
    ci_label = "approximate (Bland & Altman 1999)"

# %% Proportional bias: regression of the differences on the means
slope = slope_lo = slope_hi = slope_p = intercept = None
if True:
    reg = stats.linregress(m, d)
    tq2 = stats.t.ppf(1 - gam / 2, n - 2)
    slope, intercept, slope_p = float(reg.slope), float(reg.intercept), float(reg.pvalue)
    slope_lo, slope_hi = slope - tq2 * reg.stderr, slope + tq2 * reg.stderr
sw_p = float(stats.shapiro(d).pvalue) if 3 <= n <= 5000 else None

values = {"n": float(n), "bias": bias, "bias_low": bias - tq * se_bias, "bias_high": bias + tq * se_bias, "sd_diff": sd,
          "loa_low": loa_low, "loa_high": loa_high, "loa_low_ci_low": low_ci[0], "loa_low_ci_high": low_ci[1],
          "loa_high_ci_low": up_ci[0], "loa_high_ci_high": up_ci[1], "t": t_stat, "df": float(n - 1), "p": p,
          "slope": slope, "slope_low": slope_lo, "slope_high": slope_hi, "slope_p": slope_p, "intercept": intercept,
          "sw_p": sw_p, "mean_a": float(a.mean()), "mean_b": float(b.mean()), "z_loa": float(zp)}

# %% Assumptions
assumptions = [
    {"key": "normality", "label": "Normal differences", "status": "info" if sw_p is None else ("warn" if sw_p < 0.05 else "pass"), "p": sw_p,
     "detail": "Too many pairs for Shapiro–Wilk; inspect the histogram of differences." if sw_p is None else
     f"Shapiro–Wilk on A − B: {cs.fmt_p(sw_p)}" + (" — consider log-transformed (ratio) differences or nonparametric limits." if sw_p < 0.05 else ".")},
    {"key": "proportional_bias", "label": "No proportional bias",
     "status": "info" if slope is None else ("warn" if slope_p < 0.05 else "pass"), "p": slope_p,
     "detail": "Not tested." if slope is None else f"Slope of differences on means = {slope:.3f}, {cs.fmt_p(slope_p)}"
     + (" — the bias changes with the measurement level; consider regression-based limits." if slope_p < 0.05 else ".")},
    {"key": "sample_size", "label": "Sample size", "status": "warn" if n < 50 else "pass",
     "detail": f"{n} pairs" + (" — the limits of agreement are imprecise (wide intervals)." if n < 50 else ".")},
]

# %% Result
pct, cover = f"{conf:.0%}", f"{loa_level:.0%}"
take = np.arange(n) if n <= 5000 else np.unique(np.round(np.linspace(0, n - 1, 5000)).astype(int))
controls = {"bias": bias, "lower": loa_low, "upper": loa_high, "biasLow": values["bias_low"], "biasHigh": values["bias_high"],
            "lowerLow": low_ci[0], "lowerHigh": low_ci[1], "upperLow": up_ci[0], "upperHigh": up_ci[1]}
if slope is not None and slope_p < 0.05:
    controls.update({"slope": slope, "intercept": intercept})
cs.publish({
    "method": "agreement.bland_altman",
    "methodVersion": "1.0.1",
    "title": f"Bland–Altman: {a_name} vs {b_name}",
    "engine": cs.engine_info("numpy", "scipy"),
    "n": int(n),
    "summary": f"Bias (A − B) = {bias:.3g}, {pct} CI [{values['bias_low']:.3g}, {values['bias_high']:.3g}]; {cover} limits of agreement {loa_low:.3g} to {loa_high:.3g}.",
    "apa": f"bias = {cs.fmt_num(bias)}, {pct} CI [{cs.fmt_num(values['bias_low'])}, {cs.fmt_num(values['bias_high'])}]; limits of agreement {cs.fmt_num(loa_low)} to {cs.fmt_num(loa_high)}",
    "statistics": [{"key": "bias", "label": "Bias (A − B)", "value": bias}, {"key": "p", "label": "p (bias = 0)", "value": p, "format": "p"},
                   {"key": "loa", "label": f"{cover} limits of agreement", "value": [loa_low, loa_high]}, {"key": "sd_diff", "label": "SD of differences", "value": sd}],
    "tables": [{"key": "agreement", "title": "Bias and limits of agreement", "columns": [
        {"key": "quantity", "label": "", "type": "string"}, {"key": "estimate", "label": "Estimate", "type": "number"},
        {"key": "lower", "label": f"{pct} CI low", "type": "number"}, {"key": "upper", "label": f"{pct} CI high", "type": "number"},
    ], "rows": [
        {"quantity": "Bias (mean difference)", "estimate": bias, "lower": values["bias_low"], "upper": values["bias_high"]},
        {"quantity": f"Lower limit (bias − {zp:.2f} SD)", "estimate": loa_low, "lower": low_ci[0], "upper": low_ci[1]},
        {"quantity": f"Upper limit (bias + {zp:.2f} SD)", "estimate": loa_high, "lower": up_ci[0], "upper": up_ci[1]},
    ], "note": f"Intervals for the limits: {ci_label}."}],
    "assumptions": assumptions,
    "warnings": warnings,
    "notes": [f"Differences are {a_name} − {b_name}; means are their average. Whether the limits are acceptable is a clinical judgment."],
    "charts": [cs.chart("ba", "bland-altman", "Bland–Altman plot", {
        "mean": cs.col(f"Mean of {a_name} and {b_name}", m[take], "numeric"),
        "diff": cs.col(f"{a_name} − {b_name}", d[take], "numeric"),
    }, controls=controls)],
    "values": values,
})

With only 17 people the limits are themselves uncertain. The upper limit could be anywhere from 49 to 120. Use the worst plausible limit when you decide. The option Interval for the limits chooses exact or approximate intervals.

05

Three things to check in the plot

Read
  • Fan shape: differences widen as the mean grows. Try ratios or a log scale, then read the limits as percentages.
  • A sloped band: one method reads progressively higher. That's proportional bias, which the card tests: here p = .749. If it's real, the regression methods of the next lesson are a better fit.
  • Outliers: a single subject can stretch the limits a long way. Check them before you trust the range.
06

Same plot, two dialects

Read
Python
import numpy as np
import pandas as pd

df = pd.read_csv("pefr.csv")
d = df["wright"] - df["mini wright"]
bias, sd = d.mean(), d.std(ddof=1)
print(bias, bias - 1.96 * sd, bias + 1.96 * sd)
R
df <- read.csv("pefr.csv", check.names = FALSE)
d <- df$wright - df[["mini wright"]]
c(bias = mean(d), low = mean(d) - 1.96 * sd(d), high = mean(d) + 1.96 * sd(d))
07

Check your understanding

Checkpoint

Check yourself

The mean difference is 6 and the standard deviation of differences is 10. Using 2 in place of 1.96, what is the upper limit of agreement?

Show the answer

Answer: 26

6+2×10=266 + 2 \times 10 = 26.

Check yourself

A paired t test finds no significant difference between two methods (p = 0.8). What does that show?

Show the answer

Answer: b

A paired test looks at the mean. Two methods can have no average bias and still disagree widely on individuals.

Check yourself

Who should set the limit that counts as "close enough", and when?

Show the answer

Answer: a

Whether a difference matters depends on what it would change in practice. Setting the limit afterwards invites fitting it to the result.

08

Recap

Recap
  • Plot differences against means, and read the bias and the limits of agreement.
  • Whether methods can be swapped is a practical judgment, made against a limit set in advance.
  • Check for fans, slopes and outliers.
  • A paired test or a correlation doesn't answer this question.

Concepts in this lesson