Skip to content

Comparing a new method to a reference

Both instruments have error, so ordinary regression is biased here. Use Deming or Passing–Bablok, and read the intercept and slope as constant and proportional bias.

Advanced ~12 min10 steps

What runs in CodeSplash

You will be able to

  • Explain why ordinary least squares misleads when both methods have error
  • Read constant and proportional bias from the intercept and slope intervals
  • Choose among Passing–Bablok, Deming and weighted Deming

Read first

01

Error on both sides

Read

Ordinary regression assumes xx is measured perfectly. In a method comparison, neither instrument is perfect. Error in xx pulls the OLS slope toward zero, so you can find "proportional bias" where there's none.

Two methods avoid this:

  • Deming regressionDeming regressionA straight line fitted allowing for measurement error in both methods, given the ratio of their error variances (1 = equally precise). allows error in both, given the ratio of their error variances, λ\lambda.
  • Passing–BablokPassing–Bablok regressionA rank-based line through two methods' readings (median of pairwise slopes) that allows for error in both and resists outliers. uses the median of all pairwise slopes. It needs no distribution and resists outliers.
02

Read the line

Read

If the methods agree, the line is y=xy = x: slope 1, intercept 0.

  • Intercept interval excludes 0: constant biasConstant and proportional differenceA constant difference shifts every reading by the same amount (intercept ≠ 0); a proportional one grows with the level (slope ≠ 1)..
  • Slope interval excludes 1: proportional bias.
03

Predict the verdict

Predict

Predict first

A new assay is compared with a reference on 80 samples. Passing–Bablok gives intercept 0.37 (95% interval 0.12 to 0.63), and slope 0.987 (0.966 to 1.007).

What do these intervals show?

Constant bias onlyProportional bias onlyBothNeither
Reveal

Constant bias only. The intercept's interval excludes 0, so the new assay reads a fixed amount high. The slope's interval includes 1, so these data are compatible with no proportional bias. Decide whether that offset matters in practice. A fixed offset can often be calibrated out.

04

Check linearity first

In the app

Straight-line methods assume a straight relation. The CUSUM test checks this for Passing–Bablok.

For the first assay, p = .576: no sign of curvature. For a second version that really is curved, p < .001. Its slope of 1.47 doesn't describe anything well.

Method comparison (Passing–Bablok)Recorded · Python and R agreeRecorded 2026-11-17 · 19 values compared
R

Passing–Bablok regression: slope = 1.467, 90% CI [1.397, 1.542]; intercept = −1.687, 90% CI [−2.272, −1.240]

Slope
1.467
Intercept
−1.687
Linearity p (CUSUM)
< .001

Plots

new_curved against reference_cvHow close are a regression model's predictions to the true values, and where does it miss?
View data
new_curvedreference_cv
21.92915.939
12.00010.789
2.3923.015
4.6344.358
13.21610.436
2.6072.309
9.0547.941
40.31125.756
4.8744.241
14.18512.147
2.3321.965
21.02116.388
4.4473.899
37.74625.077
4.2183.126
6.4296.006
12.53610.491
1.5432.094
5.5735.403
2.4982.288
6.2425.580
6.3275.028
3.8143.927
2.7162.329
7.6216.798
3.0653.647
8.0306.689
3.2342.945
1.8222.073
15.18512.471
48.67230.342
4.4423.438
23.32718.235
2.3182.130
14.16611.312
7.7167.374
4.1723.416
9.5878.559
27.16519.500
8.3498.253
7.3556.145
42.82127.609
8.0117.705
8.5187.695
2.3242.556
1.5172.217
53.93532.481
5.9284.627
11.3269.943
3.8223.973
63.99336.325
16.44713.669
60.45934.736
45.00228.340
11.50210.174
22.88516.645
25.58818.225
2.8282.433
60.26834.766
3.8713.573

First 60 of 80 rows.

