Concepts

  • Regression calculations will always hand you a fitted line, even when a straight-line model is secretly the wrong choice for the data.
    • Diagnostics are the follow-up check: do the assumptions behind that line and its inference actually hold, and does any individual observation have unusual influence on the result?
    • The end goal is to be able to look at a plot, or a single observation, and name exactly what kind of problem it represents.
  • Residuals are the main diagnostic tool because they stand in for the errors we can never actually observe.
    • The true model is , where is the true, unobservable random error.
    • The residual is — the gap between the data and our fitted line, which we can compute.
    • If the fitted line is close to the true mean line, then , which makes .
    • So as long as the model is reasonable, the residuals are a usable, observable stand-in for the errors we can’t see.
  • A healthy residual plot has a specific, recognizable look.
    • Roughly random scatter centered around , with no systematic curvature and no trend against or the fitted values.
    • Roughly constant vertical spread across the whole plot.
    • A few individually large residuals are normal — the problem sign is a systematic pattern, not occasional size.
  • Each kind of departure from that healthy look points to a specific underlying problem.
    • Curvature (a U or inverted-U shape) suggests the true mean function isn’t actually linear.
    • A funnel shape (spread that grows or shrinks) suggests the error variance isn’t constant.
    • One isolated, large vertical residual suggests a response outlier.
    • Runs or clusters suggest the errors are correlated, if the observations have a natural order.
    • A Q-Q plot that bends away from a straight line suggests the errors aren’t normally distributed.
  • A concrete example of the first problem: fitting a line to data that’s actually quadratic leaves a visible pattern in the residuals.
    • Suppose the truth is , but we only fit (missing the term).
    • The residual then works out to — it still carries a systematic term that the line never captured.
    • That leftover term is exactly why curvature shows up in the residual plot: a pattern in the residuals means the model failed to explain a systematic part of the response, not just random noise.
  • The Q-Q plot checks the normality assumption by comparing the residuals’ shape to what a normal distribution’s shape should look like.
    • Plot the ordered standardized residuals against the order statistics you’d expect from a standard normal distribution.
    • Points sitting close to a straight line are consistent with normality; systematic bending away from the line is evidence against it.
    • The matching works like this: with points total, the -th smallest residual is compared against roughly the quantile of the normal distribution — e.g. with points, the 6th-smallest one is compared against the rd percentile.
    • R’s plot(m) produces four such diagnostic panels automatically: residuals vs. fitted (checks model shape), Q-Q (checks normality), a scale-location plot (checks constant variance, using ), and residuals vs. leverage.
  • The constant-variance diagnostic checks whether the error variance actually stays the same across the data, which is one of the model’s core assumptions.
    • Plot residuals (or, better, standardized residuals — explained below) against fitted or predictor values.
    • The warning sign is a cloud that visibly widens or narrows as the fitted values increase.
    • When that happens, the standard fix is a transformation — a common rule of thumb is to take the square root of both variables, , not just alone.
    • A more general transform, Box–Cox, exists for this same problem but is out of scope here.
  • Leverage asks a different question from a residual: is this observation’s -value itself unusual, regardless of what its -value turned out to be.
    • A residual is about the response — is unusual given its ?
    • Leverage is about the predictor — is itself far from the rest of the ‘s?
    • In simple linear regression, leverage has a closed form: .
    • Reading the formula: is smallest when and grows as moves away from the center, and it depends only on the ‘s — the -values never enter into it.
  • Where that leverage formula actually comes from — every fitted value turns out to be a weighted sum of every observed response, and is just one observation’s own weight in that sum.
    • Start from the fitted value written around the sample mean: .
    • Write both pieces as sums over all observations : and .
    • Substitute both in and combine into one sum: .
    • Define that bracketed quantity as , so .
    • Setting gives the observation’s own weight in determining its own fitted value, — which is why a point with large can pull the fitted line toward itself.
  • The leverages across all observations always add up to exactly in simple linear regression.
    • .
    • So the average leverage is , and the corresponds to the two parameters being fit (intercept and slope).
  • The high-leverage flag is a rule of thumb for deciding when a point’s leverage counts as “unusually large.”
    • Flag observation when its leverage exceeds twice the average: .
    • This is a screening rule, not a theorem — a flagged, high-leverage point can still lie exactly on the fitted trend and cause no real problem.
  • Raw residuals don’t all have the same variance, which is why they need to be standardized before comparing their sizes.
    • The exact variance of a residual is .
    • As (very high leverage), — a high-leverage point’s residual is artificially squeezed toward zero, even if the true errors all have the same constant variance.
    • Dividing out that effect gives the standardized residual: , where .
    • is the residual measured in units of its own estimated standard deviation, which makes residuals at different leverage points directly comparable; flag .
  • Three related but distinct ideas are easy to mix up: outlier, leverage, and influence.
    • A large residual means an unusual -value, given its .
    • High leverage means an unusual -value, regardless of .
    • An influential point is one whose removal would substantially change the fit.
    • A point can have high leverage and still sit right on the trend line (harmless); a point can have a large residual at an entirely ordinary ; a point with both traits at once is the one most capable of being seriously influential.
  • Cook’s distance combines outlyingness and leverage into one number, specifically to catch the dangerous combination of the two.
    • Conceptually, it’s defined by leaving one observation out, refitting the whole model without it, and measuring how far all the fitted values moved as a result: .
    • That’s expensive to compute directly, but it equals a simple shortcut: .
    • Reading the shortcut: gets large from a big standardized residual , a big leverage , or both together.
    • Flag .
    • Using Cook’s distance this way relies on the errors being normal, since that’s what makes the standardized residual inside it a meaningful quantity in the first place.

Practice Problems

  • Problem 1 — leverage (Huber data, YBad, ). Predictor values . Compute each and flag any leverage points against the cutoff.

    • Solution.
      • ,
      • hat values: (sum , confirming the sum-to-2 rule)
      • cutoff
      • only exceeds it () — a clear high-leverage point, matching the slides
  • Problem 2 — standardized residuals and Cook’s distance on the same data. Using the Huber YBad fit, compute the standardized residuals and Cook’s distances, and decide whether point 6 is a bad leverage point.

    • Solution.
      • standardized residuals: — point 6’s is just under the flag on its own
      • Cook’s distances: — is enormous against the cutoff
      • teaching point: the standardized residual alone almost misses point 6, but Cook’s distance (which also weights in ) flags it unmistakably as a bad leverage point
  • Problem 3 — applying the cutoff on a bigger dataset (bonds data, ). The cutoff is . Cases 4, 5, 13, and 35 have leverage values above . What does this tell you, and what would you check next?

    • Solution.
      • these four cases are flagged as leverage points purely from having unusual (coupon rate) values — three are the left-most points and one is the right-most point in the scatterplot
      • leverage alone doesn’t say they’re bad
      • next step: check their standardized residuals (or Cook’s distance) to see whether their -values also break the pattern, before considering removing or refitting around them