keepcalculator

06 Numbers and Powers

R-Squared in Regression: Formula and Meaning

Card No. 06·60770 · Updated · Standard formula, shown below

The calculator on this card is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

R-squared (R²) in regression is calculated as 1 − (SSE / SST), or equivalently as SSR / SST when the regression includes an intercept. Enter the observed values and their corresponding fitted values to calculate the proportion of variation in the observed outcome accounted for by the model, along with useful sums of squares.

Formula

The standard coefficient of determination is:

R² = 1 − SSE / SST

  • yᵢ is an observed outcome for case i. Enter all observations in the same order in the observed-values list.
  • ŷᵢ is the corresponding fitted or predicted value from the regression model.
  • SSE is the sum of squared errors: Σ(yᵢ − ŷᵢ)².
  • SST is the total sum of squares: Σ(yᵢ − ȳ)², where ȳ is the mean of the observed outcomes.
  • R² is dimensionless: it has no units.

The calculator accepts matching lists of numeric values. Each value can be in any unit appropriate to the outcome, such as dollars, metres, or degrees, but observed and fitted values must use the same unit. Squared sums then have squared units, which cancel in their ratio. For an ordinary least-squares regression with an intercept, another form is R² = SSR / SST, where SSR = Σ(ŷᵢ − ȳ)². These forms agree under those conditions.

Worked Example

Using the defaults, the observed values are 4, 6, 8, 10, and 12, and the fitted values are 5, 6, 7, 10, and 12. First find the observed mean: ȳ = (4 + 6 + 8 + 10 + 12) / 5 = 8.

  • Residuals, yᵢ − ŷᵢ: −1, 0, 1, 0, 0.
  • SSE = (−1)² + 0² + 1² + 0² + 0² = 2.
  • Deviations from the mean: −4, −2, 0, 2, 4; therefore SST = 16 + 4 + 0 + 4 + 16 = 40.
  • R² = 1 − 2 / 40 = 0.95.

The result means the residual sum of squares is 5% of the total sum of squares for this example. It does not by itself establish that the model is suitable or that its predictions are accurate for new observations.

What R-Squared Measures

R² compares the model’s squared prediction errors with the variation in the observed outcomes around their mean. The baseline in this comparison is a prediction that gives every case the same value, ȳ. If the regression’s errors are smaller than that baseline’s errors, the usual formula produces a positive R². An R² of 1 means every fitted value matches its observed value exactly; an R² of 0 means the model’s SSE equals the baseline SST.

In a standard regression with an intercept fitted by ordinary least squares on the same data, R² is between 0 and 1. In other settings it can be negative. For instance, predictions evaluated on a separate test set can be worse, in squared-error terms, than predicting the training-set mean for every case. A regression without an intercept can also have a negative value under the 1 − SSE/SST definition. State how R² was calculated when comparing results across different methods or datasets.

When to Use It and How to Read It

R² is a compact descriptive measure for regression: it can help summarize how much observed variation the fitted model accounts for in the data used for calculation. It is most informative alongside the outcome’s context, the model’s purpose, and other checks. There is no universal cutoff that makes an R² “good”; what counts as useful depends on the field, data quality, and task.

For example, an R² of 0.95 does not mean that 95% of predictions are correct, that predictions are 95% accurate, or that the model explains 95% of every individual outcome. It describes a ratio of sums of squared deviations, not a percentage of cases. It also does not demonstrate that a predictor causes the outcome. A strong association can arise for reasons that the fitted regression does not identify.

For prediction, examine errors on data not used to fit the model, and consider measures such as root mean squared error or mean absolute error, which express errors in the outcome’s units. For inference, consider the regression assumptions, uncertainty in coefficients, sample design, and whether the variables and model form make sense.

Common Problems and Misinterpretations

  • Pairing values incorrectly: Every fitted value must correspond to the observation in the same position. A reordered list can produce a meaningless result.
  • Using different scales: Observed and fitted outcomes must use identical units and transformations. Do not compare, for example, metres with centimetres without converting one list.
  • Assuming R² always rises for useful reasons: In ordinary least squares with an intercept, adding predictors cannot reduce training-set R², even if the added predictors contribute little meaningful information. Adjusted R² or out-of-sample performance can provide additional context.
  • Confusing fit with causation: R² summarizes fit under a particular calculation. It does not prove that a predictor caused changes in the outcome or rule out omitted variables.
  • Overlooking outliers: Squared errors give large residuals especially strong influence. A small number of unusual observations can materially change R², so inspect plots and residuals where appropriate.
  • Rounding too early: Calculate the sums from full-precision values, then round the final result. The displayed four-decimal result may differ slightly from calculations using rounded intermediate sums.

Related Measures and Comparisons

Adjusted R² modifies R² to account for the number of predictors and the sample size. It can be more useful than raw R² when comparing models fitted to the same outcome and dataset, but it is not a substitute for validation. Different conventions exist for specialized models, so check the software’s definition before comparing values.

Correlation squared equals R² in a simple linear regression with an intercept and one predictor, using the same observations and the usual ordinary least-squares fit. That equivalence does not generally hold for multiple regression, models without an intercept, or arbitrary predictions. Also, R² is not always the square of a correlation in general regression settings.

For models such as logistic regression, where the outcome is categorical and the fitting method differs from ordinary least squares, software may report a “pseudo-R².” These measures have distinct definitions and should not automatically be interpreted as the proportion of variance explained by the linear-regression formula.

Frequently Asked Questions

What is the formula for R-squared?
For the usual definition, R² = 1 − SSE/SST, where SSE is the sum of squared residuals and SST is the sum of squared deviations of observed values from their mean.

Can R-squared be negative?
Yes. It can be negative when the predictions have a larger squared error than the mean-only baseline, including in test data or in some regressions without an intercept.

Does an R-squared of 0.8 mean 80% accuracy?
No. It means the model’s residual sum of squares is 20% of the total sum of squares under the stated definition. It is not the percentage of predictions that are correct.

Is a higher R-squared always better?
No. It describes fit on particular data and can rise when predictors are added, even if they do not improve generalization or make the model more useful. Check model purpose and validation results.

What is the difference between R-squared and adjusted R-squared?
Adjusted R² accounts for the number of predictors and sample size, while ordinary R² does not penalize adding predictors in the standard least-squares setting. Neither alone proves that a model will predict well on new data.

Related

Formula used
list y | Observed values | 4, 6, 8, 10, 12
list f | Fitted values | 5, 6, 7, 10, 12
out r2 | R-squared | - | 1 - sum((y - f)^2) / sum((y - mean(y))^2) | 4
out sse | Residual sum of squares | - | sum((y - f)^2) | 4
out sst | Total sum of squares | - | sum((y - mean(y))^2) | 4

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →