What is the least squares method
Measured points rarely lie exactly on a line. The least squares method finds the line y = kx + b that minimises the sum of squared deviations S = Σ (yi − k·xi − b)².
Formulas
k = (n·Σxy − Σx·Σy) / (n·Σx² − (Σx)²), b = (Σy − k·Σx) / n
- Pearson r — from −1 to 1, strength and direction of the linear relationship;
- R² — share of variance of y explained by the line;
- standard error S — typical deviation of points from the line.
Example
x = 1…5, y = 2.1, 3.9, 6.2, 7.8, 10.1: n = 5, Σx = 15, Σy = 30.1, Σxy = 110.2, Σx² = 55. k = 99.5 / 50 = 1.99, b = 0.05, so y = 1.99x + 0.05, R² ≈ 0.998.
If the points follow a curve, use curve fitting; if the curve must pass exactly through all points, use interpolation.