What Is a Worked Example of R Squared?

Explore What is a worked: mechanics, differences, limitations, and practical checks.

Direct answer

A worked example of R squared (R²) starts with a small dataset, computes the model’s predicted values, then compares two quantities: (1) the variation explained by the model and (2) the total variation in the observed outcomes. R² is the ratio of explained variation to total variation, defined as

R² = 1 − (SSres / SStot)

where SSres is the residual sum of squares and SStot is the total sum of squares around the mean.

Below is a fully numeric example. It does not assume any live market data.

Mechanism or definition

To make the calculation explicit, define a dependent variable y (observed values) and a set of model predictions ŷ for the same time points.

  1. Compute the mean of the observed values: ȳ = average(y).
  2. Compute the total sum of squares (SStot): SStot = Σ(yi − ȳ)²
  3. Compute residuals and the residual sum of squares (SSres): SSres = Σ(yi − ŷi)²
  4. Convert to R²: R² = 1 − SSres / SStot

Interpretation in plain terms: R² increases when the model’s predictions stay close to the observed values (small residuals) relative to how far the observations vary around their mean (large total variation).

Evidence or example

Assume we have 4 observed outcomes y and a simple set of predictions ŷ produced by some model.

Let:

  • y = [2, 0, 4, 6]
  • ŷ = [2, 1, 3, 5]

Assumptions:

  • The predictions ŷ correspond to the same four cases as y.
  • We are using the standard variance-explained definition of R².
  • No costs, execution effects, or future behavior are included; this is purely an arithmetic summary of fit to these four points.

Step 1: Mean of y ȳ = (2 + 0 + 4 + 6) / 4 = 12/4 = 3

Step 2: Total sum of squares (SStot)

  • (2 − 3)² = 1
  • (0 − 3)² = 9
  • (4 − 3)² = 1
  • (6 − 3)² = 9 So SStot = 1 + 9 + 1 + 9 = 20

Step 3: Residuals and SSres Residuals (yi − ŷi):

  • 2 − 2 = 0 → squared: 0
  • 0 − 1 = −1 → squared: 1
  • 4 − 3 = 1 → squared: 1
  • 6 − 5 = 1 → squared: 1 So SSres = 0 + 1 + 1 + 1 = 3

Step 4: Compute R² R² = 1 − SSres / SStot = 1 − 3/20 = 17/20 = 0.85

Result: For this dataset and these predictions, R² = 0.85. That means the residual error is much smaller than the variability of y around its mean.

Limitations and risks

  1. R² is not causation. A high R² can happen even if the model captures patterns without explaining why they occur.
  2. R² depends on the chosen y and on how ŷ is produced. If you change the model form, training data, or preprocessing, R² can change.
  3. Overfitting risk: A model can fit historical points closely (high R² in-sample) yet generalize poorly. Historical relationships do not establish future results.
  4. Dataset sensitivity: If SStot is small (y values cluster near their mean), R² can become unstable or misleading.
  5. Failure mode with out-of-sample data: R² computed on new data can be much lower than in-sample values because residuals typically increase when the relationship changes.

Verification or next question

You can independently verify any R² value by recalculating the three ingredients: ȳ, SStot, and SSres using the same observed y and the same predicted ŷ. If you want to go further, a next useful question is how R² behaves when predictions come from different windows, different scaling, or different model choices—especially when relationships are not stable over time.

Trading foreign exchange and CFDs involves substantial risk. Information on FoxiForex is educational and is not personal financial advice. Sponsored placements are labelled clearly.