Distance from the Passing–Bablok lineHow do two numeric variables move together?
View data
reference_cvnew_curved − (-1.69 + 1.47·reference_cv)
15.9390.2370
10.789−2.139
3.015−0.3441
4.358−0.0710
10.436−0.4039
2.3090.9074
7.941−0.9068
25.7564.220
4.2410.3402
12.147−1.946
1.9651.136
16.388−1.329
3.8990.4150
25.0772.651
3.1261.320
6.006−0.6943
10.491−1.165
2.0940.1590
5.403−0.6653
2.2880.8275
5.580−0.2558
5.0280.6380
3.927−0.2598
2.3290.9865
6.798−0.6630
3.647−0.5974
6.689−0.0938
2.9450.6016
2.0730.4681
12.471−1.421
30.3425.854
3.4381.086
18.235−1.733
2.1300.8804
11.312−0.7401
7.374−1.413
3.4160.8473
8.559−1.281
19.5000.2501
8.253−2.069
6.1450.0286
27.6094.011
7.705−1.603
7.695−1.083
2.5560.2610
2.217−0.0481
32.4817.979
4.6270.8288
9.943−1.571
3.973−0.3186
36.32512.399
13.669−1.916
34.73611.196
28.3405.120
10.174−1.735
16.6450.1566
18.2250.5424
2.4330.9470
34.76610.960
3.5730.3171

First 60 of 80 rows.

Assumptions

  • Strong positive relation between the methods — Pearson r = 0.992; Passing–Bablok assumes highly correlated, linearly related readings.
  • Linear relation (CUSUM test) — H = 2.499, p = 7.54e-06 (1.36 is the 5 % critical value).
  • Enough samples (≥ 40 recommended) — 80 pairs.

Passing–Bablok regression of new_curved on reference_cv

EstimateSE (jackknife)90% CI low90% CI highIdentity value inside the CI?
Slope1.467—1.3971.542no (proportional difference)
Intercept−1.687—−2.272−1.240no (constant difference)

Confidence limits from the ordered pairwise slopes (Passing & Bablok 1983).

  • The methods agree when the slope interval contains 1 and the intercept interval contains 0. Ordinary least squares is not used: it assumes reference_cv is measured without error and biases the slope towards 0.
  • Passing–Bablok is robust to outliers and needs no error-variance ratio; Deming assumes normal errors with a known ratio; weighted Deming suits errors that grow with the level (constant CV).
The exact R script · R R version 4.5.1 (2025-06-13)
# Method comparison regression (Passing–Bablok, Deming)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method agreement.method_comparison 1.0.2 · spec 8a2bf1f0f7f909ef
# Dataset: c3_methcomp (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr) # cs_passing_bablok, cs_cusum_linearity, cs_deming (twins of codesplash.stats.method_comparison)

# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/c3_methcomp.parquet", col_select = c("reference_cv", "new_curved")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("reference_cv", "new_curved")]), , 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("reference_cv", "new_curved"))  # infinite values stop the run (registry/errors.yaml)

# %% Regression
xr <- "reference_cv"
yr <- "new_curved"
x <- as.numeric(df[[xr]])
y <- as.numeric(df[[yr]])
n <- length(x)
regression <- "passing_bablok"
lam <- 1
conf <- 0.9
linearity <- TRUE
cs_check_rows(n, 3, "Method comparison")  # needs at least three pairs of readings
# A method with one reading for every sample leaves the slope undefined (no variation to regress on).
cs_check_not_constant(x, xr)
cs_check_not_constant(y, yr)
if (regression == "passing_bablok") {
  fit <- cs_passing_bablok(x, y, conf)
  label <- "Passing–Bablok"
} else if (regression == "weighted_deming") {
  if (any(x <= 0) || any(y <= 0)) stop("Weighted Deming regression (constant CV) needs positive readings from both methods")
  fit <- cs_deming(x, y, lam, weighted = TRUE, conf = conf)
  label <- "Weighted Deming"
} else {
  fit <- cs_deming(x, y, lam, weighted = FALSE, conf = conf)
  label <- "Deming"
}
a <- fit$intercept
b <- fit$slope
cus <- if (linearity && regression == "passing_bablok") cs_cusum_linearity(x, y, a, b) else NULL
num_or_null <- function(v) if (is.null(v) || !is.finite(v)) NULL else v
constant_bias <- is.finite(fit$intercept_low) && is.finite(fit$intercept_high) && (fit$intercept_low > 0 || fit$intercept_high < 0)
proportional_bias <- is.finite(fit$slope_low) && is.finite(fit$slope_high) && (fit$slope_low > 1 || fit$slope_high < 1)
pct <- sprintf("%.0f%%", conf * 100)

