Projection
Part of Math Camp: An Introduction to Mathematics and Statistics with Applications in Economics.
Main Stam4Econ site | View this section in the book | Author: Fan Wang | DOI: 10.5281/zenodo.24696926
Date: 2026-11-30 | HTML | PDF | QMD
1 Projection
1.1 Normalized orthogonal basis
Basis vectors are a set of vectors that are linearly independent and span the vector space. In \(\mathbb{R}^2\), the standard basis vectors are:
\[ e_1 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}, \quad e_2 = \begin{bmatrix} 0 \\ 1 \end{bmatrix} \]
Multiplying the basis vectors by any scalar will stretch or compress them, and adding them together will create new vectors in the space with contribution from each of the basis directions. The example just given is are two orthogonal basis vectors, meaning they are at right angles to each other, with dot product zero.
Not only that, we have normalized them so the norm of each vector is 1, where norm is computed as the square root of the sum of squares of the elements of the vector. This is the Euclidean norm, also called the 2-norm, for a vector \(v\) in \(\mathbb{R}^n\), its Euclidean norm is defined as:
\[ \|v\|_2 = \sqrt{v_1^2 + v_2^2 + \ldots + v_n^2} \]
So these are orthonormal basis vectors.
These are not the only two orthonormal basis vectors in \(\mathbb{R}^2\). For example, we could have:
\[ b_1 = \begin{bmatrix} \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \end{bmatrix}, \quad b_2 = \begin{bmatrix} -\frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \end{bmatrix} \]
These two vectors are also orthonormal, as they are at right angles to each other and have a norm of 1: their dot product is zero, and their norms are both 1.
1.2 Projecting a vector onto a basis vector
Now consider any vector \(v\) in \(\mathbb{R}^n\). Imagine in \(n=2\), we can draw a line from the “tip” of this vector towards a basis vector, such that this line drawn is perpendicular to the basis vector. The point where this line intersects the basis vector is marks the projection vector of \(v\) onto this basis vector.
Note that this projection vector is a scaled version of the basis vector. Let \(\gamma^v\) be the scaling factor, then we can write the projection of \(v\) onto the basis vector \(e_1\) as:
\[ p^v_{e_1} = \gamma^v_{e_1} e_1 \]
where \(\gamma^v_{e_1}\) is the scaling factor for the projection of \(v\) onto \(e_1\). The residual after projection is the difference between \(v\) and its projection onto \(e_1\), \(v-p^v_{e_1}\). It is orthogonal to the basis vector \(e_1\).
\[ (v - p^v_{e_1}) \cdot e_1 = (v - \gamma^v_{e_1} e_1) \cdot e_1 = 0 \]
Now, working with dot product algebra, which is distributive, and the definition of \(p^v_{e_1}\)
\[\begin{align} (v - \gamma^v_{e_1} e_1) \cdot e_1 &= 0\\ v \cdot e_1 - \gamma^v_{e_1} e_1 \cdot e_1 &= 0\\ \gamma^v e_1 \cdot e_1 &= v \cdot e_1\\ \gamma^v &= \frac{v \cdot e_1}{e_1 \cdot e_1} \end{align}\]
Recognizing that the dot product of a vector with itself is the square of its norm, we can write this as:
\[ \gamma^v = \frac{v \cdot e_1}{\|e_1\|^2} \]
And correspondingly the projection vector itself is:
\[ p^v_{e_1} = \frac{v \cdot e_1}{\|e_1\|^2} e_1 \]
In vector notation we have, given that we can move around and take transpose scalar while preserving value (\(v^T e_1\) is a scalar):
\[\begin{align} p^v_{e_1} &= \frac{v^T e_1 e_1 }{e_1^T e_1} = \frac{e_1 v^T e_1}{e_1^T e_1} = \frac{e_1 e_1^T}{e_1^T e_1}v \end{align}\]
This states that the outer product, scaled by the inner product of the basis vector with itself, projects \(v\) onto \(e_1\). If \(e_1\) is a unit vector, then \(e_1^T e_1=1\) and the denominator can be dropped.
1.3 Projection onto a multidimensional subspace
We just projected a vector onto a single vector. We can project a vector, more generally, onto the subspace spanned by multiple basis vectors. In the case of \(\mathbb{R}^2\), we can project onto either \(e_1\) or \(e_2\), if we project onto the subspace spanned by both, then we get back the original vector, because a line is on the plane spanned by two basis vectors. In the case of \(\mathbb{R}^3\), suppose \(e_1\), \(e_2\) and \(e_3\) are basis vectors that span the space, then projecting \(v \in \mathbb{R^3}\) onto the spaced spanned by \(e_1\) and \(e_2\) will give us a vector on the plane spanned by \(e_1\) and \(e_2\), projecting onto the space spanned by \(e_1\) and \(e_3\) will give us a vector on the plane spanned by \(e_1\) and \(e_3\), and so on. If we project onto the space spanned by all three basis vectors, we get back the original vector again. So projection onto a “subspace” is more interesting when the subspace is of lower dimension than the original space.
Given basis vectors \(b_i\) for \(i=1,2,...,n\) that span a k-dimensional subspace of \(\mathbb{R}^n\). We can project from vector \(v\) to each of the basis, in that case, we have what we had from before. We can also project with respect to the subspace spanned by the basis vectors. Let \(\gamma_i\) be the scaling factor along each dimension, then the projection of \(v\) onto the subspace can be written as:
\[ p^v_{\mathbb{b}} = \sum_{i=1}^{k} \gamma^v_i b_i \]
where \(k \le n\). As before, the difference between \(v\) and its projection onto the subspace is orthogonal to each of the basis vectors:
\[ (v - p^v_{\mathbb{b}}) \cdot b_i = 0 \quad \text{for } i=1,2,...,k \]
\[\begin{align} (v - p^v_{b} ) \cdot b_i &= 0\\ v \cdot b_i - p^v_{b} \cdot b_i &= 0\\ p^v_{b} \cdot b_i &= v \cdot b_i\\ \left(\sum_{i=1}^{k} \gamma^v_i b_i \right) \cdot b_i &= v \cdot b_i\\ \end{align}\]
Suppose m=2, then we have:
\[\begin{align} \gamma^v_1 b_1 \cdot b_1 + \gamma^v_2 b_2 \cdot b_1 &= v \cdot b_1\\ \gamma^v_1 b_1 \cdot b_2 + \gamma^v_2 b_2 \cdot b_2 &= v \cdot b_2\\ \end{align}\]
1.4 Projection onto a multidimensional subspace, matrix representation
Building from prior, note that the dot product of \(b_i \cdot b_j\) are all scalar values. This is a system of linear equations, which we can write in matrix form as:
\[ \begin{bmatrix} b_1 \cdot b_1 & b_2 \cdot b_1 \\ b_1 \cdot b_2 & b_2 \cdot b_2 \end{bmatrix} \begin{bmatrix} \gamma^v_1 \\ \gamma^v_2 \end{bmatrix} = \begin{bmatrix} v \cdot b_1 \\ v \cdot b_2 \end{bmatrix} \]
Instead of writing dot product, we can write this in matrix form as:
\[ \begin{bmatrix} b_1^T b_1 & b_2^T b_1 \\ b_1^T b_2 & b_2^T b_2 \end{bmatrix} \begin{bmatrix} \gamma^v_1 \\ \gamma^v_2 \end{bmatrix} = \begin{bmatrix} v^T b_1 \\ v^T b_2 \end{bmatrix} \]
In general, for \(k \le n\) basis vectors, we have a matrix of the dot products of the basis vectors multiplying the vector of scaling factors equaling the vector of dot products of \(v\) with each of the basis vectors:
\[ \begin{bmatrix} b_1^T b_1 & b_2^T b_1 & \cdots & b_k^T b_1 \\ b_1^T b_2 & b_2^T b_2 & \cdots & b_k^T b_2 \\ \vdots & \vdots & \ddots & \vdots \\ b_1^T b_k & b_2^T b_k & \cdots & b_k^T b_k \end{bmatrix} \begin{bmatrix} \gamma^v_1 \\ \gamma^v_2 \\ \vdots \\ \gamma^v_k \end{bmatrix} = \begin{bmatrix} v^T b_1 \\ v^T b_2 \\ \vdots \\ v^T b_k \end{bmatrix} \]
In the matrix of dot products of the basis vectors, we have what looks like the definition of matrix product, with different cells equaling to different row-column products from two underlying matrices. The first element, is the first row of matrix 1 times the first column of matrix 2, the ith row and jth column is the ith row of matrix 1 times the jth column of matrix 2. Recognizing this, and the fact that the matrix is symmetric, we can write this more compactly. Let \(B\) (n by k) be the matrix whose columns are the basis vectors \(b_i\), we have:
\[ B = \begin{bmatrix} | & | & & | \\ b_1 & b_2 & \cdots & b_k \\ | & | & & | \end{bmatrix} \]
and we can write the system of equations as where the left hand size is k by 1 (k by n times n by k times k by 1) and the right hand size is k by 1 as well (k by n times n by 1):
\[ (B^T B) \gamma^v = B^T v \]
1.5 Projection onto a multidimensional subspace, matrix solution
If the basis vectors are not parallel (independent), then \(B^T B\) is invertible, and we can solve for \(\gamma^v\) (the k by 1 vector) as:
\[\begin{align} (B^T B) \gamma^v &= B^T v\\ (B^T B)^{-1}(B^T B) \gamma^v &= (B^T B)^{-1}B^T v\\ \gamma^v &= (B^T B)^{-1} B^T v \end{align}\]
Correspondingly, the projection vector, from \(v\) projected onto the space spanned by \(B\) is:
\[ p^v_{b} = B \cdot (B^T B)^{-1} B^T v \]
Note that the basis vectors do not have to be orthonormal, they just have to be independent. If they are orthonormal, then \(B^T B = I\) (the main diagonal are euclidean norms of each basis vector, all other components are dot products of different orthogonal basis vectors), the identity matrix, and the equation simplifies to (k by 1 = n by k times k by 1):
\[\begin{align} \gamma^v &= B^T v\\ p^v_{b} &= B (B^T v)\\ \end{align}\]
If \(n=k\), then \(p^v_{b} = v\).
They are not independent if one of the basis vectors can be written as a linear combination of the others. For example, if \(n\ge 3\) we have three basis vectors \(b_1\), \(b_2\) and \(b_3\), and \(b_3 = 2b_1 + 3b_2\), then these three basis vectors are not independent, and \(B^T B\) is not invertible.
1.6 Projection and least square regressions
From a projection point of view, the least square regression projects the a vector \(Y\) that is \(n\) by 1 onto the subspace spanned by \(k\) basis vectors, each of which is a \(n\) by 1 vector, the \(n\) by \(k\) matrix of basis vectors form matrix \(X\).\(n\) is usually the number of observations, and \(k\) the number of right-hand-side variables. Vector \(Y\) of “outcomes” correspond to the “v” vector above, and the matrix \(X\) of observable right-hand-side variables correspond to the matrix \(B\) above. The projection vector \(p^v_b\) above corresponds to the predicted value of the regression.
When we talk about colinearity issues with \(X\), that is the same as saying the basis vectors are not independent and do not span the \(R^k\) subspace.
If \(n=k\), we would have the same number of observables as coefficients of interests, and in that case, we would fit the data perfectly, hence the projection would be the same as the original vector \(Y\).