Understanding the residual calculator — concept and principle
This calculator finds the residuals of a straight-line fit: how far each observed y value lies above or below the line. It fits the least-squares line for you or uses a line you supply, and reports each residual, their sum, the sum of squares, the largest residual and the residual standard error. Use it for statistics homework, checking a regression, and spotting outliers or curvature.
How it is calculated
- Prediction: ŷ = m·x + b.
- Residual: e = y − ŷ (positive above the line, negative below).
- Least-squares line: m = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², b = ȳ − m·x̄.
- Sum of squared residuals: SSE = Σe².
- Residual standard error: √(SSE ÷ (n − 2)).
The principle
A residual is the part of each observation the line does not explain. Least squares chooses the line that makes the sum of squared residuals as small as possible; squaring treats points above and below alike and penalises big misses more. One consequence is that least-squares residuals always add up to zero, and the line passes through the point (x̄, ȳ). Dividing SSE by n − 2 instead of n accounts for the two numbers, slope and intercept, estimated from the same data.
Worked example
Default data: x = 1 to 6, y = 3.1, 4.9, 7.2, 8.8, 11.3, 12.7; least-squares line.
- x̄ = 3.5, ȳ = 8; Σ(x − x̄)(y − ȳ) = 34.4 and Σ(x − x̄)² = 17.5.
- m = 34.4 ÷ 17.5 ≈ 1.96571; b = 8 − 1.96571 × 3.5 = 1.12. Line: ŷ = 1.96571x + 1.12.
- Residuals: 0.0142857, −0.151429, 0.182857, −0.182857, 0.351429, −0.214286; their sum is 0.
- SSE = 0.259429.
- Largest residual: 0.351429 at point 5. Residual standard error = √(0.259429 ÷ 4) ≈ 0.254671.
How to read the result
Small residuals relative to the y values mean a good fit. The residual standard error is the typical size of a miss, in y units. Look at the pattern: residuals that alternate randomly in sign, as here, suggest a straight line is fine; a curve shape, a funnel shape or one residual much larger than the rest point to a curved relationship, changing variance or an outlier.
Common mistakes
- Computing ŷ − y instead of y − ŷ, which flips every sign.
- Expecting residuals from your own line to sum to zero; only the least-squares line guarantees that.
- Judging fit by the residual sum, which is always zero for least squares; use SSE or the standard error.
- Ignoring a pattern in the residuals because R² is high.
Frequently asked questions
What does a positive residual mean?
The observed value is above the line; the model underestimated it.
Why do least-squares residuals sum to zero?
Because the fitted intercept places the line through (x̄, ȳ), balancing positive and negative misses.
What is a residual plot?
A graph of residuals against x or ŷ, used to spot curvature, changing spread and outliers.
Sources: NIST/SEMATECH e-Handbook of Statistical Methods, §4.1.4.1 Linear Least Squares Regression