About this calculator
Linear regression fits the straight line y = a + bx that makes the sum of squared vertical distances from the points to the line as small as possible (least squares). Engineers use it for calibration curves, wear and drift trends, and any roughly straight-line relationship. The correlation coefficient r (−1 to 1) and R² (0 to 1) say how closely the points follow the line.
Formula
b = Sxy ÷ Sxx a = ȳ − b x̄
Sxx = Σ(x − x̄)² Sxy = Σ(x − x̄)(y − ȳ) Syy = Σ(y − ȳ)²
r = Sxy ÷ √(Sxx Syy) s = √(Σ(y − ŷ)² ÷ (n − 2))
SE(b) = s ÷ √Sxx SE(a) = s √(1/n + x̄² ÷ Sxx)
Sums are taken about the means, which is more accurate than the textbook shortcut formulas with Σx² and Σxy.
Worked example
x = 1, 2, 3, 4, 5 and y = 2.1, 3.9, 6.2, 7.8, 10.1:
- x̄ = 3, ȳ = 6.02; Sxx = 10, Sxy = 19.9
- b = 19.9 ÷ 10 = 1.99; a = 6.02 − 1.99 × 3 = 0.05 → y = 0.05 + 1.99x
- Syy = 39.708 → r = 19.9 ÷ √(10 × 39.708) = 0.998652, R² = 0.997305
- At x = 6: ŷ = 0.05 + 1.99 × 6 = 11.99 (an extrapolation)
Assumptions and limitations
- Ordinary least squares: the x values are taken as exact and all the scatter is in y.
- A high R² shows a good straight-line fit, not cause and effect. Look at the data: a curved relationship can still give a high R².
- Standard errors assume independent, normally distributed residuals with constant variance.
References
- NIST/SEMATECH e-Handbook of Statistical Methods, section 4.1.4.1 (linear least squares regression).
- Montgomery, D. C. & Runger, G. C. Applied Statistics and Probability for Engineers — simple linear regression.
