Showing posts with label Model Fit. Show all posts
Showing posts with label Model Fit. Show all posts

Wednesday, August 28, 2024

Calculating R-Squared in Regression Analysis

The formula for calculating R-squared is:


R^2 = 1 - (SS_res / SS_tot)


Where:
- `SS_res` (Sum of Squares of Residuals) is the sum of the squared differences between the observed values and the predicted values from the model.
- `SS_tot` (Total Sum of Squares) is the sum of the squared differences between the observed values and their mean.

In formula terms:


SS_res = Σ (y_i - ŷ_i)²



SS_tot = Σ (y_i - ȳ)²


Where:
- `y_i` is an observed value.
- `ŷ_i` is a predicted value from the model.
- `ȳ` is the mean of the observed values.

By substituting these values into the formula, you calculate R-squared, which indicates how well the model explains the variability in the data.

Tuesday, August 27, 2024

Breaking Down RSS, TSS, and ESS for Better Regression Understanding

Understanding TSS, RSS, ESS and R²

Understanding RSS, TSS, ESS & R² in Regression

In regression analysis, we measure how well a model explains variation in data using three core quantities: Total Sum of Squares (TSS), Residual Sum of Squares (RSS), and Explained Sum of Squares (ESS).


🎯 Learning Goal

Understand how total variation in data is decomposed into explained and unexplained parts.

💡 Core Identity: TSS = ESS + RSS

📘 Key Definitions

1️⃣ Total Sum of Squares (TSS)

Definition: Measures total variation in y around its mean.

TSS = Σ (y_i - y_mean)^2
  • y_i → actual values
  • y_mean → mean of y
💡 TSS represents total variability before modeling.

2️⃣ Residual Sum of Squares (RSS)

Definition: Measures unexplained variation (model error).

RSS = Σ (y_i - y_hat_i)^2
  • y_hat_i → predicted values
💡 RSS measures how wrong the model is.

3️⃣ Explained Sum of Squares (ESS)

Definition: Measures variation explained by the model.

ESS = Σ (y_hat_i - y_mean)^2
💡 ESS measures how much the model explains.

🔗 The Fundamental Relationship

TSS = ESS + RSS

The total variability in y is split into:

  • Explained part (ESS)
  • Unexplained part (RSS)
💡 Regression decomposes total variation into explained and residual components.

📊 Visual Interpretation (Conceptual)

Think of It Geometrically

TSS → Distance from actual points to the mean ESS → Distance from predictions to the mean RSS → Distance from actual points to predictions

Graphically:

  • Mean line → baseline model
  • Regression line → improved model
  • Vertical gaps → residuals


📈 Coefficient of Determination (R²)

R^2 = ESS / TSS
R^2 = 1 - (RSS / TSS)

Interpretation

  • R² = 1 → Perfect fit
  • R² = 0 → No improvement over mean
💡 R² measures the proportion of total variance explained by the model.

🧪 Step-by-Step Example Logic

How You Compute in Practice
  1. Compute y_mean
  2. Calculate TSS using actual values
  3. Fit regression → obtain y_hat
  4. Calculate RSS
  5. Compute ESS = TSS − RSS
  6. Compute R²

📌 Final Summary

  • TSS → Total variability
  • ESS → Explained variability
  • RSS → Unexplained variability
💡 A good regression model minimizes RSS and maximizes ESS.

End of Interactive Learning Guide

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts