The formula
The model:
y = b₀ + b₁·x + ε
Read: every measurement is a straight line plus noise. b₁ is the sensitivity you're after, b₀ is the offset, and ε is everything the line doesn't explain.
The slope, from n data points:
b₁ = Σ (x_i − x̄)·(y_i − ȳ) / Σ (x_i − x̄)²
Read: how much x and y swing together, divided by how much x swings on its own. The denominator, call it Sxx, is the spread of your test points — it shows up in every uncertainty formula below, which is why where you place the points matters as much as how many you take.
The intercept:
b₀ = ȳ − b₁·x̄
Read: slide the line so it passes exactly through the centroid (x̄, ȳ) of the data. It always does, whenever the model has an intercept — a free sanity check on any fit routine [1].
The leftover scatter:
s = √( Σ r_i² / (n − 2) ) , r_i = y_i − (b₀ + b₁·x_i)
Read: the standard deviation of the vertical misses, charged two degrees of freedom for the two numbers you just estimated. This is the noise floor of everything downstream.
What the coefficients are good for:
SE(b₁) = s / √Sxx , SE(b₀) = s·√( 1/n + x̄²/Sxx )
Read: slope uncertainty is residual scatter divided by the spread of the x-points [1]. Double the span of your test points and the slope error halves without a single extra reading.
Fit quality:
r² = 1 − Σ r_i² / Σ (y_i − ȳ)²
Read: the fraction of the data's total variation the line accounts for. Useful, quotable, and the most oversold number in test reporting — see below.
Where you meet it
- Calibrating a pressure transducer on the bench. Step a deadweight tester or pressure standard through 0, 20, 40, 60, 80, 100 psi and log the output voltage. Six points like
0.502, 1.298, 2.104, 2.897, 3.702, 4.499 Vfit toV = 0.5010 + 0.039986·P, withSE(slope) = 0.000036 V/psi, residual scatters ≈ 3.0 mV, andr² = 0.999997. The slope and offset go on the cal cert; the 3 mV is what you defend at audit. - Characterizing a load cell or strain-gauge sensor. Sensitivity in mV/V per pound is a fitted slope, and the linearity number on the datasheet is the worst residual from exactly this fit, expressed as a percent of full scale. When a vendor quotes "0.05% FS nonlinearity," a straight-line regression is the ruler they measured it with.
- Trend lines in front of a review board. Bearing temperature versus run hours, battery capacity versus cycle count, leak rate versus pressure cycles — the board wants a slope, a confidence band on that slope, and a projected crossing of the limit line. All three fall out of the formulas above, and the board should ask about the third one hardest, because it's an extrapolation.
- Pulling a material property off test data. Young's modulus is the fitted slope of the stress–strain curve's elastic region; a coefficient of thermal expansion is the fitted slope of length versus temperature. Both are regressions whether or not anyone said the word.
How it works
The fit minimizes the sum of squared vertical misses, nothing else. Behind that choice sits an assumption: x is known essentially exactly and all the error lives in y [1]. Calibration against a standard matches that assumption almost perfectly — the deadweight tester's pressure is orders of magnitude better known than your transducer's output. But regress one noisy sensor against another noisy sensor and the assumption breaks: noise in x biases the fitted slope toward zero, systematically, and averaging more points does not fix it [1]. When both axes carry comparable error, the honest tools are Deming or total least squares, not ordinary least squares.
Point placement is leverage. Sxx sits in the denominator of the slope uncertainty, so points far from x̄ do the work of pinning the slope down. That cuts both ways: the endpoints of your calibration range carry the most leverage, so one flaky reading at full scale steers the whole line while the same error mid-span barely registers. Repeat your endpoints.
Calibration runs the fit backwards. You fit output versus applied standard, but in service you have an output and want the measurand: P = (V − b₀)/b₁. That inversion — inverse prediction, the classical calibration problem — has its own uncertainty, larger than the fit residual alone, and the NIST e-Handbook treats it as its own topic for good reason [10]. From the bench example: a field reading of 2.750 V says 56.24 psi.
r² is not a residual plot. In 1973 Francis Anscombe published four datasets — a clean line, a parabola, a line with one outlier, and a cluster with a single flyer — that all produce the same fitted line y = 3.00 + 0.500·x and the same r² ≈ 0.67 [8][9]. Run the numbers yourself; they check. The summary statistics cannot tell those four situations apart. Plot the residuals against x and against run order, every time: a bow shape means the physics is curved, a fan shape means the noise grows with signal, and a slow wander means drift — which also makes the quoted standard errors optimistic, since the formulas assume independent errors.
The zero-intercept temptation. "The sensor should read zero at zero, so force b₀ = 0." Don't, at least not first. Fit the intercept and look at it: a b₀ several standard errors from zero is a real offset in your signal chain — amplifier bias, tare error, a units mistake — and forcing it to zero doesn't remove the offset, it smears the offset into your slope. Fit free, then justify the constraint.
Two points define a line and prove nothing. At n = 2 the fit is exact, r² = 1, and n − 2 = 0 degrees of freedom remain to estimate s. Every uncertainty statement dies there. A two-point cal is a setting, not a characterization; five points and a residual plot is the difference between an adjustment and evidence of linearity.
Interpolate with confidence, extrapolate with a signed waiver. Inside the tested span the line is backed by data. Beyond it, the model is an assumption about physics you did not exercise — sensors saturate, materials yield, trends bend. The line has no way to know.
History
The method arrived from astronomy, not statistics. Adrien-Marie Legendre published it in 1805, in an appendix to a work on computing comet orbits, and gave the technique its name — the method of least squares — along with the first clear recipe for it [2][3][5]. Then Carl Friedrich Gauss published his own treatment in 1809, in his treatise on celestial mechanics, and stated that he had been using the method since 1795 [2][4]. Gauss's supporting exhibit was already famous: when the newly discovered asteroid Ceres was lost behind the Sun in 1801, the 24-year-old Gauss computed where it would reappear, and Franz Xaver von Zach recovered it in December almost exactly on the prediction — a computation Gauss later said rested on least squares, though he had disclosed nothing of his method at the time [2][4]. The priority fight wounded Legendre, who spent years pressing his claim [3]. History's usual verdict splits the difference: Legendre published first and plainly; Gauss went further, tying the method to probability and the normal error curve, and in an 1823 memoir proved the result — now carrying Andrey Markov's name alongside his — that among linear unbiased estimates, least squares has the least variance [4][11].
The word "regression" came eighty years later from a different field entirely. Francis Galton, studying heredity, measured parents and their adult children and found that the children of unusually tall parents were tall, but less so — the heights drifted back toward the average. His 1886 paper "Regression towards Mediocrity in Hereditary Stature" named that biological drift [6][7]. The biology stayed put; the name escaped and attached itself to the line-fitting machinery, where it has confused first-year engineers ever since.
Related tools
- /tools/loop-4-20ma — a 4–20 mA loop is a slope and an offset; the calibration that sets them is this fit
- /tools/strain-gauge-bridge — bridge sensitivity in mV/V per unit load is a fitted slope, and the linearity spec is its worst residual
- /tools/stress-strain — Young's modulus is the regression slope of the elastic region
- /tools/thermal-expansion — a CTE is the fitted slope of dimension versus temperature
- /tools/snr-enob — the acquisition chain's noise floor sets the
syour slope uncertainty is built from
Sources
- https://en.wikipedia.org/wiki/Simple_linear_regression
- https://en.wikipedia.org/wiki/Least_squares
- https://mathshistory.st-andrews.ac.uk/Biographies/Legendre/
- https://mathshistory.st-andrews.ac.uk/Biographies/Gauss/
- https://www.york.ac.uk/depts/maths/histstat/legendre.pdf
- https://en.wikipedia.org/wiki/Regression_toward_the_mean
- https://galton.org/essays/1880-1889/galton-1886-jaigi-regression-stature.pdf
- https://en.wikipedia.org/wiki/Anscombe%27s_quartet
- https://doi.org/10.1080/00031305.1973.10478966
- https://www.itl.nist.gov/div898/handbook/mpc/section3/mpc3.htm
- https://en.wikipedia.org/wiki/Gauss%E2%80%93Markov_theorem