What R-Squared Measures
A least-squares regression line summarizes how fitted response values vary with a predictor. The coefficient of determination, written \(R^2\), compares that fitted variation with the total variation in the observed responses. It gives a compact measure of how much of the response's variation around its mean is represented by the fitted values.
The calculation depends on three sums of squares. The total sum of squares measures variation of the observed responses around their mean. The fitted sum of squares measures variation of the fitted responses around that same mean. The residual sum of squares measures the squared differences between observed and fitted responses. For ordinary least squares with an intercept, the total sum of squares is the sum of the fitted and residual sums of squares.
The name \(SSR\) is sometimes used differently in other texts, so keep the definition beside the abbreviation: in this tutorial, \(SSR\) is the sum of squared deviations of fitted responses from \(\bar y\), while \(SSE\) is the sum of squared residuals. The formulas for \(R^2\) are not interchangeable with a ratio that puts \(SSE\) in the numerator.
Why the Two Formulas Agree
The equality of the two calculations follows from the least-squares decomposition of variation. The relevant condition is that the fitted values come from ordinary least squares with an intercept. Under that condition, residuals sum to zero and are orthogonal to fitted values. These properties make the cross-product in the expansion vanish.
Squaring both sides and summing over observations gives the identity below. The cross-product is zero because \(\sum e_i\hat y_i=0\) and \(\sum e_i=0\).
Thus \(SST=SSR+SSE\). Dividing by \(SST\), when \(SST>0\), gives \(1=SSR/SST+SSE/SST\). Rearranging yields both formulas for \(R^2\). This is why a calculation using fitted sums and one using residual sums must produce the same result, apart from rounding.
The identity is not guaranteed for a fit constrained to pass through the origin, because that fit does not include an intercept. Do not apply the centered decomposition automatically to that different least-squares setup. Here, all formulas and examples refer to a least-squares fit with an intercept.
Worked Example: Using the Residual Sum of Squares
A hypothetical insurer models quarterly service expense per policy using a least-squares regression with an intercept. For a sample of six quarters, the total sum of squares is \(SST=150\) (in squared dollars), and the residuals, in dollars, are \(-2, 1, 0, 2, -1, 0\). Calculate \(R^2\), and state the fitted sum of squares.
Method. Calculate \(SSE\) by squaring and summing the residuals, then use \(R^2=1-SSE/SST\). This uses the residual version of the formula and avoids treating unexplained variation as explained variation.
First compute the residual sum of squares:
The fitted sum of squares is the remainder after removing residual variation from total variation:
Therefore,
To four decimal places, \(R^2=0.9333\). In this sample, 93.33% of the observed response variation around its mean is represented by the fitted values. As a check, \(SSR/SST=140/150=0.9333\), the same value. The common mistake is reporting \(SSE/SST=0.0667\) as \(R^2\); that ratio is the residual fraction, so it must be subtracted from 1.
Calculating the Sums from Observed Responses
Sometimes the problem gives response values and a fitted line rather than the sums of squares. In that case, calculate \(\bar y\), the fitted values, and the residuals before forming the sums. The centered deviations \(y_i-\bar y\) determine \(SST\); the residuals \(y_i-\hat y_i\) determine \(SSE\). With an intercept, \(SSR\) can then be found either from the fitted values or from \(SST-SSE\).
Worked Example: Computing R-Squared from a Small Data Set
A hypothetical operations team fits the line \(\hat y=8+2x\) to five quarterly workload observations, where \(x=1,2,3,4,5\). The observed responses are \(9,13,14,17,17\), respectively. Calculate \(SST\), \(SSE\), \(SSR\), and \(R^2\).
Method. Find the fitted values from the line, then calculate centered response deviations and residuals. This explicitly separates total variation from the variation left unexplained by the fit.
The fitted values are \(10,12,14,16,18\). Subtract each fitted value from its observed response to find the residuals:
The mean response is
The centered observed responses are \(-5,-1,0,3,3\), so
The residual sum of squares is
Using the decomposition,
To four decimal places, \(R^2=0.9091\), or 90.91% of the total response variation. As a direct check, the fitted values have mean 14 and deviations \(-4,-2,0,2,4\), whose squares sum to \(16+4+0+4+16=40\). The fitted-sum calculation \(SSR/SST=40/44\) agrees. The common mistake is to use the residuals as deviations from \(\bar y\); residuals are deviations from fitted values and belong in \(SSE\), not \(SST\).
Using Summary Statistics
A data set need not be listed observation by observation. If the sample size, \(\sum y_i\), and \(\sum y_i^2\) are supplied, the total sum of squares can be found without first writing every centered response. Expanding the definition gives
This identity is useful when the problem also supplies \(SSE\): calculate \(SST\) from the summary totals, then obtain \(SSR\) and \(R^2\). The summary values and the residual sum of squares must refer to the same observations and the same least-squares fit with an intercept.
Worked Example: Finding R-Squared from Summary Totals
For a hypothetical regression of monthly processing time on workload, a least-squares fit with an intercept uses \(n=8\) observations. The response totals are \(\sum y_i=120\) and \(\sum y_i^2=1900\), and the fit has \(SSE=35\). Find \(SST\), \(SSR\), and \(R^2\).
Method. Use the summary-statistic identity to find total variation, then use \(SST=SSR+SSE\). This avoids confusing the uncentered sum \(\sum y_i^2\) with the total sum of squares.
First calculate the correction for the response mean:
Therefore,
The fitted sum of squares and coefficient of determination are
To four decimal places, \(R^2=0.6500\). The decomposition check is \(65+35=100\). The residual fraction is \(35/100=0.35\), and \(1-0.35=0.65\), as required. A common error is to use \(1900\) as \(SST\); that omits the centering correction \(1800\) and gives the wrong denominator.
Interpreting and Checking R-Squared
For a least-squares fit with an intercept and nonconstant responses, \(R^2\) is between 0 and 1. A value near 1 means the residual sum of squares is small relative to total response variation; a value near 0 means the fitted values account for little of that variation around \(\bar y\). The ratio is dimensionless: changing the response from dollars to cents multiplies \(SST\) and \(SSE\) by the same squared conversion factor, leaving \(R^2\) unchanged.
The interpretation is specific. \(R^2\) describes variation in the observed responses for the data and fit being analyzed. It does not establish that the predictor causes the response, and it does not guarantee accurate predictions for new observations. A high value can coexist with poor predictions outside the observed range, while a low value can occur even when a fitted slope is useful for a particular purpose. Those questions require more than the sums used to calculate \(R^2\).
Before accepting a numerical answer, check that the quantities are centered and correctly assigned:
- \(SST\) uses \(y_i-\bar y\), not \(y_i-\hat y_i\).
- \(SSE\) uses the residuals \(y_i-\hat y_i\), squared and summed.
- \(SSR\) uses \(\hat y_i-\bar y\), or can be obtained as \(SST-SSE\) under the stated conditions.
- The decomposition \(SST=SSR+SSE\) should hold, and \(R^2\) should agree from both formulas.
If \(SST=0\), every observed response equals its mean. In that case the displayed ratio for \(R^2\) has a zero denominator and is undefined; do not report a value by dividing by zero. For nonconstant responses and a least-squares fit with an intercept, the decomposition also gives a useful arithmetic check: both \(SSR\) and \(SSE\) are nonnegative, and neither should exceed \(SST\).
Check Your Understanding
For each problem, assume the sums come from a least-squares regression with an intercept and round \(R^2\) to four decimal places when needed.
- A fit has \(SST=80\) and \(SSE=12\). Find \(SSR\) and \(R^2\). (Answer: \(SSR=68\), \(R^2=0.8500\))
- A fit uses \(n=5\) responses with \(\sum y_i=45\), \(\sum y_i^2=425\), and \(SSE=20\). Find \(SST\), \(SSR\), and \(R^2\). (Answer: \(SST=20\), \(SSR=0\), \(R^2=0.0000\))
- A regression has \(SST=240\) and fitted sum of squares \(SSR=198\). Find \(SSE\) and \(R^2\). (Answer: \(SSE=42\), \(R^2=0.8250\))
- For four observations, the response values are \(4,7,8,11\), and the residual sum of squares is \(5\). Find \(SST\), \(SSR\), and \(R^2\). (Answer: \(SST=25\), \(SSR=20\), \(R^2=0.8000\))
- Two least-squares fits with intercepts use the same response observations, for which \(SST=400\). Fit A has \(SSE=120\), and Fit B has \(SSE=90\). Find each \(R^2\) and the difference in their \(R^2\) values. (Answer: Fit A \(R^2=0.7000\), Fit B \(R^2=0.7750\), difference \(=0.0750\), or 7.50 percentage points)