Fit a straight line (intercept and slope) to the three points (x,y)=(0,1),(1,3),(2,2). What are the hat matrix diagonal entries h11,h22,h33, 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 H=X(X⊤X)−1X⊤: leverages, their trace, and residuals.

Key idea

The hat matrix H turns y into fitted values, y^=Hy. Its diagonal entries are the leverages, and tr⁡(H) equals the number of parameters.

Steps

  1. Write the design matrix with a column of ones: X=(101112). Then X⊤X=(3335), with determinant 15−9=6, so (X⊤X)−1=16(5−3−33).
  2. The leverage is hii=xi⊤(X⊤X)−1xi, where xi is row i of X. For x1=(1,0): h11=5/6. For x2=(1,1): (5−3−3+3)/6=1/3. For x3=(1,2): (5−6−6+12)/6=5/6.
  3. Check the trace: 5/6+1/3+5/6=2, the number of parameters. The middle point has the lowest leverage because it sits at the centre of the x values.
  4. Find the coefficients: X⊤y=(6,7)⊤, so β^=16(5⋅6−3⋅7,  −3⋅6+3⋅7)⊤=(1.5,0.5)⊤.
  5. Fitted values are 1.5,2,2.5, so the residual vector is e=(−0.5,1,−0.5).
  6. Check orthogonality: the sum is 0, and ∑ixiei=0+1−1=0, so X⊤e=0 as the normal equations require.

Common mistakes

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 y^=Xβ^ the orthogonal projection of y onto the column space of X, 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 w=0 on the data x=(1,2,−1), y=(1,1,0) (one feature, no intercept)?