Orthogonal Projection and Least Squares
For real matrices with the standard dot product, project b onto the column space of A. Solve the normal equations to minimise the squared residual length, and apply the method to straight-line regression.
What a learner can do afterwards
- Project a vector onto a subspace and verify the residual is orthogonal to it
- Set up the normal equations for an inconsistent system
- Explain why the least squares solution minimises the residual length
1 · Read
Use real vectors and the standard dot product. The column space of A is the subspace spanned by its columns: all vectors Ax. It need not be a plane. The orthogonal projection p of b is the unique closest vector in this subspace. The residual is r = b - p. Compute it by subtracting components, then check that its dot product with every column is zero. If b belongs to the column space, p = b and r = 0.
For a nonzero direction u, project b onto the line of all multiples of u using p = ((b dot u)/(u dot u))u. Compute the two dot products, divide, then scale u. A negative coefficient points opposite to u. The formula cannot use u = 0. Rescaling u by a nonzero number leaves its line and projection unchanged, though the coefficient may change.
For an m by n matrix A, x has n entries and Ax has m. A^T is the transpose: swap rows and columns. Each entry of A^T r is a column's dot product with r. Thus a least squares fit has A^T(b - Ax) = 0. Rearrange to obtain the normal equations A^T A x = A^T b. Every solution gives Ax equal to the projection, whether or not Ax = b is consistent. To check a candidate, dot its residual with every column.
Build A^T A by taking dot products of pairs of columns. Build A^T b by dotting each column with b. For A with rows (1,0), (1,1), (1,3) and b = (1,2,3), the columns are (1,1,1) and (0,1,3). Their dot products give A^T A = [[3,4],[4,10]], and their dots with b give A^T b = (6,11). The normal equations are 3x1 + 4x2 = 6 and 4x1 + 10x2 = 11.
Write ||v|| for Euclidean length. Its square is the sum of squared components. Let p be the projection and r = b - p. For any Ax, p - Ax lies in the column space and is orthogonal to r. Pythagoras gives ||b - Ax|| squared = ||r|| squared + ||p - Ax|| squared. The last term is nonnegative, so the minimum occurs exactly when Ax = p. Minimising length or squared length gives the same solutions.
The fitted vector p is unique. The coefficients x are unique when A's columns are independent. With dependent columns, different x values can give the same p. For A = [[1,1],[1,1]] and b = (2,6), the normal equations reduce to x1 + x2 = 4. Both x = (0,4) and x = (1,3) give p = (4,4). The residual (-2,2) has zero dot product with both columns.
Fit y = a + ct to observations (ti,yi), with intercept a and slope c. Put row (1,ti) in A and yi in b. Then x = (a,c) and Ax contains predictions. Each residual yi - a - cti is a vertical difference, not the perpendicular distance to the plotted line. Least squares minimises their squared sum; signed residuals can cancel. The line is unique if at least two predictor values differ. If all ti agree, different lines can give the same fitted values.
For n observations, sum means add over all observations. The line's normal equations are n a + (sum ti)c = sum yi and (sum ti)a + (sum ti^2)c = sum(ti yi). Here sum ti^2 means add the squared predictor values. Compute the sums to form the equations. Multiply equations if needed to match the coefficients of a. Subtract to eliminate a, solve for c, then substitute to find a.
For (0,2), (1,3), (2,7), the sums are n = 3, sum t = 3, sum y = 12, sum t^2 = 5 and sum ty = 17. The equations are 3a + 3c = 12 and 3a + 5c = 17. Subtracting gives 2c = 5, so c = 2.5. Substituting in the first equation gives a = 1.5. The fitted line is y = 1.5 + 2.5t.
Solve A^T A x = A^T b to find a closest fit. Its residual is orthogonal to every column. The fitted vector is unique; coefficients need independent columns for uniqueness.
Lesson, practice questions and flashcards written for this dataset.
Readings, additional questions and flashcards written for this dataset. Linked videos are credited to Khan Academy in the source records; their licenses have not been verified.
More to read
Separate the fitted vector from the residual
Use a real matrix A and the standard dot product. The vectors Ax form its column space. A coefficient vector x describes how to combine the columns; Ax is the resulting fitted vector. These are different objects and can have different numbers of entries.
The projection p is the unique fitted vector closest to b. Its residual r = b - p is orthogonal to every column. For any candidate Ax, split its residual as b - Ax = r + (p - Ax). The second term lies in the column space, so the two terms are orthogonal. Pythagoras says their squared lengths add. A candidate different from p adds a positive squared distance to the minimum score.
The normal equations A^T A x = A^T b express this residual orthogonality. They have a solution for every real A and b. Independent columns give one coefficient vector. Dependent columns allow different coefficients to produce the same projection. If an exact fit exists, least squares finds a residual of zero.
Why a fitted line needs varying predictor values
For observations (ti,yi), consider the model y = a + ct. The residual at observation i is yi - a - cti. Ordinary least squares minimises the sum of these squared vertical differences. It does not minimise perpendicular distances from the plotted points to the line.
The model matrix has a column of ones and a column of predictor values. The normal equations are n a + (sum ti)c = sum yi and (sum ti)a + (sum ti^2)c = sum(ti yi). The first equation says the residuals sum to zero. The second says the sum of each predictor times its residual is zero.
If at least two predictor values differ, the two columns are independent. The intercept and slope are then unique. If every predictor equals t0, the two columns are dependent. Only the fitted value a + ct0 is determined: it equals the mean of the observed responses. Many intercept and slope pairs can produce that value. The predicted responses at the observed inputs remain unique even though the fitted line is not.
Explore more
2 · Watch
En anglaisTake it off screen
Where it sits
14 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.