R-Squared Calculator

Calculate coefficient of determination.

Actual/measured values

Model predictions

For adjusted R² calculation

Load Example Data

Enter observed and predicted values to calculate R²

Both arrays must have equal length

What Is R-Squared?

R-squared (R²), also called the coefficient of determination, measures how well a regression model explains the variability in the data. It represents the proportion of variance in the outcome variable that's accounted for by the predictors.

Question answered: "How much of the variation in Y is explained by the model?"

Examples:

  • "How well does advertising spending explain sales variation?"
  • "What proportion of exam score differences is explained by study time?"
  • "How much of house price variation is captured by our model?"

Interpreting R²

R² = 0.75 means:

  • 75% of variance in Y is explained by the model
  • 25% remains unexplained (due to other factors, measurement error, randomness)
R²Interpretation
0.90+Excellent fit
0.70-0.90Good fit
0.50-0.70Moderate fit
0.30-0.50Weak fit
<0.30Poor fit

Caution: What counts as "good" depends on the field. Social sciences often have lower R² than physical sciences.

The Formula

R2=1−SSresidualSStotalR^2 = 1 - \frac{SS_{\text{residual}}}{SS_{\text{total}}}

Or equivalently:

R2=SSregressionSStotalR^2 = \frac{SS_{\text{regression}}}{SS_{\text{total}}}

Where:

  • SStotal=∑(yi−yˉ)2SS_{\text{total}} = \sum(y_i - \bar{y})^2 (total variance)
  • SSregression=∑(y^i−yˉ)2SS_{\text{regression}} = \sum(\hat{y}_i - \bar{y})^2 (explained variance)
  • SSresidual=∑(yi−y^i)2SS_{\text{residual}} = \sum(y_i - \hat{y}_i)^2 (unexplained variance)

R² and Correlation

For simple linear regression (one predictor):

R² = r² (squared Pearson correlation)

If r = 0.60, then R² = 0.36

This connection helps interpretation: r measures relationship strength, R² measures variance explained.

Example Calculation

Data: Advertising spend predicts sales

X (Ads)Y (Sales)Ŷ (Predicted)
100200210
200350340
300470470
400600600
500700730

Calculations:

  • ȳ = 464
  • SS_total = (200-464)² + ... + (700-464)² = 170,320
  • SS_residual = (200-210)² + ... + (700-730)² = 1,600
  • R² = 1 - (1,600 / 170,320) = 0.991

Interpretation: 99.1% of sales variation is explained by advertising.

Adjusted R²

Problem with R²: It always increases when adding predictors, even useless ones.

Solution: Adjusted R² penalizes for number of predictors:

Radj2=1−(1−R2)(n−1)n−k−1R^2_{\text{adj}} = 1 - \frac{(1 - R^2)(n - 1)}{n - k - 1}

Where:

  • nn = sample size
  • kk = number of predictors

Key properties:

  • Can be lower than R²
  • Can decrease when adding unhelpful predictors
  • Better for comparing models with different numbers of predictors

Example: R² vs. Adjusted R²

Model 1: 2 predictors, R² = 0.75, n = 50 R²_adj = 1 - [(0.25)(49) / 47] = 0.740

Model 2: 5 predictors, R² = 0.77, n = 50 R²_adj = 1 - [(0.23)(49) / 44] = 0.744

Despite higher R², Model 2's adjusted R² is only slightly better—the extra predictors barely help.

R² in Multiple Regression

With multiple predictors, R² reflects the combined explanatory power:

R² = 0.85 with 4 predictors means:

  • All four together explain 85% of variance
  • Can't directly attribute portions to individual predictors (due to correlations)

For individual predictor importance: Use partial R², semi-partial R², or standardized coefficients.

Partial R²

Measures unique contribution of one predictor:

Partial R²_x₁ = R²_full - R²_without_x₁

If R² = 0.85 with all predictors and R² = 0.72 without X₁: Partial R²_x₁ = 0.85 - 0.72 = 0.13

X₁ uniquely explains 13% of variance beyond other predictors.

Common Misconceptions

"Higher R² is always better"

False. Overfitting inflates R². A complex model might have R² = 0.99 but fail on new data.

"R² = 0.5 means the model is useless"

False. In fields with high inherent variability (psychology, economics), R² = 0.3 can be meaningful.

"R² proves causation"

False. R² measures association, not causation. Confounding variables may explain the relationship.

"Maximize R² when selecting models"

Partially false. Use adjusted R², AIC, or BIC instead. Cross-validation is even better.

When R² Is Low

Possible reasons:

  1. Missing important predictors: Key variables not in the model
  2. Non-linear relationship: Need different model form
  3. High random variation: Inherent unpredictability in the outcome
  4. Measurement error: Imprecise measurements add noise
  5. Wrong level of analysis: Individual vs. aggregate data

Low R² doesn't mean predictors are useless— they may still have significant, meaningful effects.

R² in Different Contexts

Physical Sciences

Often R² > 0.90 expected (controlled conditions, precise measurements).

Biological Sciences

R² = 0.60-0.80 often acceptable (natural variation).

Social Sciences

R² = 0.20-0.50 can be meaningful (human behavior is complex).

Economics/Finance

Varies widely; some phenomena are inherently unpredictable.

R² for Model Comparison

Same predictors, different samples: Compare directly.

Different numbers of predictors: Use adjusted R².

Nested models: Use F-test for statistical comparison:

F=(Rfull2−Rreduced2)/Δdf(1−Rfull2)/dferrorF = \frac{(R^2_{\text{full}} - R^2_{\text{reduced}}) / \Delta df}{(1 - R^2_{\text{full}}) / df_{\text{error}}}

Out-of-Sample R²

In-sample R²: Calculated on training data (can be optimistic).

Out-of-sample R²: Calculated on new data (more realistic).

Cross-validation provides honest estimate of predictive R².

Negative out-of-sample R²: Model predicts worse than simply using the mean.

Alternatives to R²

Mean Squared Error (MSE)

Average squared prediction error. Lower is better.

Not bounded; harder to interpret than R².

Root Mean Squared Error (RMSE)

√MSE. Same units as Y.

More interpretable than MSE.

Mean Absolute Error (MAE)

Average absolute error. More robust to outliers.

AIC / BIC

Information criteria balancing fit and complexity.

For model selection, not interpretation.

Reporting Results

Standard format:

"The model explained 72% of the variance in sales (R² = .72, adjusted R² = .69). This indicates that advertising spend, price, and seasonality together account for substantial variation in sales performance."

With significance:

"The regression model was significant, F(3, 96) = 82.4, p < .001, R² = .72, explaining 72% of variance in the outcome."

Historical Context

The coefficient of determination emerged from Karl Pearson's work on correlation in the late 19th century.

The interpretation as "proportion of variance explained" became standard in regression analysis developed by Ronald Fisher and others in the early 20th century.

The distinction between R² and adjusted R² was formalized later as concerns about overfitting grew with multiple regression and computerized model building.

Related Calculations

Summary

R-squared measures the proportion of variance in the outcome explained by the regression model. Values range from 0 to 1, with higher values indicating better fit. Use adjusted R² when comparing models with different numbers of predictors. What counts as "good" R² depends on the field and research question. Remember that high R² doesn't prove causation or guarantee good predictions on new data. Report both R² and adjusted R² alongside significance tests for complete model evaluation.