Fit a straight line (intercept and slope) to the three points . What are the hat matrix diagonal entries , do they sum to 2, and what is the residual vector?
Supervised learning, Least squares and the hat matrix
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
A small computation with : leverages, their trace, and residuals.
Key idea
The hat matrix turns into fitted values, . Its diagonal entries are the leverages, and equals the number of parameters.
Steps
- Write the design matrix with a column of ones: . Then , with determinant , so .
- The leverage is , where is row of . For : . For : . For : .
- Check the trace: , the number of parameters. The middle point has the lowest leverage because it sits at the centre of the values.
- Find the coefficients: , so .
- Fitted values are , so the residual vector is .
- Check orthogonality: the sum is , and , so as the normal equations require.
Common mistakes
- Forgetting the column of ones. Without it you fit a line through the origin and would be 1.
- Dividing by the determinant wrongly. Check by confirming that the trace equals 2.
- Believing leverage depends on . It depends only on .
How long your answer should be
Half a page, 5 minutes.
Read this
Previous in Supervised learning: In least-squares linear regression, why is the fitted vector the orthogonal projection of onto the column space of , and what does this say about the residuals?
Next in Supervised learning: How do you derive the log-likelihood, the gradient and the Hessian of binary logistic regression, show that the log-likelihood is concave, and carry out one Newton step from on the data , (one feature, no intercept)?