# %% Assumptions
assumptions <- list()
if (regression == "passing_bablok") {
  rr <- stats::cor(x, y)
  assumptions[[length(assumptions) + 1]] <- list(key = "correlation", label = "Strong positive relation between the methods",
    status = if (rr > 0.5) "pass" else "warn",
    detail = sprintf("Pearson r = %.3f; Passing–Bablok assumes highly correlated, linearly related readings.", rr))
  if (!is.null(cus) && !is.finite(cus$p)) {
    # The CUSUM test needs residuals on both sides of the line (and a nonzero slope).
    assumptions[[length(assumptions) + 1]] <- list(key = "linearity", label = "Linear relation (CUSUM test)", status = "info",
      detail = "The CUSUM test needs points above and below the fitted line; it can't be computed here.")
  } else if (!is.null(cus)) {
    assumptions[[length(assumptions) + 1]] <- list(key = "linearity", label = "Linear relation (CUSUM test)", status = if (cus$p < 0.05) "fail" else "pass",
      detail = sprintf("H = %.3f, p = %.3g (1.36 is the 5 %% critical value).", cus$h, cus$p))
  }
} else {
  assumptions[[length(assumptions) + 1]] <- list(key = "error_ratio", label = "Error-variance ratio known", status = "info",
    detail = sprintf("λ = Var(error in %s) / Var(error in %s) = %s; estimate it from replicate measurements.", yr, xr, format(lam)))
}
assumptions[[length(assumptions) + 1]] <- list(key = "sample_size", label = "Enough samples (≥ 40 recommended)", status = if (n < 40) "warn" else "pass",
  detail = sprintf("%d pairs%s", n, if (n < 40) "; intervals are wide and the linearity test has little power." else "."))

