Linear Regression y = mx + c — The Least-Squares Idea
In every practical you have ever done, the same thing happens: you plot the readings, and they do not sit exactly on a straight line. So where do you draw the line? "By eye, with a ruler" is what most students are told. Least-squares linear regression is the method that removes the guesswork — it picks the one line for which the total squared vertical error is as small as possible. This is the maths behind every calibration curve, every Beer–Lambert plot, and every "find the slope of the graph" question in a lab exam.
What "least squares" actually means
Take any candidate line y = mx + c. For each data point, the residual is the vertical gap between the measured y and the y the line predicts. Some residuals are positive, some negative. Squaring them makes all of them positive, and punishes big misses more than small ones. The least-squares line is the one that makes the sum of those squares smallest. Solving that minimisation (a calculus exercise using two partial derivatives) gives closed formulas — no trial and error needed:
c = [ Σy − m(Σx) ] / n (equivalently c = ȳ − m x̄)
Here n is the number of data points, Σx means "add up all the x values", and Σxy means "multiply each x by its own y, then add". Note the difference between Σx² (square each x, then add) and (Σx)² (add first, then square) — mixing these up is the classic error.
Worked example — a Beer–Lambert calibration curve
Five standard solutions are measured in a colorimeter. Concentration x is in arbitrary standard units and absorbance y has no unit.
| x | y | xy | x² | y² |
|---|---|---|---|---|
| 1 | 0.21 | 0.21 | 1 | 0.0441 |
| 2 | 0.40 | 0.80 | 4 | 0.1600 |
| 3 | 0.62 | 1.86 | 9 | 0.3844 |
| 4 | 0.79 | 3.16 | 16 | 0.6241 |
| 5 | 1.00 | 5.00 | 25 | 1.0000 |
| Σ = | 3.02 | 11.03 | 55 | 2.2126 |
Σx = 1 + 2 + 3 + 4 + 5 = 15, and n = 5.
Slope:
nΣxy = 5 × 11.03 = 55.15
(Σx)(Σy) = 15 × 3.02 = 45.30
numerator = 55.15 − 45.30 = 9.85
nΣx² = 5 × 55 = 275, (Σx)² = 15² = 225 → denominator = 275 − 225 = 50
m = 9.85 / 50 = 0.197
Intercept:
m(Σx) = 0.197 × 15 = 2.955
Σy − m(Σx) = 3.02 − 2.955 = 0.065
c = 0.065 / 5 = 0.013
Best-fit line: y = 0.197x + 0.013
Checking the fit — residuals must cancel
A property of the least-squares line that gives you a free check: the residuals always add up to zero. Work them out for the example above.
| x | Observed y | Predicted 0.197x + 0.013 | Residual (obs − pred) |
|---|---|---|---|
| 1 | 0.21 | 0.210 | 0.000 |
| 2 | 0.40 | 0.407 | −0.007 |
| 3 | 0.62 | 0.604 | +0.016 |
| 4 | 0.79 | 0.801 | −0.011 |
| 5 | 1.00 | 0.998 | +0.002 |
Sum of residuals = 0.000 − 0.007 + 0.016 − 0.011 + 0.002 = 0.000 ✓. If yours does not come to (near) zero, you have an arithmetic error in m or c — go back before using the line for anything.
How good is the fit? The correlation coefficient
Using the same sums: numerator = 9.85 (already computed).
nΣy² = 5 × 2.2126 = 11.063, (Σy)² = 3.02² = 9.1204 → 11.063 − 9.1204 = 1.9426
denominator = √(50 × 1.9426) = √97.13 = 9.8555
r = 9.85 / 9.8555 = 0.9994, so r² = 0.9989.
r runs from −1 to +1. Values near +1 mean a strong straight-line relationship with a positive slope; near −1, the same but with a negative slope; near 0, no linear relationship. r² is read as "the fraction of the variation in y that the straight line accounts for" — here about 99.9%.
Using the line
Two things a calibration line is used for, and both appear in practical exams:
Interpolation (x known, want y): at x = 2.5,
y = 0.197 × 2.5 + 0.013 = 0.4925 + 0.013 = 0.506
Inverse use (y measured, want x) — this is what you actually do with an
unknown sample. If the unknown gives an absorbance of 0.55:
x = (y − c) / m = (0.55 − 0.013) / 0.197 = 0.537 / 0.197 = 2.73 units
Check by substituting back: 0.197 × 2.73 + 0.013 = 0.53781 + 0.013 = 0.5508 ≈ 0.55 ✓
A second, smaller example
x = 0, 1, 2, 3 and y = 2, 4, 5, 8. n = 4.
Σx = 6, Σy = 19, Σx² = 0 + 1 + 4 + 9 = 14, Σxy = 0 + 4 + 10 + 24 = 38.
m = (4 × 38 − 6 × 19) / (4 × 14 − 36) = (152 − 114) / (56 − 36) = 38 / 20 =
1.9
c = (19 − 1.9 × 6) / 4 = (19 − 11.4) / 4 = 7.6 / 4 = 1.9
Line: y = 1.9x + 1.9. Notice the line passes through the mean point
(x̄, ȳ) = (1.5, 4.75): 1.9 × 1.5 + 1.9 = 2.85 + 1.9 = 4.75 ✓ — another free check that
holds for every least-squares line.
Common mistakes
- Confusing Σx² with (Σx)². In the first example Σx² = 55 but (Σx)² = 225. Using the wrong one changes the slope completely.
- Swapping x and y. Least squares minimises vertical error, so regressing x on y gives a different line. Put the quantity you control (concentration, time, temperature) on the x-axis.
- Reading r = 0.999 as proof of a physical law. A high r says the points lie near a line. It does not prove one variable causes the other, and it does not detect a systematic instrument error that shifts every reading equally.
- Assuming c must be zero. Beer's law predicts a zero intercept, but a real blank correction or a dirty cuvette gives a small non-zero c. Report what the data gives; do not force the line through the origin unless the method specifically requires it.
- Extrapolating far beyond the data. The line was fitted between x = 1 and x = 5. Using it at x = 40 is a guess dressed as a calculation — most real calibration curves bend at high concentration.
- Forgetting that the slope carries units. If y is absorbance and x is mol/L, then m has units of L/mol. In a Beer–Lambert plot that slope is εl, not ε.
- Rounding the sums. Keep full precision in Σxy and Σx² and round only m, c and r at the end.
Where this appears in exams
| Exam / class | Typical use |
|---|---|
| CBSE/ICSE Class 11–12 practicals | Drawing a best-fit line, finding a slope from a graph |
| Class 12 chemistry | Beer–Lambert calibration; first-order kinetics from a ln[A] vs t plot |
| Class 12 physics | Ohm's law V–I graphs, resistivity and other slope-based practicals |
| IIT-JAM / GATE / CSIR-NET | Arrhenius plots, Nernst plots, van 't Hoff plots — all "linearise, then fit" |
The pattern to notice: most physical-chemistry equations are deliberately rearranged into y = mx + c form so that a slope becomes a physical constant. Activation energy from an Arrhenius plot is a slope; ΔH from a van 't Hoff plot is a slope. Confirm exam-specific requirements from the current official notification.
Fit your practical data in seconds. Enter the x and y readings and the linear regression tool returns the slope, the intercept and the correlation coefficient — ideal for checking a calibration curve you plotted by hand.
Open the Linear Regression Calculator →Practical-file graphs and slope questions cost easy marks when the method is shaky. ABC Chemistry runs Class 11–12 chemistry coaching at the Gurugram centre and online classes across India — abcchemistry.in.