liveBook · Manning

Regression sum of squares

As explained in Statistics Every Programmer Needs

The sum of squares regression is the sum of squared differences between predicted response values and their mean.

Regression sum of squares (SSR) measures the variability in observed responses explained by a fitted regression. For response values y, predictions ŷ, and response mean ȳ, calculate SSR as Σ(ŷ − ȳ)². Unlike total sum of squares, SSR uses predictions rather than observed values and excludes unexplained residual variation. section 4.2.3

Use SSR with the other components of the regression sum-of-squares decomposition:

  • SST = Σ(y − ȳ)² measures total response variability without predictors. section 4.2.3
  • SSE = Σ(y − ŷ)² measures the portion not explained by the regression. section 4.2.3
  • SST = SSR + SSE, and R² = SSR / SST; therefore, SSR indicates the explained share of total variability. section 4.2.3

Calculating SSR with Python

After fitting a linear model named lm to predict stage2 from stage1, calculate the explained variability with `SSR = np.sum((lm.predict(x) - np.mean(mds['stage2'])) ** 2)`. The marathon-stage example returns SSR = 28,537.79, while SST = 49,636.95, producing R² ≈ 0.575. This value indicates that the fitted relationship explains about 57.5% of stage2 variance; model significance and predictor usefulness still require evaluation. section 4.2.3

Table 4.2 The sum of squares summary for the fitted linear regression. The stage1 and stage2 columns represent, respectively, the observed values from the two mds variables. SST equals the sum of squares total, or the total variability in the dependent variable without the consideration of any predictors. The yhat column contains the predictions for the response variable from the fitted regression. SSE equals the sum of squares error, or the portion of the SST that can’t be explained by the regression; and SSR equals the sum of squares regression, or the percentage of the variance in the dependent variable explained by the model.
x
stage1
y
stage2
( y − ȳ) 2
SST
y
yhat
( y − ŷ) 2
SSE
( ŷ − ȳ) 2
SSR
152
191
3,654.20
195.78
22.88
3098.73
162
184
4,549.50
208.87
618.36
1813.33
165
193
3,416.40
212.79
391.71
1494.46
163
191
3,654.20
210.18
367.68
1,703.62
166
193
3,416.40
214.10
445.21
1,395.02
187
292
1,644.30
241.57
2,542.75
97.53
175
235
270.60
225.87
83.27
654.10
202
226
647.70
261.20
1,238.96
95.04
179
214
1,402.50
231.11
292.68
413.80
222
274
508.50
287.36
178.62
1,289.87
184
300
2,357.10
237.65
3,887.60
190.46
193
242
89.30
249.42
55.12
4.10
255
279
759.00
330.54
2,656.24
6,255.02
202
288
1,335.90
261.20
718.30
95.04
221
269
308.00
286.06
290.92
1,197.61
207
329
6,014.00
267.74
3,752.75
265.37
227
268
273.90
293.91
671.14
1,802.54
239
315
4,038.60
309.61
29.10
3,382.11
164
201
2,545.20
211.48
109.90
1,597.33
226
345
8,751.60
292.60
2,745.97
1,693.16
49,636.95
21,099.16
28,538.24

Inspect the sum-of-squares table to compare observed responses, fitted predictions, residual errors, SST, SSE, and SSR row by row. section 4.2.3

How Statistics Every Programmer Needs covers it

How deep it goes
Derives SSR mathematically, computes it in Python, relates it to SST and SSE, and stops short of a proof.
Examples
Uses marathon stage times, fitted values, a sum-of-squares table, and NumPy calculations returning SSR, SST, SSE, and R².
What it assumes
Assumes familiarity with linear regression, predicted responses, means, and variance while reinforcing the metric through derivation and code.
What you can do after
Evaluate linear-regression fit by computing SSR, decomposing SST, and interpreting the resulting R².
How it connects
Connects SSR to linear regression, total sum of squares, sum of squares error, R-squared, and model reduction.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.