# %% Result
values <- list(
  n = n, regression = regression, slope = b, slope_low = num_or_null(fit$slope_low), slope_high = num_or_null(fit$slope_high),
  intercept = a, intercept_low = num_or_null(fit$intercept_low), intercept_high = num_or_null(fit$intercept_high),
  slope_se = num_or_null(fit$slope_se), intercept_se = num_or_null(fit$intercept_se),
  error_ratio = if (regression != "passing_bablok") lam else NULL, iterations = if (regression == "weighted_deming") fit$iterations else NULL,
  constant_bias = constant_bias, proportional_bias = proportional_bias,
  cusum_h = if (is.null(cus)) NULL else num_or_null(cus$h), cusum_p = if (is.null(cus)) NULL else num_or_null(cus$p),
  cusum_n_above = if (is.null(cus)) NULL else cus$n_above, cusum_n_below = if (is.null(cus)) NULL else cus$n_below,
  mean_difference = mean(y - x)
)
resid <- y - a - b * x
take <- unique(round(seq(1, n, length.out = min(n, 5000))))
flags <- c(constant_bias, proportional_bias)
verdict <- if (!any(flags)) "no constant or proportional difference" else paste(c("a constant difference", "a proportional difference")[flags], collapse = " and ")
cs_publish(list(
  method = "agreement.method_comparison",
  methodVersion = "1.0.2",
  title = sprintf("Method comparison (%s)", label),
  engine = cs_engine_info("stats", "nanoparquet"),
  n = n,
  summary = sprintf("%s: %s = %.4g + %.4g × %s; slope %s CI [%.4g, %.4g], intercept %s CI [%.4g, %.4g] — %s.",
                    label, yr, a, b, xr, pct, fit$slope_low, fit$slope_high, pct, fit$intercept_low, fit$intercept_high, verdict),
  apa = sprintf("%s regression: slope = %s, %s CI [%s, %s]; intercept = %s, %s CI [%s, %s]", label, cs_fmt_num(b, 3), pct,
                cs_fmt_num(fit$slope_low, 3), cs_fmt_num(fit$slope_high, 3), cs_fmt_num(a, 3), pct, cs_fmt_num(fit$intercept_low, 3),
                cs_fmt_num(fit$intercept_high, 3)),
  statistics = c(list(list(key = "slope", label = "Slope", value = b), list(key = "intercept", label = "Intercept", value = a)),
                 if (!is.null(cus)) list(list(key = "cusum_p", label = "Linearity p (CUSUM)", value = values$cusum_p, format = "p"))),
  tables = list(list(key = "coefficients", title = sprintf("%s regression of %s on %s", label, yr, xr), columns = list(
      list(key = "term", label = "", type = "string"), list(key = "estimate", label = "Estimate", type = "number"),
      list(key = "se", label = "SE (jackknife)", type = "number"), list(key = "low", label = sprintf("%s CI low", pct), type = "number"),
      list(key = "high", label = sprintf("%s CI high", pct), type = "number"), list(key = "reading", label = "Identity value inside the CI?", type = "string")),
    rows = list(list(term = "Slope", estimate = b, se = values$slope_se, low = values$slope_low, high = values$slope_high,
                     reading = if (proportional_bias) "no (proportional difference)" else "yes (1)"),
                list(term = "Intercept", estimate = a, se = values$intercept_se, low = values$intercept_low, high = values$intercept_high,
                     reading = if (constant_bias) "no (constant difference)" else "yes (0)")),
    note = if (regression == "passing_bablok") "Confidence limits from the ordered pairwise slopes (Passing & Bablok 1983)."
           else sprintf("Jackknife standard errors (Linnet 1990), t with %d df.", n - 2))),
  effectSizes = list(),
  assumptions = assumptions,
  warnings = warnings,
  notes = list(sprintf(paste("The methods agree when the slope interval contains 1 and the intercept interval contains 0. Ordinary least squares is not used:",
                             "it assumes %s is measured without error and biases the slope towards 0."), xr),
               paste("Passing–Bablok is robust to outliers and needs no error-variance ratio; Deming assumes normal errors with a known ratio; weighted Deming",
                     "suits errors that grow with the level (constant CV).")),
  charts = c(list(cs_chart("comparison", "pred-actual", sprintf("%s against %s", yr, xr), list(
                  actual = cs_col(yr, y[take], "numeric"), predicted = cs_col(xr, x[take], "numeric")), controls = list(identity = TRUE)),
                cs_chart("residuals", "scatter", sprintf("Distance from the %s line", label), list(
                  x = cs_col(xr, x[take], "numeric"), y = cs_col(sprintf("%s − (%.3g + %.3g·%s)", yr, a, b, xr), resid[take], "numeric")),
                  controls = list(fit = "none"))),
             if (regression == "deming") list(cs_chart("deming", "deming-fit", sprintf("Deming fit of %s on %s", yr, xr),
               list(x = cs_col(xr, x[take], "numeric"), y = cs_col(yr, y[take], "numeric")), controls = list(delta = lam),
               note = if (length(take) < n) sprintf("Drawn from %s evenly spaced rows; the fit above uses all %s.", format(length(take), big.mark = ","), format(n, big.mark = ",")) else NULL))),
  values = values
))
Python

Passing–Bablok regression: slope = 1.467, 90% CI [1.397, 1.542]; intercept = −1.687, 90% CI [−2.272, −1.240]

Slope
1.467
Intercept
−1.687
Linearity p (CUSUM)
< .001

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

Assumptions

  • Strong positive relation between the methods — Pearson r = 0.992; Passing–Bablok assumes highly correlated, linearly related readings.
  • Linear relation (CUSUM test) — H = 2.499, p = 7.54e-06 (1.36 is the 5 % critical value).
  • Enough samples (≥ 40 recommended) — 80 pairs.

Passing–Bablok regression of new_curved on reference_cv

EstimateSE (jackknife)90% CI low90% CI highIdentity value inside the CI?
Slope1.467—1.3971.542no (proportional difference)
Intercept−1.687—−2.272−1.240no (constant difference)

