Course contentsShow
← Data Science
Lesson 532 of 2,14514. Simple Linear RegressionFree lesson

Calculating R-Squared

Compute R-squared using sum of squares: SSR, SSE, SST, and the formula R² = SSR/SST = 1 - SSE/SST.

Calculating R-Squared

You'll learn: How to compute R² using the sum of squares components (SSR, SSE, SST) and understand what the calculation reveals about your model.

The Three Building Blocks

Remember from earlier lessons that R-squared measures how much variation your model explains. To calculate it, you need three sum of squares values:

  • SST (Total Sum of Squares): The total variation in your dependent variable from its mean
  • SSR (Regression Sum of Squares): The variation explained by your model's predictions
  • SSE (Error Sum of Squares): The unexplained variation (residuals)

These relate as: SST = SSR + SSE

The R² Formula

You can calculate R-squared two equivalent ways:

R² = SSR/SST

Or alternatively:

R² = 1 - SSE/SST

Both give identical results because of the relationship above.

What the Calculation Means

Think of SST as the "total puzzle" of variation. SSR is the pieces your model successfully places (explained variation), and SSE is the leftover pieces (unexplained variation).

When you compute SSR/SST, you're asking: "What fraction of total variation did my model explain?"

When you compute 1 - SSE/SST, you're asking: "What remains after subtracting the fraction of variation left unexplained?"

Example Intuition

If SST = 1000, SSR = 700, and SSE = 300:

  • R² = 700/1000 = 0.70
  • Or: R² = 1 - 300/1000 = 1 - 0.30 = 0.70

Your model explains 70% of the variation.

Key Takeaway: R² is calculated by dividing explained variation (SSR) by total variation (SST), or equivalently, by subtracting the fraction of unexplained variation (SSE/SST) from 1. The result quantifies model fit as a proportion between 0 and 1.