In statistics, R-squared (R2) measures the proportion of the variance in the response variable that can be explained by the predictor variable in a regression model.
We use the following formula to calculate R-squared:
R2 = [ (nΣxy – (Σx)(Σy)) / (√nΣx2-(Σx)2 * √nΣy2-(Σy)2) ]2
The following step-by-step example shows how to calculate R-squared by hand for a given regression model.
Step 1: Create a Dataset
First, let’s create a dataset:

Step 2: Calculate Necessary Metrics
Next, let’s calculate each metric that we need to use in the R2 formula:

Step 3: Calculate R-Squared
Lastly, we’ll plug in each metric into the formula for R2:
- R2 = [ (nΣxy – (Σx)(Σy)) / (√nΣx2-(Σx)2 * √nΣy2-(Σy)2) ]2
- R2 = [ (8*(2169) – (72)(223)) / (√8*(818)-(72)2 * √8*(6447)-(223)2) ]2
- R2 = 0.6686
Note: The n in the formula represents the number of observations in the dataset and turns out to be n = 8 observations in this example.
Assuming x is the predictor variable and y is the response variable in this regression model, the R-squared for the model is 0.6686.
This tells us that 66.86% of the variation in the variable y can be explained by variable x.
Additional Resources
Introduction to Simple Linear Regression
Introduction to Multiple Linear Regression
R vs. R-Squared: What’s the Difference?
What is a Good R-squared Value?
jesus christ your formula is disgustingly formatted. unreadable. and you didn’t even get it right
No need to sqrt then square the denominator.
Just square the numerator:
R² = [ n(Σxy) – (Σx)(Σy) ]² /
[ n(Σx²) – (Σx)² ] * [ n(Σy²) – (Σy)² ]
Hi Kat…You’re correct that calculating \( R^2 \) by hand doesn’t involve taking the square root and then squaring back the denominator. Your formula effectively captures \( R^2 \) as follows:
### Formula for \( R^2 \) by Hand
Given:
– \( n \) is the number of data points,
– \( x \) and \( y \) are the individual data points for two variables,
the formula for \( R^2 \) is:
\[
R^2 = \frac{ \left[ n \sum xy – (\sum x)(\sum y) \right]^2 }{ \left[ n \sum x^2 – (\sum x)^2 \right] \cdot \left[ n \sum y^2 – (\sum y)^2 \right] }
\]
### Steps to Calculate \( R^2 \):
1. **Calculate** \( \sum x \), \( \sum y \), \( \sum xy \), \( \sum x^2 \), and \( \sum y^2 \).
2. **Compute** \( n \sum xy – (\sum x)(\sum y) \) for the numerator.
3. **Calculate** \( n \sum x^2 – (\sum x)^2 \) and \( n \sum y^2 – (\sum y)^2 \) for the denominator terms.
4. **Square** the result of the numerator.
5. **Divide** by the product of the denominator terms to get \( R^2 \).
This approach avoids unnecessary steps and simplifies calculating \( R^2 \) manually, especially when working with a small dataset. Let me know if you’d like to see an example calculation!