Skip to content
svgdeming-fit

Deming fit

What is the line between two noisy measurements, when both have error?

Demo data · seed 20261101 · 40 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read the bold line as the fit when both measurements have error.
  2. Compare it with the identity line: an offset suggests constant bias, a different slope proportional bias.
  3. Change δ to see how the assumed error ratio moves the line.
  1. Callout 1: The Deming line.
  2. Callout 2: The identity line: perfect agreement.
  3. Callout 3: Segments slant: both x and y have error.

Watch out

  • The slope depends on δ. Choose it from replicate measurements rather than from what looks good.

Defaults

Error variance ratio δ (y ÷ x)
1
How much noisier y is than x. δ = 1 is orthogonal regression; very large δ tends to ordinary least squares.
Range 0.1 to 10, step 0.1
Residual segments
On
Draw each row's path to the line.

Demo data

Proportional bias in the demo
1.08
The true slope behind the demo data.
Range 0.8 to 1.3, step 0.01

Pinned in the code

  • Slope b = (s_yy − δ·s_xx + √((s_yy − δ·s_xx)² + 4δ·s_xy²)) / (2·s_xy), intercept ȳ − b·x̄ (Linnet 1990).
  • Fitted x̂ᵢ = xᵢ + b/(b² + δ) · (yᵢ − a − b·xᵢ); each segment joins (xᵢ, yᵢ) with (x̂ᵢ, a + b·x̂ᵢ).
  • Both axes share one scale, so the identity line is the diagonal.
# Deming fit — Codesplash Chart Lab (recipe "deming-fit")
# controls: delta=1, segments=true
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("deming-fit-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
X = "method A"
Y = "method B"
DELTA = 1  # ratio of y-error variance to x-error variance
d = df.dropna(subset=[X, Y])
x, y = d[X].to_numpy(float), d[Y].to_numpy(float)
sxx, syy, sxy = np.var(x, ddof=1), np.var(y, ddof=1), np.cov(x, y)[0, 1]
b = (syy - DELTA * sxx + np.sqrt((syy - DELTA * sxx) ** 2 + 4 * DELTA * sxy**2)) / (2 * sxy)  # Linnet (1990)
a = y.mean() - b * x.mean()
fx = x + b / (b**2 + DELTA) * (y - a - b * x)
lim = np.array([min(x.min(), y.min()), max(x.max(), y.max())])
fig, ax = plt.subplots(figsize=(5.5, 5.5))
ax.plot(lim, lim, color=REF, linestyle="--", label="identity (y = x)")
for i in range(len(x)):
    ax.plot([x[i], fx[i]], [y[i], a + b * fx[i]], color=REF, alpha=0.35, linewidth=0.8)
ax.plot(lim, a + b * lim, color=PALETTE[0], linewidth=2, label=f"y = {a:.3g} + {b:.3g}·x")
ax.scatter(x, y, s=16, color=PALETTE[0], edgecolors="white", linewidths=0.5, zorder=3)
ax.set_aspect("equal", adjustable="datalim")
ax.set_xlabel(X)
ax.set_ylabel(Y)
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads deming-fit-demo.csv · app theme from the optional codesplash helper