Tutorials › Exam SRM - Statistics for Risk Modeling › Connecting ANOVA Sums of Squares to R-Squared

Exam SRM · Inference and ANOVA · Tutorial 75 of 926

Connecting ANOVA Sums of Squares to R-Squared

Calculate R-squared from regression ANOVA quantities, justify the sums-of-squares identity, and interpret the fraction of observed response variation accounted for by a fitted model.

Intermediate 10 min read

What You'll Learn

  • Define total, regression, and error sums of squares using observed and fitted responses
  • Derive the sums-of-squares decomposition for ordinary least squares with an intercept
  • Calculate R-squared from raw data or an ANOVA table
  • Explain what R-squared measures in the observed sample
  • Recognize when the usual decomposition does not apply
  • Avoid common errors involving uncentered sums and model interpretation

Why Connect ANOVA Sums of Squares to R-Squared?

A regression ANOVA table separates variation in the observed response into a part associated with fitted values and a part left in the residuals. R-squared summarizes that split as one proportion. The calculation is short, but it depends on using the right sums of squares and on understanding when their decomposition is valid.

This connection is useful when a regression output gives sums of squares rather than R-squared, or when a question asks what fraction of the response variation is accounted for by the fitted model. It is aligned with the SOA Exam SRM (Statistics for Risk Modeling) syllabus.

Definition: For observations \(y_1,\ldots,y_n\), let \(\bar y=\frac{1}{n}\sum_{i=1}^n y_i\), let \(\hat y_i\) be the fitted response, and let \(e_i=y_i-\hat y_i\) be the residual. The total sum of squares, regression sum of squares, and error sum of squares are
$$ SS_{\mathrm{Tot}}=\sum_{i=1}^n(y_i-\bar y)^2,\qquad SS_{\mathrm{Reg}}=\sum_{i=1}^n(\hat y_i-\bar y)^2,\qquad SS_E=\sum_{i=1}^n e_i^2. $$
For ordinary least squares regression with an intercept and \(SS_{\mathrm{Tot}}>0\), \(R^2=SS_{\mathrm{Reg}}/SS_{\mathrm{Tot}}=1-SS_E/SS_{\mathrm{Tot}}\).

The total sum of squares measures the observed response’s variation around its sample mean. The regression sum of squares measures how much the fitted values vary around that same mean. The error sum of squares measures the remaining squared differences between observations and fitted values. All three quantities are nonnegative.

The stated formula uses an ordinary least squares (OLS) fit with an intercept. With an intercept, OLS includes the constant-only fit as a possible model and satisfies the orthogonality conditions needed for the decomposition. The definition of \(SS_{\mathrm{Tot}}\) still makes sense for other fits, but the equality \(SS_{\mathrm{Tot}}=SS_{\mathrm{Reg}}+SS_E\), and hence the equivalence of the two formulas for \(R^2\), need not hold for a model without an intercept or for arbitrary fitted values.

Why the Sums-of-Squares Decomposition Holds

For an OLS model with an intercept, the residuals sum to zero, and the residual vector is orthogonal to every column of the design matrix. The fitted-value vector is a linear combination of those columns, so it is also orthogonal to the residual vector. In particular, \(\sum_{i=1}^n(\hat y_i-\bar y)e_i=0\). These facts give the decomposition directly.

1
Center the observed responses.
Since the model includes an intercept, \(\sum_i e_i=0\), so \(\bar y=\overline{\hat y}\). Write \(y_i-\bar y=(\hat y_i-\bar y)+e_i\).
2
Square and sum.
Expanding the squared expression gives \(SS_{\mathrm{Tot}}=SS_{\mathrm{Reg}}+SS_E+2\sum_i(\hat y_i-\bar y)e_i\).
3
Use OLS orthogonality.
The cross-product is zero: \(\sum_i(\hat y_i-\bar y)e_i=\sum_i\hat y_i e_i-\bar y\sum_i e_i=0\). Therefore \(SS_{\mathrm{Tot}}=SS_{\mathrm{Reg}}+SS_E\).

The first equality in the last step follows because fitted values lie in the design matrix’s column space and OLS residuals are orthogonal to that space. The second term vanishes because the residuals sum to zero. Thus, \[ \frac{SS_{\mathrm{Reg}}}{SS_{\mathrm{Tot}}} =\frac{SS_{\mathrm{Tot}}-SS_E}{SS_{\mathrm{Tot}}} =1-\frac{SS_E}{SS_{\mathrm{Tot}}}. \] This also explains the two common ways to calculate \(R^2\).

Calculating R-Squared from Fitted Values

When observations and fitted values are provided, calculate all relevant quantities using the same observations. First find the observed mean; then compute the centered total, fitted-value, and residual sums of squares. For an OLS model with an intercept, check that the decomposition is satisfied before reporting \(R^2\).

Worked Example: Computing R-Squared from Four Fitted Responses