Confidence limits from the ordered pairwise slopes (Passing & Bablok 1983).

  • The methods agree when the slope interval contains 1 and the intercept interval contains 0. Ordinary least squares is not used: it assumes reference_cv is measured without error and biases the slope towards 0.
  • Passing–Bablok is robust to outliers and needs no error-variance ratio; Deming assumes normal errors with a known ratio; weighted Deming suits errors that grow with the level (constant CV).
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Method comparison regression (Passing–Bablok, Deming)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method agreement.method_comparison 1.0.2 · spec 8a2bf1f0f7f909ef
# Dataset: c3_methcomp (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.errors import check_not_constant
from codesplash.stats import method_comparison as mc

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

# %% Regression
xr, yr = "reference_cv", "new_curved"
x = df[xr].to_numpy(dtype=float)
y = df[yr].to_numpy(dtype=float)
n = x.size
regression = "passing_bablok"
lam = 1
conf = 0.9
linearity = True
cs.check_rows(n, 3, "Method comparison")  # needs at least three pairs of readings
# A method with one reading for every sample leaves the slope undefined (no variation to regress on).
check_not_constant(x, xr)
check_not_constant(y, yr)
if regression == "passing_bablok":
    fit = mc.passing_bablok(x, y, conf)
    label = "Passing–Bablok"
elif regression == "weighted_deming":
    if np.any(x <= 0) or np.any(y <= 0):
        raise ValueError("Weighted Deming regression (constant CV) needs positive readings from both methods")
    fit = mc.deming(x, y, lam, weighted=True, conf=conf)
    label = "Weighted Deming"
else:
    fit = mc.deming(x, y, lam, weighted=False, conf=conf)
    label = "Deming"
a, b = fit["intercept"], fit["slope"]
cus = mc.cusum_linearity(x, y, a, b) if (linearity and regression == "passing_bablok") else None


def num(v):
    return None if v is None or not np.isfinite(v) else float(v)


constant_bias = bool(num(fit["intercept_low"]) is not None and num(fit["intercept_high"]) is not None
                     and (fit["intercept_low"] > 0 or fit["intercept_high"] < 0))
proportional_bias = bool(num(fit["slope_low"]) is not None and num(fit["slope_high"]) is not None
                         and (fit["slope_low"] > 1 or fit["slope_high"] < 1))
pct = f"{conf:.0%}"

# %% Assumptions
assumptions = []
if regression == "passing_bablok":
    assumptions.append({"key": "correlation", "label": "Strong positive relation between the methods",
                        "status": "pass" if float(np.corrcoef(x, y)[0, 1]) > 0.5 else "warn",
                        "detail": f"Pearson r = {float(np.corrcoef(x, y)[0, 1]):.3f}; Passing–Bablok assumes highly correlated, linearly related readings."})
    if cus and not np.isfinite(cus["p"]):
        # The CUSUM test needs residuals on both sides of the line (and a nonzero slope).
        assumptions.append({"key": "linearity", "label": "Linear relation (CUSUM test)", "status": "info",
                            "detail": "The CUSUM test needs points above and below the fitted line; it can't be computed here."})
    elif cus:
        assumptions.append({"key": "linearity", "label": "Linear relation (CUSUM test)", "status": "fail" if cus["p"] < 0.05 else "pass",
                            "detail": f"H = {cus['h']:.3f}, p = {cus['p']:.3g} (1.36 is the 5 % critical value)."})
else:
    assumptions.append({"key": "error_ratio", "label": "Error-variance ratio known", "status": "info",
                        "detail": f"λ = Var(error in {yr}) / Var(error in {xr}) = {lam:g}; estimate it from replicate measurements."})
assumptions.append({"key": "sample_size", "label": "Enough samples (≥ 40 recommended)", "status": "warn" if n < 40 else "pass",
                    "detail": f"{n} pairs" + ("; intervals are wide and the linearity test has little power." if n < 40 else ".")})

