How To Find Sum Of Squared Residuals

7 min read

How to Find the Sum of Squared Residuals: A Step-by-Step Guide

The sum of squared residuals (often abbreviated as SSR, SSE, or RSS depending on the textbook) measures how far your observed data points sit from the values predicted by a regression model. Because of that, in simple terms, it tells you how much error your line of best fit still carries after it has been fitted to the data. Learning how to find the sum of squared residuals is one of the most practical skills in statistics, because it sits at the heart of least squares regression, goodness-of-fit measures such as R², and even hypothesis testing for slope coefficients. This guide walks you through the concept, the formula, a fully worked example, and the common traps to avoid.

What Is a Residual?

Before computing anything, you need to understand what a residual is. A residual is simply the vertical distance between an actual observed value and the value your model predicts:

e = y − ŷ

Here, y is the observed value and ŷ (read as "y-hat") is the predicted value from your regression equation. A positive residual means the model underpredicted; a negative residual means it overpredicted.

If you add raw residuals together, they will always sum to zero in an ordinary least squares fit, because positive and negative errors cancel out. That is exactly why we square them first: squaring removes the sign, keeps every error as a positive contribution, and gives extra weight to large mistakes.

The Formula

The sum of squared residuals is written as:

SSR = Σ (yᵢ − ŷᵢ)²

Where:

  • yᵢ = the observed value of the dependent variable for observation i
  • ŷᵢ = the predicted value for observation i
  • Σ = "the sum of", taken over all n observations

For a simple linear regression line ŷ = b₀ + b₁x, the least squares method chooses b₀ and b₁ so that this sum is as small as possible. That is the meaning of "least squares."

Step-by-Step Procedure

Follow these steps whenever you are asked to find the sum of squared residuals by hand:

  1. Fit the regression line. Calculate the slope b₁ = Sxy / Sxx and the intercept b₀ = ȳ − b₁x̄.
  2. Plug each x value into the equation to get a predicted value ŷ for every observation.
  3. Subtract each predicted value from its matching observed value: e = y − ŷ.
  4. Square each residual so that all values become positive.
  5. Add all squared residuals together. That total is your sum of squared residuals.

A Complete Worked Example

Suppose a teacher records hours studied (x) and quiz scores (y) for five students:

x (hours) y (score)
1 2
2 4
3 5
4 4
5 5

Step 1 — Find the means. x̄ = 15 / 5 = 3 and ȳ = 20 / 5 = 4.

Step 2 — Compute Sxx and Sxy.

  • Sxx = Σ(x − x̄)² = 4 + 1 + 0 + 1 + 4 = 10

  • Sxy = Σ(x − x̄)(y − ȳ) = (–2)(–2) + (–1)(0) + (0)(1) + (1)(0) + (2)(1) = 4 + 0 + 0 + 0 + 2 = 6

Step 3 — Calculate the regression coefficients.

  • Slope: b₁ = Sxy / Sxx = 6 / 10 = 0.6
  • Intercept: b₀ = ȳ − b₁x̄ = 4 − 0.6(3) = 2.2

The fitted line is ŷ = 2.2 + 0.6x.

Step 4 — Generate predictions and residuals.

x y ŷ = 2.2 + 0.6x Residual (e = y − ŷ) Squared Residual (e²)
1 2 2.8 –0.That's why 8 0. 64
2 4 3.On top of that, 4 0. Which means 6 0. 36
3 5 4.But 0 1. Day to day, 0 1. On top of that, 00
4 4 4. 6 –0.6 0.36
5 5 5.Still, 2 –0. 2 0.

Step 5 — Sum the squared residuals. SSR = 0.64 + 0.36 + 1.00 + 0.36 + 0.04 = 2.40

This value (2.40) is the minimum possible sum of squared vertical distances for any straight line drawn through these five points.

Common Pitfalls to Avoid

  1. Confusing SSR with other sums of squares. In many textbooks, SSR stands for Sum of Squared Residuals (also called SSE, or Error Sum of Squares). That said, some software packages and texts use SSR for Regression Sum of Squares (explained variation). Always check the notation key: if the context is "minimizing SSR," it refers to residuals; if the context is "partitioning total variation," SSR often means regression.
  2. Forgetting to square before summing. Summing raw residuals will always yield zero (subject to rounding) in OLS, giving a false impression of perfect fit.
  3. Using the wrong x-values. Ensure the x-values used to calculate ŷ are the exact same ones paired with the observed y-values in the dataset. Mismatched rows are a frequent source of error in spreadsheet work.
  4. Rounding intermediate coefficients. Rounding b₀ or b₁ to one decimal place before calculating ŷ introduces "round-off error" that inflates the final SSR. Carry at least four to six decimal places through the calculation and round only the final answer.

Interpreting the Result

A lower SSR indicates a tighter fit, but the raw number is scale-dependent: doubling the y-units quadruples the SSR. For scale-free comparison, analysts typically convert SSR into:

  • Mean Squared Error (MSE) = SSR / (n − 2) for simple regression, which estimates the error variance σ². Also, - Root Mean Squared Error (RMSE) = √MSE, expressed in the original units of y. - R² = 1 − (SSR / SST), where SST is the total sum of squares (Σ(y − ȳ)²). In the example above, SST = 6, so R² = 1 − (2.4 / 6) = 0.60, meaning the model explains 60% of the score variation.

Using Software

While hand calculation builds intuition, real-world datasets require software. The command is trivial in every major environment:

  • R: sum(residuals(lm(y ~ x))^2) or deviance(lm(y ~ x))
  • Python (statsmodels): model.fit().ssr or sum((y - model.predict(x))**2)
  • Excel: Use LINEST to get coefficients, compute predicted values in a column, then =SUMSQ(observed_range, predicted_range).
  • TI-84: Run LinReg(ax+b), then sum((L2 - Y1(L1))^2) where L1/L2 hold x/y and Y1 stores the regression equation.

Conclusion

The sum of squared residuals is more than a computational exercise; it is the objective function that defines the "best" line in ordinary least squares regression. Mastering its calculation—whether by hand for a five-point homework problem or via code for a million-row dataset—gives you direct insight into how

how the estimated coefficients respond to the shape of the data, the presence of outliers, or the inclusion of additional predictors. Because each residual is squared before summation, the metric gives greater weight to observations with larger prediction errors, making it sensitive to outliers and influential points. Which means a single extreme value can therefore produce a deceptively small SSR if the regression line bends toward it, even though the overall fit may be poor. This sensitivity is why residual diagnostics—plots, put to work, and Cook’s distance—are essential companions to the SSR itself.

In practice, SSR should be interpreted alongside the other quantities that standardize its scale. Dividing by the degrees of freedom yields a variance estimate, taking the square root returns the result to the original units of the outcome, and comparing it with total variation provides a proportion of explained variance. Together, these transformations turn a raw sum into actionable insight Small thing, real impact. And it works..

Pulling it all together, the sum of squared residuals is the core objective behind ordinary least squares, but it is only one piece of regression evaluation. Here's the thing — its calculation is simple, yet its meaning depends on context, scale, and assumptions. By using SSR correctly—and complementing it with MSE, RMSE, R², and residual analysis—the analyst can fairly assess model performance and make informed decisions about whether the fitted line truly represents the underlying relationship.

New Additions

Hot New Posts

Similar Vibes

A Few More for You

Thank you for reading about How To Find Sum Of Squared Residuals. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home