Tutorials › Regression Analysis (Undergraduate) › Residual Sum of Squares

Model Fit and Nested Comparisons · Tutorial 245 of 991

Residual Sum of Squares

Calculate residual sum of squares from observed and fitted outcomes, and interpret what its value says about a model’s fit.

Intermediate 9 min read

What You'll Learn

  • Define a regression residual and residual sum of squares.
  • Calculate fitted values and residual sum of squares for a least-squares line.
  • Keep track of the units of residuals and squared residuals.
  • Interpret residual sum of squares without treating it as a percentage or a measure of causation.
  • Recognize when two residual sum of squares values cannot be compared fairly.

Why Summarize Residuals?

A regression model gives a fitted outcome for each observed case. Comparing each fitted outcome with what was actually observed shows where the model misses: some fitted values are too high, and others are too low. A summary is useful because a list of signed differences can conceal the overall size of those discrepancies. Residual sum of squares provides one such summary by squaring each difference before adding them.

Residual sum of squares is a measure of fit for a particular model and data set. It is not a test of whether the model is true, a measure of causation, or by itself a percentage of variation explained. Its units and the data used to calculate it matter when interpreting or comparing its value.

Definition and Model Setup

Suppose there are \(n\) observed outcomes \(y_1,\ldots,y_n\). Once a regression model has been fitted, let \(\hat{y}_i\) be the fitted outcome for case \(i\), calculated using that case’s predictor values. The residual is the observed outcome minus the fitted outcome.

Definition: The residual for case \(i\) is \(e_i=y_i-\hat{y}_i\). The residual sum of squares, abbreviated RSS, is the sum of the squared residuals across all \(n\) cases:
$$ \operatorname{RSS}=\sum_{i=1}^{n} e_i^2 =\sum_{i=1}^{n}(y_i-\hat{y}_i)^2. $$

For example, in a simple linear regression, a common model is \(y_i=\beta_0+\beta_1x_i+\varepsilon_i\). Here \(x_i\) is the predictor, \(\beta_0+\beta_1x_i\) describes the model’s mean outcome at that predictor value, and \(\varepsilon_i\) is the deviation of the observed outcome from that mean. After estimating the coefficients, the fitted value is \(\hat{y}_i=\hat{\beta}_0+\hat{\beta}_1x_i\). A residual is calculated from the observed and fitted values; it is not the unobserved error \(\varepsilon_i\).

The calculation of RSS requires observed and fitted outcomes but does not require a normal distribution or any other distributional assumption. In the usual linear regression model, assumptions such as a correctly specified linear mean and independent errors with mean zero and constant variance matter for regression inference. They are not needed to perform the arithmetic that defines RSS.

Squaring makes every contribution nonnegative, so residuals of opposite signs cannot cancel. The square also gives larger discrepancies more weight: a residual of 4 contributes \(16\), whereas a residual of 2 contributes \(4\). If outcomes are measured in points, residuals are in points and RSS is in points squared.

RSS and Least-Squares Fitting

In least-squares regression, the coefficients are chosen to make RSS as small as possible among the coefficient values allowed by the model. Thus RSS is both a summary of the remaining discrepancies after fitting and the quantity that least squares minimizes. It is not generally zero: a fitted line or other model may not pass through every observed outcome.

A short derivation illustrates why fitting a least-squares line with an intercept produces residuals whose sum is zero. Fix a slope \(b\) and choose an intercept \(a\). The sum of squared residuals is \(Q(a)=\sum_{i=1}^{n}(y_i-a-bx_i)^2\). Differentiating with respect to \(a\) gives \(-2\sum_{i=1}^{n}(y_i-a-bx_i)\). At a minimum this derivative is zero, so the residuals sum to zero. This condition concerns the signed residuals; it does not imply that their squares sum to zero.

Worked Example: Calculating RSS for a Least-Squares Line

Suppose a hypothetical instructor records practice time \(x\), in hours, and quiz score \(y\), in points, for four learners. The data are \((1,10)\), \((2,12)\), \((3,11)\), and \((4,15)\). Fit a least-squares line with an intercept and calculate its RSS.

The model is \(y_i=\beta_0+\beta_1x_i+\varepsilon_i\), with a linear mean in practice time. Least squares chooses the intercept and slope to minimize the squared residuals for these four cases. The sample means are \(\bar{x}=2.5\) hours and \(\bar{y}=12\) points. The slope is

$$ \hat{\beta}_1 =\frac{\sum (x_i-\bar{x})(y_i-\bar{y})} {\sum (x_i-\bar{x})^2} =\frac{7}{5} =1.4\ \text{points per hour}. $$

The intercept is \(\hat{\beta}_0=\bar{y}-\hat{\beta}_1\bar{x}=12-(1.4)(2.5)=8.5\) points. The fitted line is therefore \(\hat{y}=8.5+1.4x\), with fitted scores in points. This calculation uses the observed predictor and outcome values; it makes no claim that additional practice causes a score change.