# %% Result
values = {
    "n": n, "regression": regression, "slope": b, "slope_low": num(fit["slope_low"]), "slope_high": num(fit["slope_high"]),
    "intercept": a, "intercept_low": num(fit["intercept_low"]), "intercept_high": num(fit["intercept_high"]),
    "slope_se": num(fit.get("slope_se")), "intercept_se": num(fit.get("intercept_se")),
    "error_ratio": lam if regression != "passing_bablok" else None, "iterations": fit.get("iterations") if regression == "weighted_deming" else None,
    "constant_bias": constant_bias, "proportional_bias": proportional_bias,
    "cusum_h": num(cus["h"]) if cus else None, "cusum_p": num(cus["p"]) if cus else None,
    "cusum_n_above": cus["n_above"] if cus else None, "cusum_n_below": cus["n_below"] if cus else None,
    "mean_difference": float(np.mean(y - x)),
}
resid = y - a - b * x
take = np.unique(np.round(np.linspace(0, n - 1, min(n, 5000))).astype(int))
verdict = ("no constant or proportional difference" if not (constant_bias or proportional_bias)
           else " and ".join(w for w, f in (("a constant difference", constant_bias), ("a proportional difference", proportional_bias)) if f))
cs.publish({
    "method": "agreement.method_comparison",
    "methodVersion": "1.0.2",
    "title": f"Method comparison ({label})",
    "engine": cs.engine_info("pandas", "numpy", "scipy"),
    "n": n,
    "summary": f"{label}: {yr} = {a:.4g} + {b:.4g} × {xr}; slope {pct} CI [{fit['slope_low']:.4g}, {fit['slope_high']:.4g}], "
    f"intercept {pct} CI [{fit['intercept_low']:.4g}, {fit['intercept_high']:.4g}] — {verdict}.",
    "apa": f"{label} regression: slope = {cs.fmt_num(b, 3)}, {pct} CI [{cs.fmt_num(fit['slope_low'], 3)}, {cs.fmt_num(fit['slope_high'], 3)}]; "
    f"intercept = {cs.fmt_num(a, 3)}, {pct} CI [{cs.fmt_num(fit['intercept_low'], 3)}, {cs.fmt_num(fit['intercept_high'], 3)}]",
    "statistics": [{"key": "slope", "label": "Slope", "value": b}, {"key": "intercept", "label": "Intercept", "value": a}]
    + ([{"key": "cusum_p", "label": "Linearity p (CUSUM)", "value": values["cusum_p"], "format": "p"}] if cus else []),
    "tables": [{"key": "coefficients", "title": f"{label} regression of {yr} on {xr}", "columns": [
        {"key": "term", "label": "", "type": "string"}, {"key": "estimate", "label": "Estimate", "type": "number"},
        {"key": "se", "label": "SE (jackknife)", "type": "number"}, {"key": "low", "label": f"{pct} CI low", "type": "number"},
        {"key": "high", "label": f"{pct} CI high", "type": "number"}, {"key": "reading", "label": "Identity value inside the CI?", "type": "string"}],
        "rows": [{"term": "Slope", "estimate": b, "se": values["slope_se"], "low": values["slope_low"], "high": values["slope_high"],
                  "reading": "no (proportional difference)" if proportional_bias else "yes (1)"},
                 {"term": "Intercept", "estimate": a, "se": values["intercept_se"], "low": values["intercept_low"], "high": values["intercept_high"],
                  "reading": "no (constant difference)" if constant_bias else "yes (0)"}],
        "note": ("Confidence limits from the ordered pairwise slopes (Passing & Bablok 1983)." if regression == "passing_bablok"
                 else f"Jackknife standard errors (Linnet 1990), t with {n - 2} df.")}],
    "effectSizes": [],
    "assumptions": assumptions,
    "warnings": warnings,
    "notes": [f"The methods agree when the slope interval contains 1 and the intercept interval contains 0. Ordinary least squares is not used: "
              f"it assumes {xr} is measured without error and biases the slope towards 0.",
              "Passing–Bablok is robust to outliers and needs no error-variance ratio; Deming assumes normal errors with a known ratio; weighted Deming "
              "suits errors that grow with the level (constant CV)."],
    "charts": [cs.chart("comparison", "pred-actual", f"{yr} against {xr}", {
                   "actual": cs.col(yr, y[take], "numeric"), "predicted": cs.col(xr, x[take], "numeric")}, controls={"identity": True}),
               cs.chart("residuals", "scatter", f"Distance from the {label} line", {
                   "x": cs.col(xr, x[take], "numeric"), "y": cs.col(f"{yr} − ({a:.3g} + {b:.3g}·{xr})", resid[take], "numeric")},
                   controls={"fit": "none"})]
    + ([cs.chart("deming", "deming-fit", f"Deming fit of {yr} on {xr}", {"x": cs.col(xr, x[take], "numeric"), "y": cs.col(yr, y[take], "numeric")},
                 controls={"delta": lam}, note=None if len(take) == n else f"Drawn from {len(take):,} evenly spaced rows; the fit above uses all {n:,}.")]
       if regression == "deming" else []),
    "values": values,
})
05

