R-Squared Calculator Formula

Understand the math behind the r-squared calculator. Each variable explained with a worked example.

Formulas Used

R² (Coefficient of Determination)

r_squared = ss_reg / ss_total

R (Correlation Coefficient)

r_value = sqrt(ss_reg / ss_total)

Residual Sum of Squares (SSE)

ss_resid = ss_total - ss_reg

Variables

VariableDescriptionDefault
ss_regRegression Sum of Squares (SSR)800
ss_totalTotal Sum of Squares (SST)1000

How It Works

R-Squared (Coefficient of Determination)

R² measures the proportion of variance in the dependent variable that is explained by the regression model.

Formula

R² = SSR / SST = 1 - SSE / SST

where SSR is the regression sum of squares, SST is the total sum of squares, and SSE is the residual sum of squares. R² ranges from 0 (model explains nothing) to 1 (perfect fit).

Worked Example

A regression with SSR = 800 and SST = 1000.

ss_reg = 800ss_total = 1000
  1. 01R² = 800 / 1000 = 0.80
  2. 02The model explains 80% of the variance in y.
  3. 03SSE = 1000 - 800 = 200
  4. 04R = sqrt(0.80) = 0.8944

Ready to run the numbers?

Open R-Squared Calculator