What is a residual?

Nov 01, 2018

The residual e is the error vector between the true output vector y and its estimate ˆy:

e=yˆy

Residuals for linear regressions

When ˆy is produced by a linear model, the residual represent the aspects of y that cannot be explained by the columns of the design matrix X :

e=yXˆw

Since ^vy=Xˆw is a vector in the linear space spanned by the columns of X, the residual is a vector outside of this linear space, pointing towards y.

Note: and when the MSE-loss is used, the residual is orthogonal to this linear space.

Let M(X) be the column space of X. The vector ˆy is in this linear subspace while y isn’t. This is illustrated on the picture below.

Residual geometry.

Residuals for OLS

The parameter vector ˆw can be expressed using a closed-form formula in the case of an OLS regression;

^vw=(XX)1Xy

Pluging this formula into the definition of a residual, we get:

e=yX(XX)1XHy

H is the hat-matrix (because it puts a hat on y). Rewriting the equality with y as factor, we get:

e=(InH)y

As mentioned above, for OLS regressions, the residual is a vector orthogonal to the column space of X.