Concepts

  • We have observed pairs and want one straight line that summarizes how changes with .
    • The population model assumes a true but unknown line plus random noise: .
    • are the true population intercept and slope — we never observe them directly.
    • From the sample, we estimate them with (the hat just means “estimated from data”).
    • The fitted line, our best guess at the true line, is .
    • End goal of least squares: choose so the fitted line has the smallest possible total squared vertical error from the observed points.
  • The starting point is the residual — the vertical miss between a candidate line and the data.
    • For observation , a candidate line predicts .
    • The residual is the gap between what actually happened and what the line predicted: .
    • Adding up the raw residuals is a bad way to measure total error, because a positive miss and a negative miss of the same size would cancel out and hide the fact that the line is bad.
    • Squaring each residual before adding fixes that, since squares are always positive.
    • This gives the sum of squared errors:
    • Everything that follows is machinery for making as small as possible.
  • A few summation facts are needed before the derivation, all of which follow from the definition of a mean.
    • and — a sum is just the mean multiplied by how many terms there are.
    • — deviations from the mean always cancel out exactly, by definition of the mean.
    • — this is the sum of squared deviations of from its own mean, written two equivalent ways (the second is a shortcut for hand computation).
    • — the same idea, but for how and deviate together.
    • and are really just the sample variance and covariance before dividing by . That’s why later reads as “covariance over variance” — the same ratio as , since the in each cancels.
    • Pitfall: , and — you cannot pull a sum apart like that.
  • Derive the estimators by minimizing with calculus: take a partial derivative with respect to each unknown, and set each one to zero.
    • Step 1 finds the condition on .
      • Differentiate: .
      • Set the derivative to , since that’s what makes a point a minimum: .
      • Expand and rearrange: — this is called the first normal equation.
      • Divide every term by and use the mean identities from above: , so .
      • This equation says the fitted line is forced to pass through the point , no matter what the slope turns out to be.
    • Step 2 finds the second condition, this time on .
      • Differentiate with respect to instead: .
      • Set it to and rearrange: — the second normal equation.
    • Step 3 solves the two normal equations together by substitution.
      • Plug (from Step 1) and into the second normal equation.
      • Expanding and collecting the terms on one side gives .
      • The two parentheses are exactly and from the summation facts above, so this reads .
      • Solving for gives .
    • Step 4 plugs the slope back into Step 1’s equation to recover the intercept: .
    • Step 5 assembles the fitted line: .
    • This stationary point really is a minimum (not a maximum or saddle) because is a quadratic bowl in , and as long as the aren’t all identical, , so the bowl opens upward.
  • The two normal equations from Steps 1–2 have a direct restatement in terms of the residuals: and .
    • This is usually phrased as “the least-squares residual vector is orthogonal to the constant column and to .”
    • In plain terms, that just means the leftover residual has nothing left to explain: no overall bias (the constant direction), and no leftover linear relationship with (the direction).
  • Centering around the mean keeps appearing throughout this derivation for a reason.
    • measures how spread out is around .
    • measures how and move together around their means.
    • So reads as “how much moves with , relative to how much itself varies.”
  • The exam workflow for a hand-computed fit is always the same chain of steps.
    • Compute the five raw sums: .
    • Convert to the means .
    • Convert to the centered sums .
    • Compute , then .
    • Write the fitted line, and if a residual is asked for, compute at the requested point.

Practice Problems

  • Problem 1 — hand-compute a fit. Data , with , , , , . Find the fitted line and the residual at .

    • Solution.
      • ,
      • at : , observed , so
  • Problem 2 — derive from scratch, cold. Derive the two normal equations from and solve them for and . Write it the way you would on the exam — the Concepts section above has the fully justified version; this is the fast, exam-pace version of the same argument.

    • Solution.
        • — first normal equation
        • — second normal equation
      • substitute and into the second equation