Read a comparison

Checkpoint

Check yourself

A comparison gives slope 1.08 (95% CI 1.03 to 1.13) and intercept 0.2 (95% CI −0.5 to 0.9). What is it compatible with?

Show the answer

Answer: b

The slope's interval excludes 1 and the intercept's includes 0: the new method reads progressively higher, by about 8%.

06

Which method?

Read
SituationUse
Error variance ratio unknown, outliers possiblePassing–Bablok
Known or estimable λ\lambda, roughly normal errorsDeming
Error grows with the level (a constant CV)Weighted Deming

With λ\lambda = 1, Deming gives slope 0.990. The ratio comes from replicate measurements; if you've no replicates, Passing–Bablok is the safer choice. All need a wide range of values, so run over the range you'll use in practice.

Deming fitWhat is the line between two noisy measurements, when both have error?
View data
method Amethod B
15.21015.510
18.29019.750
16.39018.090
9.08010.100
10.85012.410
4.7403.870
14.96016.400
19.41020.330
8.45010.270
13.42014.920
17.97020.070
17.27020.150
14.26014.450
3.1602.340
10.23013.120
11.35012.830
16.22018.780
11.14012.830
5.4904.050
16.37019.390
16.67020.460
4.3105.840
17.57019.290
2.3102.840
13.36016.010
12.48013.350
16.94017.550
7.0408.490
17.31019.940
2.4702.960
18.92018.440
6.3306.780
1.3403.050
5.1307.260
15.15015.560
16.09018.520
19.55022.350
18.27018.080
15.48016.040
18.74018.560
07

Plan the samples

Reflect

You're about to compare a new assay or sensor with the current one. How would you choose samples that span the range you'll use in practice? What slope or bias would make you reject the new method? Decide before you collect anything.

08

Deming by hand

Read

R and Python have dedicated packages, but the Deming slope has a closed form. This reproduces the card.

Python
import numpy as np
import pandas as pd

df = pd.read_csv("c3_methcomp.csv")
x, y = df["reference"], df["new"]
lam = 1.0  # error-variance ratio, new / reference
sxx, syy, sxy = x.var(ddof=1), y.var(ddof=1), x.cov(y)
slope = (syy - lam * sxx + np.sqrt((syy - lam * sxx) ** 2 + 4 * lam * sxy ** 2)) / (2 * sxy)
print(slope, y.mean() - slope * x.mean())
R
df <- read.csv("c3_methcomp.csv")
x <- df$reference; y <- df$new
lam <- 1  # error-variance ratio, new / reference
sxx <- var(x); syy <- var(y); sxy <- cov(x, y)
slope <- (syy - lam * sxx + sqrt((syy - lam * sxx)^2 + 4 * lam * sxy^2)) / (2 * sxy)
c(slope = slope, intercept = mean(y) - slope * mean(x))
09

Check your understanding

Checkpoint

Check yourself

Why does ordinary least squares tend to report a slope below 1 even when two methods agree perfectly on average?

Show the answer

Answer: a

Error in the predictor pulls the slope toward zero. Deming and Passing–Bablok allow for error on both sides.

Check yourself

All your samples cluster within a narrow range. What's the consequence?

Show the answer

Answer: b

With a narrow range, the line is poorly anchored. Choose samples that span the range you'll use in practice.

10

Recap

Recap
  • With error on both sides, use Deming or Passing–Bablok instead of OLS.
  • An intercept interval that excludes 0 means constant bias; a slope interval that excludes 1 means proportional bias.
  • Check linearity, and cover the range you'll use.

Concepts in this lesson