The sum of squared residuals (SSR) measures how far a set of data points falls from a fitted model, such as a regression line. You find it by calculating each residual (observed value minus predicted value), squaring each residual, and adding them all together. A smaller SSR means the model fits the data more closely. This guide walks through the calculation step by step, using a simple worked example, and covers the mistakes and checks that matter most.
What You'll Need
- A set of paired data points (an x-value and a y-value for each observation).
- A model that produces a predicted y-value for each x-value. This can be a regression equation you have already fitted, or a set of predictions supplied with the data.
- The formula for the model, or the predicted values themselves.
- A calculator or spreadsheet for the arithmetic.
Step-by-Step
- Write down your data pairs. List each observation as (x, y). Keep the rows together so you do not mix up which y belongs to which x. For a small example, suppose you have four points: (1, 2), (2, 4), (3, 5), and (4, 4).
- Obtain the predicted value for each x. If you have a fitted model such as y = a + bx, substitute each x into the equation to get the predicted y (often written ŷ). If predictions are already provided, use them directly. For illustration, suppose the model predicts ŷ = 1.5 + 0.7x. Then the predicted values for x = 1, 2, 3, 4 are 2.2, 2.9, 3.6, and 4.3.
- Calculate each residual. The residual is the observed y minus the predicted ŷ: residual = y − ŷ. Do the subtraction in that order. Using the example: 2 − 2.2 = −0.2; 4 − 2.9 = 1.1; 5 − 3.6 = 1.4; 4 − 4.3 = −0.3.
- Square each residual. Multiply each residual by itself. Squaring removes the sign, so positive and negative misses both count as error. Continuing: (−0.2)² = 0.04; (1.1)² = 1.21; (1.4)² = 1.96; (−0.3)² = 0.09.
- Add the squared residuals. Sum all the squared values: 0.04 + 1.21 + 1.96 + 0.09 = 3.30. That total is the sum of squared residuals for this model and these four points.
- Check your arithmetic. Re-add the squared residuals in a different order, and confirm that no residual was squared with the wrong sign or paired with the wrong x. A quick sanity check: the SSR cannot be negative, and it should be zero only if every prediction matches its observed value exactly.
- Interpret the result in context. The SSR is in squared units of the y-variable, so it is not directly comparable to the original measurements. It is most useful for comparing models fitted to the same data: the model with the smaller SSR has smaller total squared error. To compare across datasets or put the error back into original units, use the mean squared residual (SSR divided by the number of residuals) or the root mean squared residual (the square root of that mean).
Common Mistakes
- Subtracting in the wrong order. The residual is observed minus predicted, not predicted minus observed. Reversing the order flips every sign; because the values are squared, the final SSR is unchanged, but any intermediate table or interpretation of residuals will be wrong.
- Forgetting to square before summing. Adding the raw residuals first can produce a misleadingly small total, because positive and negative residuals cancel. The sum of raw residuals is not the SSR.
- Mismatching predictions and observations. If the predicted value for one x is paired with the observed y of another x, the residuals are meaningless. Keep rows aligned.
- Using the wrong model. The SSR depends entirely on the predictions used. Recomputing with a different fitted equation gives a different SSR, so state which model the calculation refers to.
- Rounding too early. Rounding predicted values or residuals before squaring can shift the total noticeably, especially with many data points. Carry full precision through the squaring step and round only the final answer.
Tips
- Build a table with columns for x, y, predicted ŷ, residual, and squared residual. It makes the calculation easy to audit and to correct.
- In a spreadsheet, use separate columns for each stage rather than one long formula. This makes errors visible and lets you check intermediate values.
- Remember that SSR is one part of the picture. The total variation in y (the total sum of squares) and the variation explained by the model together determine measures such as R-squared. A small SSR relative to the total variation indicates a good fit.
- If you are comparing models, keep the dataset identical. Adding or removing data points changes the SSR, so comparisons are only fair on the same observations.
- For a quick check, the mean of the residuals in a model fitted with an intercept is typically close to zero; a large average residual suggests something is off in the predictions or the pairing.
Troubleshooting
- The SSR comes out negative. This is arithmetically impossible. Check for a sign error in the squaring step or for a spreadsheet formula that subtracts instead of adds.
- The SSR is far larger than expected. Look for a data-entry error, a mismatched prediction, or a model that does not fit the data. Recheck a few rows by hand.
- The SSR is zero. This happens only when every prediction equals its observed value. Confirm that the predicted values were not accidentally copied from the observed values.
- Results differ between two calculations. Differences usually come from rounding, from using a different model, or from including a different number of data points. Standardise the inputs and the rounding rule.
- You only have residuals, not predictions. You can still compute the SSR: square each residual and add them. You do not need the original x and y values if the residuals are already correct.
Frequently Asked Questions
What is the difference between a residual and an error?
A residual is the difference between an observed value and the value predicted by a fitted model, calculated from your sample. An error usually refers to the difference between an observed value and the true, unknown value. In practice, residuals are what you can compute.
Can the sum of squared residuals be negative?
No. Squaring any real number gives a non-negative result, so the sum of squared residuals is always zero or positive.
Why square the residuals instead of taking absolute values?
Squaring gives more weight to large misses and makes the mathematics of fitting models (such as least squares) tractable. Absolute values are also used in some methods, but squared residuals are the standard in ordinary least squares.
Is a lower sum of squared residuals always better?
For models fitted to the same data, a lower SSR indicates a closer fit. But adding parameters can reduce the SSR without improving genuine predictive performance, so SSR should be considered alongside other measures and the purpose of the model.
How is the sum of squared residuals related to R-squared?
R-squared is calculated from the ratio of the SSR to the total sum of squares of the y-values around their mean. A smaller SSR relative to that total variation corresponds to a higher R-squared.
Do I need the regression equation to find the SSR?
No. If you already have the residuals, you can square and sum them directly. The equation is needed only to generate the predicted values in the first place.