A hypothetical severity model is fitted by OLS with an intercept to four observations, in thousands of dollars. The observed responses are \(3,3,5,9\), and the fitted responses are \(2,4,6,8\). Calculate \(SS_{\mathrm{Tot}}\), \(SS_{\mathrm{Reg}}\), \(SS_E\), and \(R^2\). The values are supplied as a fitted OLS regression; they are not assumed to be arbitrary predictions.

Method: calculate the centered sums and residual sum directly. The observed mean is \(\bar y=(3+3+5+9)/4=20/4=5\).

The total sum of squares is \(SS_{\mathrm{Tot}}=(3-5)^2+(3-5)^2+(5-5)^2+(9-5)^2=4+4+0+16=24\).

The regression sum of squares is \(SS_{\mathrm{Reg}}=(2-5)^2+(4-5)^2+(6-5)^2+(8-5)^2=9+1+1+9=20\). The residuals are \(3-2=1\), \(3-4=-1\), \(5-6=-1\), and \(9-8=1\). Therefore, \(SS_E=1^2+(-1)^2+(-1)^2+1^2=4\).

Check the decomposition: \(SS_{\mathrm{Reg}}+SS_E=20+4=24=SS_{\mathrm{Tot}}\). The residuals also sum to \(1-1-1+1=0\). Hence \(R^2=SS_{\mathrm{Reg}}/SS_{\mathrm{Tot}}=20/24=5/6=0.8333\), rounded to four decimal places.

The fitted model accounts for about \(83.33\%\) of the observed response variation around the sample mean in these four observations. Common mistake avoided: do not treat the decomposition as automatic for any list of predictions; it is justified here because the values are from an OLS fit with an intercept.

Calculating R-Squared from an ANOVA Table

A regression ANOVA table commonly reports \(SS_{\mathrm{Reg}}\) and \(SS_E\), with \(SS_{\mathrm{Tot}}\) either shown directly or obtained by addition. For an OLS model with an intercept, the total equals the sum of the regression and error sums of squares. Degrees of freedom and mean squares are different ANOVA quantities; they are not substituted for sums of squares in the \(R^2\) formula.

Worked Example: Recovering R-Squared from Regression ANOVA Quantities

A hypothetical OLS model with an intercept uses two predictors and \(16\) observations. Its ANOVA table reports \(SS_{\mathrm{Reg}}=72\) and \(SS_E=48\). Find \(SS_{\mathrm{Tot}}\) and \(R^2\).

Method: add the sums of squares, then form the explained proportion. The model has regression degrees of freedom \(2\), residual degrees of freedom \(16-2-1=13\), and total degrees of freedom \(16-1=15\). These degrees of freedom are consistent with a model containing an intercept and two predictors, but the \(R^2\) calculation uses the sums of squares.

By the OLS decomposition, \(SS_{\mathrm{Tot}}=SS_{\mathrm{Reg}}+SS_E=72+48=120\). Thus, \(R^2=SS_{\mathrm{Reg}}/SS_{\mathrm{Tot}}=72/120=0.6000\). As a check, \(1-SS_E/SS_{\mathrm{Tot}}=1-48/120=1-0.4000=0.6000\).

The fitted model accounts for \(60\%\) of the sample variation in the response around its mean. Common mistake avoided: using the regression degrees of freedom or a mean square in place of \(SS_{\mathrm{Reg}}\) would not give this proportion.

What R-Squared Does—and Does Not—Say

For an OLS regression with an intercept and positive total variation, the decomposition implies \(0\leq R^2\leq1\): both \(SS_{\mathrm{Reg}}\) and \(SS_E\) are nonnegative parts of \(SS_{\mathrm{Tot}}\). An \(R^2\) of \(0\) means the fitted values have no variation around \(\bar y\), as in the constant-only fit. An \(R^2\) of \(1\) means every residual is zero, so the fitted values match the observed responses exactly.

R-squared describes the fitted model’s accounting for variation in the observed response values. It does not say that predictors caused the response, establish that the model’s assumptions are appropriate, or guarantee accurate predictions for new observations. Nor does an \(R^2\) value by itself indicate whether a relationship is practically important. Interpretation should stay tied to the sample and response being analyzed.

For the same response observations, adding predictors to an OLS model with an intercept cannot increase \(SS_E\): the expanded model can always reproduce the original fit by assigning zero coefficients to the added predictors. Since \(SS_{\mathrm{Tot}}\) is unchanged, \(R^2=1-SS_E/SS_{\mathrm{Tot}}\) cannot decrease. An increase in training-sample \(R^2\) therefore does not, by itself, demonstrate that the added predictors are useful.

If a model is fitted without an intercept, the usual centered decomposition may fail, and the formula \(1-SS_E/SS_{\mathrm{Tot}}\) can even be negative. Some software instead reports an uncentered measure based on \(\sum_i y_i^2\); that quantity uses a different baseline and should not be silently treated as the centered \(R^2\) defined here. Always identify the model and the sums of squares used.

