Chapter 6: Inner product spaces
6.5Least squares
A linear system with more equations than unknowns usually has no solution, and that is the normal situation with measured data. Suppose the length of a spring is measured under five different loads. Hooke’s law says that the five data points lie on a line , which gives five linear equations in the two unknowns , and small measurement errors make them inconsistent. When no satisfies , the natural substitute is an for which is as close to as possible. As varies, runs over the column space , so this asks for the point of closest to , and Theorem 6.4.33 says that this point is . This section turns the observation into a computation, the normal equations , which find the best without an orthonormal basis of , and applies it to fitting lines and curves to data.
Throughout, is or , has columns , and . The spaces and carry the dot product (Definition 6.1.8), so and . Only Section 6.5.5 and the exercises built on it use other inner products.
6.5.1The least-squares problem
Intuition (Solving as well as possible). As ranges over , the vector
Picture , with a plane through and off the plane (Figure 6.5.1). The nearest point of the plane is the foot of the perpendicular from , which is . It lies in , so it equals for some , and that is the best we can do. So the problem splits into a geometric step, projecting onto , and an algebraic one, solving , a system that is consistent by construction. The normal equations of Section 6.5.2 merge the two steps.
Definition 6.5.1 (Least-squares solution). Let and . A least-squares solution of is a vector such that
For such an , the vector is the residual, and is the least-squares error.
The name comes from the quantity being minimized. In coordinates,
the sum of the squares of the errors in the equations. If has a solution, its least-squares solutions are exactly its solutions: the solutions have error , and by definiteness only they do. The course writes for the problem of finding a least-squares solution.
The intuition above becomes the following proposition, which is Theorem 6.4.33 read for the subspace .
Proposition 6.5.2 (Least squares is projection). Let and .
- (a) is a least-squares solution of if and only if .
- (b)Least-squares solutions exist. If is one, the set of all of them is
. - (c)The least-squares solution is unique if and only if the columns of are linearly independent.
- (d)The least-squares error is .
Uses. Proposition 2.6.18 (The column space is spanned by the columns), Theorem 6.4.20 (Orthonormal bases exist), Theorem 6.4.33 (Best approximation), Corollary 2.6.31 (Fibers are translates of the kernel), Theorem 2.6.11 (Injectivity is decided at ), Corollary 2.6.24 (The columns decide), Definition 6.4.34 (Distance to a subspace)
The column space is a subspace of the finite-dimensional space , so it has an orthonormal basis and is defined (Theorem 6.4.20). Let . By Proposition 2.6.18, every vector of has the form .
(a) Suppose , and let . Since , Theorem 6.4.33 gives
Conversely, suppose is a least-squares solution. Since , there is with , and so
(b) Since , there is with , and it is a least-squares solution by (a). By (a), the least-squares solutions are exactly the solutions of the consistent system , and by Corollary 2.6.31 (applied to ) these form the set .
(c) By (b), the least-squares solution is unique if and only if , that is, if and only if is injective (Theorem 2.6.11). By Corollary 2.6.24, this happens if and only if the columns of are linearly independent.
(d) By (a) and Definition 6.4.34,
By (b), the set of least-squares solutions has the same shape as the solution set of a consistent system (Proposition 3.1.19), and for a good reason: it is the solution set of the consistent system . Note also that the vector is always unique, even when is not.
Example 6.5.3 (Three points and a line). No line passes through the three points , , . Let us find the line that comes closest, in the sense that the sum of the squared vertical gaps between the points and the line is as small as possible. The line passes through all three points exactly when
that is, when for the unknown , where
The first two equations force and , and then the third says , so the system is inconsistent. The th entry of is the vertical gap
The column space is the plane in spanned by and . These are not orthogonal, so we first run Gram–Schmidt (Algorithm 6.4.14):
Solving gives and , and the third equation checks: . The columns of are independent, so by Proposition 6.5.2 the least-squares line is unique: it is .
The residual is
The computation in Example 6.5.3 took a detour. We wanted the coefficients , but we first computed an orthogonal basis of and the vector , and only then solved for . The normal equations go to directly.
6.5.2The normal equations
Intuition (Why the residual is perpendicular). Here is a direct reason, without Theorem 6.4.33, why the best must be the foot of the perpendicular. Take any candidate and its residual . Suppose is not perpendicular to , so that for some ; replacing by a scalar multiple, we may take real and positive. Slide the candidate a little in the direction , to with , which is still in . Its distance to satisfies
by Proposition 6.1.29. For small the term beats , so the new candidate is strictly closer. A candidate whose residual has any component along can be improved by sliding toward that component. So the best candidate, if there is one, has a residual orthogonal to all of , which is the condition of Theorem 6.4.6.
The condition is checked one column at a time, since is spanned by the columns. And “ for every ” is a single matrix equation: is the th entry of . With , the condition is a linear system for . Here “normal” means perpendicular: the equations say that the residual is normal to the column space.
The column-by-column test deserves to be recorded for any matrix.
Uses. Definition 6.3.26 (Conjugate transpose), Proposition 2.4.8 (Four views of the product), Definition 6.1.8 (Dot product), Proposition 6.3.9 (Properties of ), Proposition 2.6.18 (The column space is spanned by the columns)
Let be the columns of . By Definition 6.3.26, row of is , so by Proposition 2.4.8 and Definition 6.1.8 the th entry of is
Hence if and only if for every . By Proposition 6.3.9(c) and Proposition 2.6.18, that holds if and only if
For real this says ; applied to , it is the statement of Example 6.4.23(b), where is the span of the rows. Theorem 6.6.21 extends the lemma to linear maps between arbitrary inner product spaces.
- (i) is a least-squares solution of ;
- (ii), that is, the residual is orthogonal to every column of ;
- (iii).
Proof (by projection).
Uses. Proposition 6.5.2 (Least squares is projection), Theorem 6.4.6 (The projection is characterized by orthogonality), Theorem 6.4.20 (Orthonormal bases exist), Lemma 6.5.4 (The orthogonal complement of a column space)
Techniques. Recognize a projection by its two conditions (Technique 6.4.7)
(i) (ii). By Proposition 6.5.2(a), (i) holds if and only if . Fix an orthonormal basis of (Theorem 6.4.20). By Theorem 6.4.6, is the unique vector with and . The vector lies in in any case, so if and only if .
(ii) (iii). By Lemma 6.5.4, if and only if , that is, .
Finally, least-squares solutions exist by Proposition 6.5.2(b), and by (i) (iii) they are exactly the solutions of the normal equations. □
The second proof does not use projections at all. It makes the sliding argument of the intuition precise, and the move it uses applies to many minimization problems.
Technique 6.5.6 (Perturb a minimizer). Suppose minimizes a real-valued quantity over a vector space. Then for every direction , the function of a real variable has a minimum at . When is the squared norm of a vector that depends linearly (or affinely) on , this function is a quadratic polynomial with , and a minimum at forces the linear coefficient to vanish: if , a small of the opposite sign makes . Doing this for every gives an equation that must satisfy. Choosing cleverly, usually equal to the vector you want to show is zero, turns “” into a statement (Technique 6.1.36). In the other direction, if the linear coefficient vanishes for every , the expansion shows that
This is “the derivative vanishes at a minimum” without derivatives, and with the converse built in. Reach for it when a vector is defined as the minimizer (or maximizer) of something and you need an equation it satisfies. The canonical example is the second proof of Theorem 6.5.5. The same move gives the minimal-norm solution in Section 6.5.7, and in Section 12.3 it shows that a maximizer of over unit vectors is an eigenvector.
Used in 4 places
Theorem 6.5.5, Exercise 6.5.39, Exercise 6.7.6, Exercise 6.7.13.
Proof of Theorem 6.5.5 (by perturbation).
Uses. Proposition 6.1.29 (Expanding a norm), Proposition 6.3.27 (Properties of the conjugate transpose), Definition 6.1.2 (Inner product), Lemma 6.5.4 (The orthogonal complement of a column space), Proposition 6.5.2 (Least squares is projection)
Techniques. Perturb a minimizer (Technique 6.5.6), Show a vector is zero via its norm (Technique 6.1.36)
Let and
so Proposition 6.1.29 gives, for every ,
(iii) (i). If , then (6.5.1) reads
(i) (iii). Suppose is a least-squares solution, and take with real and positive. Then , and (6.5.1) together with minimality gives
after dividing by . If , choose so small that
(ii) (iii) is Lemma 6.5.4 applied to , as in the first proof. The perturbation argument characterizes the least-squares solutions but does not produce one, so existence still comes from Proposition 6.5.2(b); Exercise 6.5.45 gives an algebraic existence proof instead. □
The first proof is the picture of Figure 6.5.1: least squares is projection, and projections are recognized by orthogonality. The second is the calculus approach of “set the gradient to zero”, done without derivatives: is, up to a factor , the gradient of . It does not use Theorem 6.4.33, and it gives a sharper statement. If solves the normal equations, then by (6.5.1) with ,
for every . This is Pythagoras for the right triangle of Figure 6.5.1 with vertices , , , and it says exactly how fast the error grows as moves away from .
Example 6.5.7 (Three points, by the normal equations). Return to Example 6.5.3, with and . The entries of are the dot products of the columns and (Theorem 6.3.29), and lists their dot products with :
The normal equations , give , so and , as before. This time no orthogonal basis was needed: only the inner products of the columns with each other and with .
Exercise 6.5.8. In , let and , and let be the matrix with column .
- (a)Find the least-squares solution of , that is, of , and check that the residual is orthogonal to .
- (b)A student solves instead. Show that the resulting is not a least-squares solution.
Uses. Theorem 6.5.5 (The normal equations), Definition 6.1.8 (Dot product), Definition 6.3.26 (Conjugate transpose)
(a) With one column, the normal equations read . Here , so
and by Theorem 6.5.5. The residual is
using . Its inner product with is
(b) and , so the student gets . Its residual is
When is the solution unique?
Intuition (Same kernel). The coefficient matrix of the normal equations is the Gram matrix of the columns of (Theorem 6.3.29). By Proposition 6.5.2(c) and Theorem 6.5.5, the normal equations have exactly one solution precisely when the columns of are independent. Since is square, we expect it to be invertible exactly when the columns of are independent, and the underlying statement is that and have the same kernel.
One containment is free: if , then . For the other we must get from back to , and can have a large kernel, so we cannot cancel it. Two things rescue us. Multiplying by turns into , so the norm vanishes (Technique 6.1.36). Geometrically, says that is orthogonal to (Lemma 6.5.4), while lies in .
Proposition 6.5.9 (
- (a).
- (b)
. - (c) is invertible if and only if the columns of are linearly independent, that is, if and only if .
Proof (by the norm).
Uses. Proposition 6.3.27 (Properties of the conjugate transpose), Definition 6.1.8 (Dot product), Definition 6.1.2 (Inner product), Theorem 4.2.11 (Rank–nullity), Corollary 3.5.25 (The invertible matrix theorem), Corollary 2.6.24 (The columns decide), Theorem 3.5.12 (First Fundamental Theorem, completed)
Techniques. Show a vector is zero via its norm (Technique 6.1.36), Double containment (Technique 1.3.14)
(a) If , then . Conversely, suppose . By Proposition 6.3.27(b) and (a), , so, identifying matrices with scalars (Definition 6.1.8),
By definiteness, . So .
(b) Both and have columns, so by Theorem 4.2.11 and (a),
(c) The matrix is square, so it is invertible if and only if (Corollary 3.5.25). By (a), that is , which holds if and only if the columns of are linearly independent (Corollary 2.6.24), and if and only if (Theorem 3.5.12). □
Proof (by orthogonality).
Uses. Lemma 6.5.4 (The orthogonal complement of a column space), Proposition 6.3.9 (Properties of ), Theorem 4.2.11 (Rank–nullity), Corollary 3.5.25 (The invertible matrix theorem), Corollary 2.6.24 (The columns decide)
Techniques. Double containment (Technique 1.3.14)
The first proof is the one that generalizes to operators: the same computation shows for a linear map between inner product spaces (Section 6.6). It is also Proposition 6.3.30(b) for the columns of , whose Gram matrix is . The second proof is Theorem 6.5.5 with : the least-squares solutions of are the solutions of
Corollary 6.5.11 (The least-squares solution for independent columns). If the columns of are linearly independent, then for every the system has exactly one least-squares solution,
If moreover , then is invertible and .
Uses. Proposition 6.5.9 (
By Proposition 6.5.9(c), is invertible, so the normal equations have exactly one solution, . By Theorem 6.5.5, the least-squares solutions are exactly the solutions of the normal equations.
If , then is a square matrix with independent columns, so it is invertible (Corollary 2.6.24, Corollary 3.5.25), and so is (Proposition 6.3.27(c)). By Proposition 2.5.17,
The formula is good for theory, but to compute by hand one solves the normal equations by row reduction rather than inverting , as in Example 6.5.7.
Example 6.5.12 (Dependent columns). Let
The second column is twice the first, so and the least-squares solution is not unique. The normal equations are
so they reduce to (the second equation is twice the first). Their solutions are
6.5.3Projection onto a column space
Theorem 6.4.31 computes the matrix of from an orthonormal basis of . The normal equations give a formula from any basis, with no Gram–Schmidt step.
Proposition 6.5.13 (Projection onto a column space). Let have linearly independent columns. Then
That is, the matrix of is .
Proof (by the two conditions).
Uses. Proposition 6.5.9 (
Techniques. Recognize a projection by its two conditions (Technique 6.4.7)
By Proposition 6.5.9(c), is invertible, so is defined. Let and , where . Then , and
so by Lemma 6.5.4. These are the two conditions of Theorem 6.4.6 (for an orthonormal basis of , which exists by Theorem 6.4.20), so . □
Proof (by reduction to an orthonormal basis).
Uses. Theorem 6.4.31 (The matrix of an orthogonal projection), Theorem 6.4.20 (Orthonormal bases exist), Proposition 6.4.29 (The orthogonal projection as a linear map), Theorem 6.3.29 (Orthonormal columns), Proposition 6.3.27 (Properties of the conjugate transpose), Proposition 2.5.17 (Algebra of inverses), Corollary 3.5.25 (The invertible matrix theorem), Corollary 2.6.24 (The columns decide)
Techniques. Test injectivity at (Technique 2.6.12)
The columns of are a basis of , so . By Theorem 6.4.20, has an orthonormal basis, which therefore has vectors . Let have these columns. By Theorem 6.4.31, , and by Theorem 6.3.29. Since fixes every vector of (Proposition 6.4.29(b)), it fixes each column of , so
The square matrix is invertible: if , then , so because the columns of are independent (Corollary 2.6.24), and Corollary 3.5.25 applies. So is invertible too (Proposition 6.3.27(c)). Now
as desired. □
The first proof is Technique 6.4.7, the method Section 6.4 promised for this formula. The second shows how the formula relates to : an arbitrary basis of is for an invertible change-of-basis matrix , and the factor
Some consequences can be read off directly. The matrix satisfies
Example 6.5.14 (A projection matrix from a non-orthogonal basis). The plane
and
the matrix found in Example 6.4.32 from the normal vector .
Uses. Proposition 6.5.13 (Projection onto a column space), Corollary 6.5.11 (The least-squares solution for independent columns), Proposition 6.5.2 (Least squares is projection)
Here is a single nonzero column, so and, by Proposition 6.5.13,
By Corollary 6.5.11,
6.5.4Linear regression
The most common source of inconsistent systems is data. Suppose we have measured two real quantities times, with results
Definition 6.5.16 (Least-squares line). Let
is as small as possible. The numbers
To turn this into a least-squares problem, let , , and in , and let be the matrix with columns and . For , the th entry of is , so the sum in Definition 6.5.16 is . Hence is a least-squares line if and only if is a least-squares solution of , and the residuals of the line are the entries of the residual vector . (The lecture writes the line as , so and . We keep the letter for right-hand sides, and the indices match the interactive figures.)
As in Example 6.2.19, the answer is best expressed through the means
Proposition 6.5.17 (The least-squares line). Let
In particular, the line passes through the point , and its residuals add up to . If all are equal, there are infinitely many least-squares lines.
Proof (by solving the normal equations).
Uses. Theorem 6.5.5 (The normal equations), Theorem 6.3.29 (Orthonormal columns), Technique 6.1.9 (A sum of nonnegative terms), Proposition 6.5.2 (Least squares is projection), Corollary 2.6.24 (The columns decide)
By Theorem 6.3.29, the entries of and are dot products:
So the normal equations are
Dividing the first by gives , that is, . Substituting this into the second, and using , gives
Expanding the squares and products,
and
so the second equation reads . Since the are not all equal, , and (Technique 6.1.9). So the normal equations have exactly one solution, the one in the statement, and by Theorem 6.5.5 it is the unique least-squares solution. The first normal equation, , says that lies on the line. It is also the equation , so the residuals add up to .
If all are equal, then is a multiple of , the columns of are dependent, and by Proposition 6.5.2 the least-squares solutions form a translate of the line . Different vectors give different lines, so there are infinitely many least-squares lines. □
Proof (by centering, which orthogonalizes the columns).
Uses. Corollary 6.4.10 (Projecting with an orthogonal list), Proposition 6.3.13 (Orthogonal lists are independent), Proposition 6.5.2 (Least squares is projection), Theorem 6.5.5 (The normal equations)
Techniques. Recognize a projection by its two conditions (Technique 6.4.7)
First,
By Corollary 6.4.10, with and
with
The second proof explains the shape of the formula. Centering the -data is Gram–Schmidt applied to the columns , and once the columns are orthogonal, the projection splits into two one-dimensional problems: the best constant fit to the data is the mean , and the slope is the coefficient of the shadow of on . In the plane of the data, centering moves the origin to , and is then the slope of the best line through the new origin (Exercise 6.5.20). When the are not all equal, Example 6.2.19 gives
Example 6.5.18 (A spring). A spring hangs from a hook, and its length (in cm) is measured under loads (in newtons):
Hooke’s law predicts , where is the natural length and is the stiffness. Here and , so
Then
and the least-squares line is : a natural length of about cm and a stiffness of about N/cm. In matrix form, the normal equations were
The residuals are , , , , . They add up to , as Proposition 6.5.17 says, and the least-squares error is cm.
Remark 6.5.19 (The calculus derivation). Statistics courses usually find the least-squares line with calculus. The function
and setting both to gives and . These are the normal equations, in form (ii) of Theorem 6.5.5. The second proof of Theorem 6.5.5 is this computation without derivatives, and it shows at the same time that the critical point is a minimum, which the calculus argument has to check separately.
- (a)Show that the line through the origin that best fits data
, with the not all , in the least-squares sense has . - (b)Currents
(in amperes) through a resistor produce voltages (in volts). Ohm’s law says . Estimate .
Uses. Corollary 6.5.11 (The least-squares solution for independent columns), Definition 6.5.1 (Least-squares solution)
(a) The sum is , so we want the least-squares solution of for the matrix with column . Since , this column is independent, and by Corollary 6.5.11
(b) Here
Other models
Nothing in the line-fitting problem was special to lines. What made it a least-squares problem is that the unknown coefficients enter linearly. A model
with fixed functions and unknown coefficients , leads to the system with entries , however nonlinear the are. The most important case is fitting a polynomial of degree at most , where and row of is . For data points this is the square Vandermonde matrix of Definition 3.4.22.
Proposition 6.5.21 (Polynomial fits). Let
- (a)A polynomial
of degree at most minimizes among all such polynomials if and only if is a least-squares solution of . - (b)The minimizing polynomial is unique if and only if at least of the numbers are distinct.
- (c)If are distinct and , the minimizer is the interpolating polynomial of Theorem 3.4.24, and every residual is .
Uses. Definition 1.2.17 (Evaluation), Definition 1.2.13 (Polynomials), Proposition 6.5.2 (Least squares is projection), Lemma 3.4.23 (Too many roots), Corollary 3.4.19 (More unknowns than equations), Theorem 3.4.24 (Polynomial interpolation)
Techniques. Test injectivity at (Technique 2.6.12)
(a) By Definition 1.2.17, the th entry of is
(b) By (a) and Proposition 6.5.2(c), the minimizer is unique if and only if . A vector lies in exactly when the corresponding satisfies for every .
Suppose of the are distinct. If , then has degree at most and vanishes at distinct points, so by Lemma 3.4.23, and .
Suppose instead that the take only distinct values . Rows of with the same are equal, so has the same solutions as the system of equations
(c) By Theorem 3.4.24 there is a polynomial of degree at most with for every . Its residuals are all , so it is a minimizer, and by (b) it is the only one. □
So the polynomial of degree at most closest to the data is unique as soon as there are distinct -values, and it interpolates the data when there are exactly that many points. With more points it does not interpolate in general, and it is usually the better model: the high-degree interpolating polynomial passes through every measurement error as well.
Example 6.5.22 (A thrown ball). A ball is thrown upward, and its height (in meters) is read off a video every half second:
Without air resistance,
There are six distinct , so by Proposition 6.5.21 the solution is unique; row reduction gives
So the ball left the hand at about m with speed about m/s, and , close to the true . The residuals are all smaller than m in absolute value (Figure 6.5.2).
Two further variations use the same machinery. With several explanatory variables, say
6.5.5Normal equations in an inner product space
The only place where the proof of Theorem 6.5.5 used was in writing the inner products of the columns as the entries of . In a general inner product space, the Gram matrix (Definition 6.3.28) takes the place of .
Proposition 6.5.23 (Normal equations for a spanning list). Let be an inner product space, let have Gram matrix , let
where
Uses. Theorem 6.4.20 (Orthonormal bases exist), Theorem 6.4.6 (The projection is characterized by orthogonality), Proposition 6.3.9 (Properties of ), Definition 6.3.28 (Gram matrix), Proposition 6.3.30 (Gram matrices detect independence), Corollary 3.5.25 (The invertible matrix theorem)
Techniques. Recognize a projection by its two conditions (Technique 6.4.7), Gram matrices (Technique 6.3.31)
The subspace is finite-dimensional, so is defined (Theorem 6.4.20). Let
So if and only if .
Since , it equals for some , which then solves . The solution is unique if and only if the square matrix is invertible (Corollary 3.5.25), that is, by Proposition 6.3.30, if and only if is linearly independent. □
For with the dot product and , the columns of , the Gram matrix is (Theorem 6.3.29) and
Example 6.5.24 (The line closest to ). In with
The system , gives and . So the best line is , and its squared error is
The chord through the endpoints of the graph has squared error
For polynomials of higher degree the Gram matrix of is the Hilbert matrix of Exercise 6.3.54. It is invertible, but so close to singular that solving numerically loses most of the accuracy for moderate . That is why Approximating functions projects onto orthogonal polynomials instead.
Aside (Weighted least squares). Sometimes the equations of an inconsistent system deserve different amounts of trust, for instance measurements made with instruments of different precision. Then one minimizes a weighted sum with weights . With
The same works with replaced by any positive definite matrix , since is then an inner product (Proposition 6.1.22). In statistics one takes , where is the standard deviation of the error in the th measurement, so that precise measurements count for more. Exercise 6.5.48 gives a second derivation and a computation.
6.5.6Least squares via QR Beyond 21-242
QR factorization is not covered in lecture (Section 6.4.5).
If is the QR factorization of a matrix with independent columns (Theorem 6.4.38), the normal equations simplify, because .
Proposition 6.5.25 (Least squares via QR). Let have linearly independent columns, and let be its QR factorization. Then the least-squares solution of is the unique solution of the upper triangular system
Uses. Theorem 6.4.38 (QR factorization), Theorem 6.3.29 (Orthonormal columns), Proposition 6.3.27 (Properties of the conjugate transpose), Corollary 3.5.25 (The invertible matrix theorem), Theorem 6.5.5 (The normal equations), Corollary 2.6.24 (The columns decide)
By Theorem 6.4.38, has orthonormal columns, so (Theorem 6.3.29), and by Proposition 6.3.27(b),
The square matrix is invertible: if , then , so by independence of the columns of (Corollary 2.6.24, Corollary 3.5.25). Hence is invertible (Proposition 6.3.27(c)), and holds if and only if . By Theorem 6.5.5, the least-squares solution is the unique solution of . □
The two sides have a meaning. is the coordinate vector of
In exact arithmetic there is no reason to prefer QR to the normal equations. In floating-point arithmetic there is: forming can destroy information that still contains. Let with . Its columns are independent, and
6.5.7The pseudoinverse Beyond 21-242
The pseudoinverse is not covered in lecture; see LADR 6C. Section 9.2 completes the picture with the SVD.
When the columns of are dependent, the least-squares solutions form a translate of the kernel (Example 6.5.12). A natural way to pick one is to take the shortest.
Proposition 6.5.27 (The least-squares solution of minimal norm). Let and , and let .
- (a)Among the least-squares solutions of there is exactly one of smallest norm, . It is the only least-squares solution in , and for every least-squares solution .
- (b)The map , , is linear.
Uses. Proposition 6.5.2 (Least squares is projection), Theorem 6.4.24 (Orthogonal decomposition), Theorem 6.3.3 (Pythagorean theorem), Proposition 6.3.9 (Properties of ), Theorem 6.5.5 (The normal equations)
Techniques. Orthogonal decomposition (Technique 6.2.4), Uniqueness via two candidates (Technique 1.1.8)
(a) Let be a least-squares solution (Proposition 6.5.2(b)). The kernel is a subspace of the finite-dimensional space , so by Theorem 6.4.24 with
with equality if and only if . So is the unique least-squares solution of smallest norm, and . If is any least-squares solution in , then lies in (both are in ) and in (a subspace), so by Proposition 6.3.9(d). Since was arbitrary, for every least-squares solution .
(b) By (a) and Theorem 6.5.5, is the only vector with and . Let have minimal solutions , and let . Then , since is a subspace, and
It is also called the Moore–Penrose inverse. By Proposition 6.5.2(a), . If the columns of are independent, the least-squares solution is unique, so by Corollary 6.5.11; in particular when is invertible. Exercise 6.5.49 shows . LADR defines differently, as the inverse of the restriction of to , composed with ; by Proposition 6.5.27(a) it is the same matrix.
Example 6.5.29 (A pseudoinverse). Let as in Example 6.5.12, and , so that and . For ,
For , , the point of the line of solutions of Example 6.5.12 closest to .
Computing from the definition means solving a least-squares problem for every . The singular value decomposition gives by a formula, and Section 9.2 finishes the story there.
Exercises
Exercise 6.5.30. Find the least-squares solution and the least-squares error of the system
and check that the residual is orthogonal to both columns of the coefficient matrix.
Uses. Theorem 6.5.5 (The normal equations), Proposition 6.5.9 (
Let and . Then
The columns of are independent, so by Theorem 6.5.5 and Proposition 6.5.9 the unique least-squares solution solves , . Subtracting times the second equation from the first gives , so and
Its dot products with the columns are and . The least-squares error is
Exercise 6.5.31. Find the least-squares solution of in , where
and the least-squares error.
Uses. Theorem 6.5.5 (The normal equations), Definition 6.3.26 (Conjugate transpose), Theorem 6.3.29 (Orthonormal columns)
With and ,
and . So (Theorem 6.3.29). Also
Subtracting times the second from the first gives , so , and then
so the residual is
Exercise 6.5.32. A used car of a certain model sells for the following prices (in thousands of dollars) at ages (in years):
Find the least-squares line and its residuals, and use it to predict the price at age . What does it predict at age , and what does that say about extrapolating?
Uses. Proposition 6.5.17 (The least-squares line)
Here and , so and
so by Proposition 6.5.17 and
Exercise 6.5.33. For the data , , , :
- (a)find the least-squares line and its squared error;
- (b)find the least-squares parabola
and its squared error; - (c)explain without computing why the error in (b) can be no larger than the one in (a).
Uses. Proposition 6.5.17 (The least-squares line), Proposition 6.5.21 (Polynomial fits), Theorem 6.5.5 (The normal equations), Proposition 6.5.2 (Least squares is projection), Theorem 6.4.33 (Best approximation)
(a) For the line, and
(b) For the parabola, row of is , and with , , , , , , , the normal equations are
Row reduction gives
(c) Let and be the two design matrices. The columns of are also columns of , so . By Proposition 6.5.2(d) the two errors are and , and the distance from to a larger set is no larger, since Theorem 6.4.33 minimizes over all its points. Concretely, the least-squares line is the parabola with , so the best parabola does at least as well. (Exercise 6.5.39 says exactly when the error drops.)
Uses. Theorem 6.5.5 (The normal equations), Lemma 6.5.4 (The orthogonal complement of a column space)
By Theorem 6.5.5, is a least-squares solution of if and only if
the line through the point of the plane perpendicular to that plane. The columns of are independent, so for each such the vector is the only least-squares solution, and the least-squares error is , which is only for . In terms of data, the least-squares line of
Exercise 6.5.35. Let and . Prove or disprove:
- (a)If is a least-squares solution of and is one of , then is a least-squares solution of .
- (b)If is unitary, then and have the same least-squares solutions.
- (c)If is invertible, then and have the same least-squares solutions.
- (d)If is invertible, then is a least-squares solution of if and only if is a least-squares solution of .
Uses. Theorem 6.5.5 (The normal equations), Definition 6.3.33 (Unitary and orthogonal matrices), Proposition 6.3.27 (Properties of the conjugate transpose), Corollary 6.5.11 (The least-squares solution for independent columns)
Techniques. Finding counterexamples and minimal examples (Technique 1.4.18)
(a) True. By Theorem 6.5.5, and . Adding,
(b) True. Since (Definition 6.3.33) and (Proposition 6.3.27(b)),
So the two problems have the same normal equations, and by Theorem 6.5.5 the same least-squares solutions. (Geometrically, preserves lengths, so
(c) False. Let , , and . By Corollary 6.5.11, the least-squares solution of is
(d) True. As runs over , so does , since is invertible, and . So takes the same values as , and minimizes the first if and only if minimizes the second. With , this is the claim.
Exercise 6.5.36. Let have independent columns. A student computes
and concludes from Proposition 6.5.13 that , so that every vector of lies in and every system is consistent. Find the error. For which is the conclusion correct?
Uses. Proposition 2.5.17 (Algebra of inverses), Proposition 6.5.13 (Projection onto a column space), Corollary 3.5.25 (The invertible matrix theorem)
The step
Conversely, if , then is a square matrix with independent columns, hence invertible (Corollary 3.5.25), and so is . Then the student’s computation is valid, , and indeed .
- (a)Let , and suppose . Show that the residual of a least-squares solution of has entries adding up to , so that the entries of have the same mean as those of .
- (b)Part (a) applies to every polynomial fit. Show by an example that the residuals of the least-squares line through the origin, , need not add up to .
Uses. Theorem 6.5.5 (The normal equations), Exercise 6.5.20
(a) Let . By Theorem 6.5.5, , and , so . Hence
(b) For the data , Exercise 6.5.20 gives
Exercise 6.5.38. Let have independent columns, and let . Without using Proposition 6.5.13, show:
- (a) and ;
- (b), and ;
- (c).
- (d)Compute for the regression matrix with columns and , and check that , , and .
Uses. Proposition 6.3.27 (Properties of the conjugate transpose), Proposition 2.4.28 (Cyclicity of the trace), Proposition 6.5.9 (
Techniques. Cyclicity of trace (Technique 2.4.29)
The matrix is invertible by Proposition 6.5.9(c), and Hermitian, since
(a)
(b)
(c) By Proposition 2.4.28,
(d) Here , with determinant , so
so
Each row adds up to , so ; the rows times give , divided by , so ; and
Uses. Theorem 6.5.5 (The normal equations), Proposition 6.5.2 (Least squares is projection), Proposition 6.1.29 (Expanding a norm), Lemma 6.5.4 (The orthogonal complement of a column space)
Techniques. Perturb a minimizer (Technique 6.5.6)
Let be a least-squares solution of , so and . (By Proposition 6.5.2(a), does not depend on the choice of .) For , the vector has , so its residual is , and
Taking gives .
Suppose . Then ; let . By Proposition 6.1.29,
which is less than . So .
Suppose . By Theorem 6.5.5(ii), is orthogonal to the columns of , and now also to , so to every column of . The vector has residual for , so by Theorem 6.5.5 it is a least-squares solution of , and .
In words: adding a column to the design matrix never makes the fit worse, and it makes it strictly better exactly when the new column is correlated with what the old model leaves unexplained. This is also why the error alone cannot decide between models: a model with more columns always wins.
Exercise 6.5.40. Let
- (a)Show that the residual vector is .
- (b)Show that the squared least-squares error is . So the line accounts for the fraction of the spread of the -values about their mean.
- (c)Compute for the spring data of Example 6.5.18.
Uses. Proposition 6.5.17 (The least-squares line), Proposition 6.1.29 (Expanding a norm), Example 6.2.19 (Correlation is a cosine)
(a) By Proposition 6.5.17, , so
(b) By Proposition 6.1.29 (all vectors are real) and
and the last fraction is . Since the left side is nonnegative, this reproves , with equality exactly when every residual is , that is, when the data lie on a line.
(c) For the spring data,
Exercise 6.5.41. Let
- (a)Show that .
- (b)Show that both lines pass through , and that they are the same line if and only if all data points lie on one line.
- (c)Find both lines for the data
.
Uses. Proposition 6.5.17 (The least-squares line), Example 6.2.19 (Correlation is a cosine), Theorem 6.2.1 (Cauchy–Schwarz inequality)
(a) By Proposition 6.5.17,
(b) By Proposition 6.5.17, and , so both lines pass through . If , then , and the lines are and , which are different. If , then and the second line is
(c) Here , , and . So
Since , (a) gives . So when , , and when the line of on is vertical: either way, the line of on is never steeper than the line of on . Predictions of from are pulled toward the mean , which is where the word “regression” comes from.
Exercise 6.5.42. Let be the least-squares line for data
Uses. Proposition 6.5.2 (Least squares is projection), Proposition 6.4.29 (The orthogonal projection as a linear map), Proposition 2.6.18 (The column space is spanned by the columns)
Techniques. Recognize a projection by its two conditions (Technique 6.4.7)
Let and have columns and . Since and , each pair of columns lies in the span of the other, so (Proposition 2.6.18). The are not all equal, so the new least-squares line is unique, and by Proposition 6.5.2(a) its fitted values are . By linearity of (Proposition 6.4.29(a)), , and
So the new line is with and
Uses. Proposition 6.5.23 (Normal equations for a spanning list), Theorem 6.4.33 (Best approximation), Proposition 6.4.4 (Properties of )
Techniques. Gram matrices (Technique 6.3.31)
Let be the polynomials of degree at most . By Proposition 6.5.23 with the list , the coefficients of
Multiplying by , , and gives ,
Since and (Proposition 6.4.4),
For the best line, drop and the third equation: and give , with squared error
Exercise 6.5.44. Over any field , the equations make sense for and , even though there is no inner product. Prove or disprove:
- (a)For every and , the system has a solution.
- (b)If has independent columns, then is invertible.
- (c)Both statements hold over .
Uses. Theorem 6.5.5 (The normal equations), Proposition 6.5.9 (
Techniques. Finding counterexamples and minimal examples (Technique 1.4.18)
(a) False. Let and . Then and , so the system reads , which has no solution.
(b) False. The same has a single nonzero, hence independent, column, but is not invertible.
(c) True. Over , . The system is the normal equations, which always have a solution by Theorem 6.5.5, and is invertible when the columns are independent by Proposition 6.5.9(c). Both proofs used for , which fails over for (Remark 6.5.10).
Solution (by orthogonal complements).
Uses. Lemma 6.5.4 (The orthogonal complement of a column space), Proposition 6.5.9 (
By Proposition 6.3.27, and . By Lemma 6.5.4, applied to and to , and by Proposition 6.5.9(a),
Subspaces of are finite-dimensional, so Theorem 6.4.26 gives
Hence
Solution (by counting dimensions).
Uses. Proposition 6.5.9 (
Techniques. Dimension counting (Technique 4.2.24)
Exercise 6.5.46. Let have linearly independent rows, and let .
- (a)Show that is invertible.
- (b)Show that
solves and lies in . - (c)Show that is the unique solution of of smallest norm.
- (d)Find the solution of smallest norm of , .
Uses. Proposition 6.5.9 (
(a) Row of , read as a vector, has conjugate equal to column of (Definition 6.3.26). A relation among the conjugated rows gives, after conjugating, the relation among the rows, so the columns of are independent. By Proposition 6.5.9(c) applied to , the matrix is invertible.
(b)
(c) By Proposition 3.1.19, the solutions are the vectors with . Since , Theorem 6.3.3 gives
(d) Here , whose rows are independent, and . So
Check: and , and is orthogonal to , which spans . In the language of Section 6.5.7, , and for with independent rows.
Exercise 6.5.47. Let
where pairs with are omitted (they would have weight ). Deduce that lies between the smallest and the largest of the .
Uses. Proposition 6.5.17 (The least-squares line)
Let with means . Summing over all ordered pairs , including , whose terms are ,
Since and , the right side is
With and , this gives
The weights
- (a)Let , let
, and let . Show that , and deduce from Theorem 6.5.5 that the minimizers of this sum are the solutions of . - (b)Four measurements give
, but the last one was made with an instrument whose errors have twice the standard deviation of the others, so it gets weight . Find the ordinary and the weighted least-squares lines.
Uses. Theorem 6.5.5 (The normal equations), Proposition 6.3.27 (Properties of the conjugate transpose), Aside (Weighted least squares) (Weighted least squares)
(a) The th entry of is , so
(b) Ordinary least squares: and
Weighted, with
Multiplying by , the system is , , with determinant . So
Exercise 6.5.49. Let with pseudoinverse (Definition 6.5.28).
- (a)Show that .
- (b)Deduce the Penrose equations , , , and .
- (c)Find for and check the four equations.
Uses. Proposition 6.5.27 (The least-squares solution of minimal norm), Proposition 6.4.29 (The orthogonal projection as a linear map), Theorem 6.4.31 (The matrix of an orthogonal projection), Proposition 6.5.2 (Least squares is projection)
(a) Let . Then is the least-squares solution of smallest norm of . This system is consistent, so its least-squares solutions are its solutions, (Proposition 6.5.2(b)). By Proposition 6.5.27(a) with ,
(b) By Proposition 6.5.2(a), , which fixes every column of ; so . By Proposition 6.5.27(a), every lies in , which fixes; with (a), . Finally and are matrices of orthogonal projections, which are Hermitian by Theorem 6.4.31.
(c) Here ,
Exercise 6.5.50. Least squares measures vertical distances to the line. Orthogonal regression measures perpendicular distances instead. Let be points, not all equal, with centroid , and write
- (a)Every line is for a unit vector and some . Show that
, and that for fixed , is smallest when passes through . - (b)For a line through with unit direction , show that
. - (c)With , show that
. Deduce that, if , the lines minimizing are exactly the line through with . - (d)Find the best line in this sense for
, and compare it with the two lines of Exercise 6.5.41(c).
Uses. Example 6.4.35 (Distance to a hyperplane), Exercise 6.5.20, Theorem 6.3.22 (Parseval’s identity), Theorem 6.2.1 (Cauchy–Schwarz inequality), Exercise 6.5.41
Techniques. Apply Cauchy–Schwarz to a well-chosen inner product (Technique 6.2.21)
(a) Pick , so and with . Translating by preserves distances, so by Example 6.4.35,
(b) Let be a unit vector orthogonal to , so that is an orthonormal basis of and
(c) We have
By Cauchy–Schwarz (Theorem 6.2.1),
(d) Here , , and (Exercise 6.5.41(c)), so , , and . The best line is , with . Its slope lies between the slope of the regression of on and the slope of the regression of on , as it treats the two coordinates symmetrically. The direction maximizing is the first principal component of the points (Section 16.2).
More practice
The practice bank has 20 exercises on this section’s topics.