Course contentsShow
← Data Science
Lesson 542 of 2,14514. Simple Linear RegressionFree lesson

Computing Fitted Values and Residuals

Calculate fitted values and residuals by hand for small datasets; verify calculations in software.

Computing Fitted Values and Residuals

You'll learn: How to calculate fitted values and residuals by hand for small datasets and verify your work in software.

The Core Idea

Now that you understand what fitted values and residuals are, it's time to actually compute them. Given a simple linear regression model ŷ = β₀ + β₁x, you'll plug in your estimated coefficients and each x value to get the fitted value (ŷ). Then subtract this from the actual value (y) to get the residual (e).

Think of it like checking your work on a prediction: the fitted value is your guess, and the residual tells you how far off you were.

The Step-by-Step Process

By Hand:

  1. Fit your model to get β₀ (intercept) and β₁ (slope)
  2. For each observation i:
    • Compute ŷᵢ = β₀ + β₁xᵢ
    • Compute eᵢ = yᵢ - ŷᵢ

Example: Say your model is ŷ = 2 + 3x, and you have data point (x=4, y=15).

  • Fitted value: ŷ = 2 + 3(4) = 14
  • Residual: e = 15 - 14 = 1

Why Calculate These?

Computing fitted values and residuals helps you:

  • Verify your software output is correct
  • Understand where your model succeeds and fails
  • Check assumptions through residual plots
  • Identify outliers (large residuals)

Quick Check

After computing residuals by hand for all observations, they should sum to approximately zero (a key property!). If they don't, recheck your calculations.

Key Takeaway: Computing fitted values and residuals transforms abstract formulas into concrete numbers you can verify—manually calculating a few points deepens understanding and catches implementation errors.