Worked Example: Checking the Centering in a Raw-Data Calculation

For a hypothetical OLS regression with an intercept, observed responses are \(12,12,14,18\), and fitted responses are \(11,13,15,17\), in thousands of dollars. Calculate \(R^2\), and assess the tempting calculation \(SS_{\mathrm{Reg}}/\sum_i y_i^2\).

Method: use centered sums of squares for the standard \(R^2\). The observed mean is \(\bar y=(12+12+14+18)/4=56/4=14\). The centered total is \(SS_{\mathrm{Tot}}=(12-14)^2+(12-14)^2+(14-14)^2+(18-14)^2=4+4+0+16=24\).

The fitted mean is \((11+13+15+17)/4=56/4=14\). Thus \(SS_{\mathrm{Reg}}=(11-14)^2+(13-14)^2+(15-14)^2+(17-14)^2=9+1+1+9=20\). The residuals are \(1,-1,-1,1\), so \(SS_E=1+1+1+1=4\). The check is \(20+4=24\); therefore \(R^2=20/24=0.8333\), rounded to four decimal places.

The tempting uncentered denominator is \(\sum_i y_i^2=12^2+12^2+14^2+18^2=144+144+196+324=808\). The ratio \(20/808\) is approximately \(0.0248\), but it is not the standard centered \(R^2\): it compares the regression sum of squares to an uncentered sum that is not \(SS_{\mathrm{Tot}}\). The correct standard calculation uses \(SS_{\mathrm{Tot}}=24\). Common mistake avoided: do not replace the centered total variation around \(\bar y\) with the raw sum of squared responses.

Common Calculation Traps

  • Mixing definitions. Use \(SS_{\mathrm{Reg}}=\sum_i(\hat y_i-\bar y)^2\) and \(SS_{\mathrm{Tot}}=\sum_i(y_i-\bar y)^2\) for the centered decomposition.
  • Ignoring the intercept condition. The familiar identity and the usual range from zero to one are justified for OLS with an intercept, not for every possible prediction rule.
  • Using the wrong denominator. \(R^2\) is a fraction of total response variation, not a ratio to \(\sum_i y_i^2\) under the centered definition.
  • Interpreting “accounted for” as “caused.” R-squared is a descriptive measure of the fitted sample, not a causal conclusion.
  • Reporting a percentage without checking the arithmetic. Confirm \(SS_{\mathrm{Tot}}=SS_{\mathrm{Reg}}+SS_E\) before converting the proportion to a percentage.
Key takeaway: For an OLS regression with an intercept and \(SS_{\mathrm{Tot}}>0\), \(SS_{\mathrm{Tot}}=SS_{\mathrm{Reg}}+SS_E\), so \(R^2=SS_{\mathrm{Reg}}/SS_{\mathrm{Tot}}=1-SS_E/SS_{\mathrm{Tot}}\). It is the fraction of observed response variation around the sample mean accounted for by the fitted values.

Check Your Understanding

For each problem, use the centered definition and check whether the stated model conditions support the usual decomposition.

  1. An OLS model with an intercept has \(SS_{\mathrm{Reg}}=45\) and \(SS_E=30\). Find \(SS_{\mathrm{Tot}}\) and \(R^2\). (Answer: \(SS_{\mathrm{Tot}}=75\), \(R^2=0.6000\).)
  2. A response has observed mean \(10\), total sum of squares \(200\), and residual sum of squares \(50\) from an OLS fit with an intercept. Find the regression sum of squares and \(R^2\). (Answer: \(SS_{\mathrm{Reg}}=150\), \(R^2=0.7500\).)
  3. An OLS regression with an intercept gives \(SS_{\mathrm{Reg}}=84\) and \(R^2=0.7000\). Find \(SS_{\mathrm{Tot}}\) and \(SS_E\). (Answer: \(SS_{\mathrm{Tot}}=120\), \(SS_E=36\).)
  4. For an OLS fit with an intercept, \(SS_{\mathrm{Tot}}=160\) and \(R^2=0.6250\). Find \(SS_{\mathrm{Reg}}\) and \(SS_E\), then state the percentage of sample variation accounted for. (Answer: \(SS_{\mathrm{Reg}}=100\), \(SS_E=60\), and \(62.50\%\).)
  5. A model without an intercept has centered \(SS_{\mathrm{Tot}}=40\), \(SS_{\mathrm{Reg}}=30\), and \(SS_E=20\). Can the centered OLS decomposition be used to claim \(R^2=30/40\)? Explain using the supplied sums. (Answer: No. \(SS_{\mathrm{Reg}}+SS_E=50\ne40\), so the centered decomposition does not hold; \(30/40\) is not justified as the usual \(R^2\) by these quantities.)
Clinical Biostats