GAgreement & reliability · agreement.method_comparison
Method comparison regression (Passing–Bablok, Deming)
Does a new measurement method give the same values as the reference — is there a constant or proportional difference?
Regresses a new method's readings on a reference method's with a procedure that allows for error in both: Passing–Bablok (rank-based, robust, with the CUSUM test of linearity), Deming (known ratio of error variances) or weighted Deming (errors proportional to the level). The slope's interval should contain 1 and the intercept's 0; otherwise the methods differ proportionally or by a constant.
A real result
Example “Passing bablok ties”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
Passing–Bablok regression: slope = 0.987, 95% CI [0.966, 1.007]; intercept = 0.365, 95% CI [0.124, 0.625]
- Slope
- 0.9871
- Intercept
- 0.3652
- Linearity p (CUSUM)
- .576
Plots
View data
| new | reference |
|---|---|
| 17.148 | 15.600 |
| 11.749 | 11 |
| 3.398 | 2.400 |
| 5.362 | 4.900 |
| 9.777 | 10.100 |
| 2.648 | 2.900 |
| 7.950 | 8.400 |
| 26.067 | 26.200 |
| 4.752 | 4.700 |
| 11.983 | 11.600 |
| 2.272 | 1.500 |
| 17.193 | 15.800 |
| 4.512 | 3.500 |
| 25.100 | 25.600 |
| 3.628 | 2.800 |
| 5.958 | 5.700 |
| 9.790 | 9.600 |
| 2.519 | 1.500 |
| 5.853 | 5.200 |
| 2.556 | 1.600 |
| 5.939 | 5.500 |
| 5.862 | 5.700 |
| 4.658 | 3.900 |
| 2.014 | 2.300 |
| 7.621 | 6 |
| 3.262 | 3.400 |
| 7.175 | 5.900 |
| 3.670 | 3.600 |
| 2.411 | 1.500 |
| 11.409 | 12.200 |
| 30.339 | 30.900 |
| 3.782 | 3.400 |
| 18.315 | 18.600 |
| 2.607 | 1.700 |
| 11.934 | 11.800 |
| 7.890 | 6.700 |
| 3.629 | 4.800 |
| 8.177 | 8.700 |
| 19.102 | 19 |
| 7.944 | 8 |
| 6.962 | 5.500 |
| 26.806 | 28.200 |
| 7.069 | 6.800 |
| 8.014 | 6.700 |
| 2.604 | 2.500 |
| 2.367 | 2.600 |
| 32.259 | 32.300 |
| 4.730 | 4.500 |
| 9.223 | 10.100 |
| 4.151 | 5.300 |
| 36.129 | 35.800 |
| 12.993 | 14 |
| 35.331 | 35.100 |
| 27.948 | 28.900 |
| 9.730 | 8.700 |
| 17.106 | 16.900 |
| 17.395 | 17.900 |
| 2.722 | 2 |
| 35.595 | 34.700 |
| 3.874 | 3.800 |
First 60 of 80 rows.
View data
| reference | new − (0.365 + 0.987·reference) |
|---|---|
| 15.600 | 1.383 |
| 11 | 0.5250 |
| 2.400 | 0.6639 |
| 4.900 | 0.1593 |
| 10.100 | −0.5579 |
| 2.900 | −0.5802 |
| 8.400 | −0.7073 |
| 26.200 | −0.1613 |
| 4.700 | −0.2526 |
| 11.600 | 0.1667 |
| 1.500 | 0.4261 |
| 15.800 | 1.231 |
| 3.500 | 0.6913 |
| 25.600 | −0.5360 |
| 2.800 | 0.4990 |
| 5.700 | −0.0342 |
| 9.600 | −0.0520 |
| 1.500 | 0.6728 |
| 5.200 | 0.3550 |
| 1.600 | 0.6110 |
| 5.500 | 0.1443 |
| 5.700 | −0.1295 |
| 3.900 | 0.4428 |
| 2.300 | −0.6217 |
| 6 | 1.333 |
| 3.400 | −0.4593 |
| 5.900 | 0.9855 |
| 3.600 | −0.2490 |
| 1.500 | 0.5648 |
| 12.200 | −0.9995 |
| 30.900 | −0.5291 |
| 3.400 | 0.0603 |
| 18.600 | −0.4106 |
| 1.700 | 0.5640 |
| 11.800 | −0.0799 |
| 6.700 | 0.9110 |
| 4.800 | −1.475 |
| 8.700 | −0.7760 |
| 19 | −0.0188 |
| 8 | −0.3182 |
| 5.500 | 1.168 |
| 28.200 | −1.397 |
| 6.800 | −0.0090 |
| 6.700 | 1.034 |
| 2.500 | −0.2286 |
| 2.600 | −0.5652 |
| 32.300 | 0.0090 |
| 4.500 | −0.0777 |
| 10.100 | −1.113 |
| 5.300 | −1.446 |
| 35.800 | 0.4245 |
| 14 | −1.192 |
| 35.100 | 0.3174 |
| 28.900 | −0.9454 |
| 8.700 | 0.7766 |
| 16.900 | 0.0578 |
| 17.900 | −0.6403 |
| 2 | 0.3825 |
| 34.700 | 0.9758 |
| 3.800 | −0.2427 |
First 60 of 80 rows.
Assumptions
- Strong positive relation between the methods — Pearson r = 0.997; Passing–Bablok assumes highly correlated, linearly related readings.
- Linear relation (CUSUM test) — H = 0.781, p = 0.576 (1.36 is the 5 % critical value).
- Enough samples (≥ 40 recommended) — 80 pairs.
Passing–Bablok regression of new on reference
| Estimate | SE (jackknife) | 95% CI low | 95% CI high | Identity value inside the CI? | |
|---|---|---|---|---|---|
| Slope | 0.9871 | — | 0.9664 | 1.007 | yes (1) |
| Intercept | 0.3652 | — | 0.1244 | 0.6250 | no (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 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).
Passing–Bablok regression: slope = 0.987, 95% CI [0.966, 1.007]; intercept = 0.365, 95% CI [0.124, 0.625]
- Slope
- 0.9871
- Intercept
- 0.3652
- Linearity p (CUSUM)
- .576
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Strong positive relation between the methods — Pearson r = 0.997; Passing–Bablok assumes highly correlated, linearly related readings.
- Linear relation (CUSUM test) — H = 0.781, p = 0.576 (1.36 is the 5 % critical value).
- Enough samples (≥ 40 recommended) — 80 pairs.
Passing–Bablok regression of new on reference
| Estimate | SE (jackknife) | 95% CI low | 95% CI high | Identity value inside the CI? | |
|---|---|---|---|---|---|
| Slope | 0.9871 | — | 0.9664 | 1.007 | yes (1) |
| Intercept | 0.3652 | — | 0.1244 | 0.6250 | no (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 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).
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
- Passing bablok tiesc3_methcomp · candidate: new · reference: reference
- Passing bablok curvedc3_methcomp · candidate: new_curved · reference: reference_cv
- Demingc3_methcomp · candidate: new · reference: reference
- Deming ratioc3_methcomp · candidate: new · reference: reference
- Weighted deming cvc3_methcomp · candidate: new_cv · reference: reference_cv
- Degenerate constantc3_methcomp · candidate: new · reference: reference
- Degenerate n2c3_methcomp · candidate: new · reference: reference
- Degenerate n3c3_methcomp · candidate: new · reference: reference
In the guides
Where it sits in the decision guides
- Concordance: CCC, Deming, Passing–Bablok · Statistics Guide · G — Agreement / reliability
What you need
- Reference methodnumeric · 1 column
- Readings by the established (comparative) method, on the x axis.
- New methodnumeric · 1 column
- Readings by the method being evaluated, on the same samples (y axis).
Choices you make
statistics
- Regressiondefault passing_bablok
All three allow for measurement error in both methods; ordinary least squares does not.
- Passing–Bablok(default) — Median of pairwise slopes: robust to outliers, no distribution or error ratio needed; needs a strong positive relation.
- Deming — Least squares perpendicular to the error ratio; assumes normal errors with constant SD and a known ratio.
- Weighted Deming (constant CV) — Linnet's weighting for errors that grow in proportion to the level; positive readings only.
- Error-variance ratio λ (new / reference)default 1
Var(error of the new method) / Var(error of the reference); 1 when both are equally precise. Estimate it from replicates.
hypothesis
- CUSUM test of linearitydefault on
Passing and Bablok's test that the relation is linear over the range (needed for the regression to make sense).
- 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.
Strong positive relation between the methods
Passing–Bablok assumes highly correlated, linearly related readings.
Linear relation (CUSUM test)
A significant CUSUM test means the methods are not linearly related over the range.
Error-variance ratio known
Deming needs the ratio of the methods' error variances (1 when equally precise).
Enough samples
At least 40 samples spread over the measuring range are recommended (CLSI EP09).
What it reports
- n
- How many independent units the analysis used; it sets precision and power.
- regression
- Which regression was fitted: passing_bablok, deming or weighted_deming. All allow measurement error in both methods.
- slope
- A rank-based line through two methods' readings (median of pairwise slopes) that allows for error in both and resists outliers.
- slope_low
- A range of effect values compatible with your data at the chosen confidence level.
- slope_high
- A range of effect values compatible with your data at the chosen confidence level.
- intercept
- A rank-based line through two methods' readings (median of pairwise slopes) that allows for error in both and resists outliers.
- intercept_low
- A range of effect values compatible with your data at the chosen confidence level.
- intercept_high
- A range of effect values compatible with your data at the chosen confidence level.
- slope_se
- A straight line fitted allowing for measurement error in both methods, given the ratio of their error variances (1 = equally precise).
- intercept_se
- A straight line fitted allowing for measurement error in both methods, given the ratio of their error variances (1 = equally precise).
- error_ratio
- A straight line fitted allowing for measurement error in both methods, given the ratio of their error variances (1 = equally precise).
- iterations
- Whether an iterative fit found a stable solution; warnings mean estimates may be unreliable.
- constant_bias
- A constant difference shifts every reading by the same amount (intercept ≠ 0); a proportional one grows with the level (slope ≠ 1).
- proportional_bias
- A constant difference shifts every reading by the same amount (intercept ≠ 0); a proportional one grows with the level (slope ≠ 1).
- cusum_h
- Checks that two methods are linearly related by tracking runs of points above and below the fitted line; H > 1.36 rejects at 5 %.
- cusum_p
- Checks that two methods are linearly related by tracking runs of points above and below the fitted line; H > 1.36 rejects at 5 %.
- cusum_n_above
- Checks that two methods are linearly related by tracking runs of points above and below the fitted line; H > 1.36 rejects at 5 %.
- cusum_n_below
- Checks that two methods are linearly related by tracking runs of points above and below the fitted line; H > 1.36 rejects at 5 %.
- mean_difference
- One group's mean minus another's, in the outcome's own units.
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
- All three regressions are codesplash twins written from the papers. Deming and weighted Deming (jackknife intervals) equal mcr::mcreg(method.reg = 'Deming' / 'WDeming', method.ci = 'jackknife') to every printed digit on c3_methcomp (mcr's error.ratio is our 1/λ). Passing–Bablok slope, intercept and CUSUM statistic equal mcr's; mcr interpolates the confidence limits between adjacent slopes whereas we use the order statistics of the 1983 paper (lower slope limit 0.96637 vs mcr's 0.96644 there).
The exact script CodeSplash ran for example “Passing bablok ties” · 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 b9c98f1f48d596fb
# 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", "new"])
n_input = len(df)
df = df.dropna(subset=["reference", "new"]) # 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", "new"]) # infinite values stop the run (registry/errors.yaml)
# %% Regression
xr, yr = "reference", "new"
x = df[xr].to_numpy(dtype=float)
y = df[yr].to_numpy(dtype=float)
n = x.size
regression = "passing_bablok"
lam = 1
conf = 0.95
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,
})
The exact script CodeSplash ran for example “Passing bablok ties” · 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 b9c98f1f48d596fb
# 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", "new")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("reference", "new")]), , 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", "new")) # infinite values stop the run (registry/errors.yaml)
# %% Regression
xr <- "reference"
yr <- "new"
x <- as.numeric(df[[xr]])
y <- as.numeric(df[[yr]])
n <- length(x)
regression <- "passing_bablok"
lam <- 1
conf <- 0.95
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
))
Sources
- Passing, H., & Bablok, W. (1983). A new biometrical procedure for testing the equality of measurements from two different analytical methods. J Clin Chem Clin Biochem, 21, 709–720.
- Linnet, K. (1990). Estimation of the linear relationship between the measurements of two methods with proportional errors. Statistics in Medicine, 9, 1463–1473.
- Linnet, K. (1993). Evaluation of regression procedures for methods comparison studies. Clinical Chemistry, 39, 424–432.
- Deming, W. E. (1943). Statistical adjustment of data. Wiley.
- CLSI (2018). EP09c: Measurement procedure comparison and bias estimation using patient samples.
From the CodeSplash method registry · agreement.method_comparison v1.0.2.