Practice time \(x_i\) (hours)Observed score \(y_i\) (points)Fitted score \(\hat{y}_i\) (points)Residual \(e_i\) (points)\(e_i^2\) (points squared)
1109.90.10.01
21211.30.70.49
31112.7-1.72.89
41514.10.90.81

For instance, at \(x=3\) hours the fitted score is \(8.5+(1.4)(3)=12.7\) points, so the residual is \(11-12.7=-1.7\) points. Summing the four squared residuals gives

$$ \operatorname{RSS} =(0.1)^2+(0.7)^2+(-1.7)^2+(0.9)^2 =0.01+0.49+2.89+0.81 =4.20\ \text{points}^2. $$

For these four learners, the sum of squared differences between observed and fitted scores is \(4.20\) points squared. The negative residual at three hours indicates that the fitted score is above the observed score; its square contributes positively to RSS.

Interpreting the Value

RSS combines the discrepancies for all included cases into one number. A smaller RSS means smaller total squared residuals for the particular observations and response scale used. It does not describe how the residuals are distributed among cases: many moderate discrepancies and one relatively large discrepancy can contribute quite differently while producing the same total.

A residual has the same units as the outcome, but RSS has squared outcome units. If the response is recorded in kilograms, RSS is in kilograms squared. The numerical value alone is therefore not an average error in the original units. To summarize a typical discrepancy in the outcome’s units, other summaries can be used, but RSS itself remains the sum of squared discrepancies.

A value of zero means every observed outcome equals its fitted value on the included cases. That is a perfect fit to those observations, not proof that the model captures the underlying process or will predict new outcomes perfectly. Conversely, a nonzero RSS is expected whenever at least one observed outcome differs from its fitted value.

Worked Example: Summing Residuals From Fitted Outcomes

Suppose a hypothetical packaging process is evaluated for five packages. A fitted regression model gives the predicted weights shown below. The model is already fitted; the task is to calculate and interpret RSS, not to infer how its coefficients were estimated.

PackageObserved weight (g)Fitted weight (g)Residual (g)Squared residual (g squared)
150250024
2499500-11
350550411
4497500-39
550150011

For package 4, for example, \(e_4=497-500=-3\) g and \(e_4^2=(-3)^2=9\) g squared. The full calculation is

$$ \operatorname{RSS} =2^2+(-1)^2+1^2+(-3)^2+1^2 =4+1+1+9+1 =16\ \text{g}^2. $$

The observed and fitted weights differ by a total of \(16\) squared grams under this definition. The residuals sum to zero, \(2-1+1-3+1=0\), as expected for a least-squares fit with an intercept. That signed sum alone would hide the discrepancies; RSS retains their magnitudes by squaring them.

Comparisons and a Common Pitfall

RSS can help describe and compare model fit, but a comparison is meaningful only when the quantities are calculated on comparable data and outcomes. In particular, the cases included and the response scale should be the same. RSS also depends on the number of observations: adding cases adds more squared terms, so values calculated from different sets or counts of cases are not automatically comparable.

Worked Example: Changing the Outcome Units

Return to the five hypothetical package weights. Their RSS was \(16\ \text{g}^2\). Suppose the same observed and fitted weights are both converted to kilograms. Since \(1\) g is \(0.001\) kg, each residual in kilograms is its residual in grams multiplied by \(0.001\). The residuals become \(0.002\), \(-0.001\), \(0.001\), \(-0.003\), and \(0.001\) kg.

The RSS in kilograms squared is

$$ \operatorname{RSS} =(0.002)^2+(-0.001)^2+(0.001)^2+(-0.003)^2+(0.001)^2 =0.000016\ \text{kg}^2. $$

The numerical RSS is different because the units have changed, but the observations and discrepancies are the same: \(16\ \text{g}^2=0.000016\ \text{kg}^2\). Comparing these numerical values as if they were on the same scale would be misleading.

A common mistake is to say that the model with the smaller raw RSS is always better. That conclusion may be unjustified if the models were assessed on different observations or outcome scales. For example, changing the outcome from grams to kilograms changes the numerical RSS without changing the fit in any substantive sense. Compare RSS values only after checking that the response and cases match, and interpret the result in squared response units.

Another mistake is to treat RSS as a percentage. It is a sum of squared discrepancies, not a fraction of outcomes or a percentage of variation explained. A percentage-based fit summary requires additional quantities and definitions; RSS alone does not supply one.

Key takeaway: Calculate each residual as observed outcome minus fitted outcome, square each residual, and sum the squares. RSS is nonnegative, has squared response units, and describes the total squared discrepancy for the specified model and cases.

Check Your Understanding

Try these questions without looking back.

  1. An observed outcome is 18 units and its fitted value is 21 units. What is the residual, and what is its contribution to RSS?
  2. For residuals \(1\), \(-2\), and \(3\) points, calculate RSS and state its units.
  3. Why does a negative residual still make a positive contribution to RSS?
  4. What does an RSS of zero mean for the fitted and observed outcomes in the cases included?
  5. Why is it misleading to compare numerical RSS values when one is calculated in grams and the other in kilograms?