Exercise: A residual plot chooses the next question#
Your mean model looks plausible, but the data contain curvature, increasing noise, and an influential extrapolation point. Determine which diagnostic reveals which problem.
See the shared submission guidance and rubric. Run from book/exercises; the setup below supplies data, not completed answers.
# Shared simulator and small utility functions; no live service is called.
source("../R/course.R")
set.seed(112)
x <- runif(120,-2,2)
d <- data.frame(x=x, y=2+1.5*x+1.2*x^2+rnorm(120,0,.3+.6*abs(x)))
d_with_point <- rbind(d, data.frame(x=5,y=-6))
1. Diagnose the ordinary fit#
Fit a straight line to d. Draw residual-versus-fitted and residual-versus-x plots. Describe the conditional-mean pattern separately from the change in spread. State why a high R-squared would not resolve either issue.
# Fit the linear model and label the two diagnostics.
Your explanation and evidence:
2. Fix the mean, then look again#
Fit a quadratic model and repeat the diagnostics. Compare the remaining spread with the known noise generator. Explain which issue the quadratic term addresses and which remains. Do not use improved residual appearance as proof of causal validity.
# Compare linear and quadratic fitted curves and residual patterns.
Your explanation and evidence:
3. Investigate one influential case#
Fit both specifications to d_with_point. Report the new point’s leverage and Cook’s distance and compare coefficients with the original fits. Show the point on the plot. Write a decision memo distinguishing a data error, a valid unusual observation, and evidence of model failure; do not delete it merely to improve results.
# Compare influence and fitted curves with and without the flagged point.
Your explanation and evidence:
What to submit#
A diagnostic panel, a before/after influence table, and a short investigation memo explaining what further information is needed.