Note · Quantitative Finance / Econometrics
The Geometry of Ordinary Least Squares
Visualizing the workhorse model for regression analysis.
A linear model can be expressed in the form:
Where , , , and .
Mathematically, the equation is nothing more than a statement until we define what the problem is. In OLS, we’re given and and asked to find . What criteria defines ? We say we want to minimize the squared error terms.
Minimizing the squared error terms by select can be thought of in two ways.
- Selecting to minimize . We write this problem as:
- Selecting to minimize . We write this as:
I’ll refer to the setup (1) as the row way of thinking about the problem and (2) as the column way of thinking about the problem.
The Row Interpretation (Elementary)
Thinking about the problem as minimizing is intuitive and, consequentially, the first way students are taught to think about regression. Consider row of the rows that form the .
By convention with each row representing and “observation” with each column representing some “feature” of the observation. Each has the corresponding scalar outcome . We can make a tuple ) and plot it in the space .
One features case (K=1)
When we only have one feature our points live in . This is our standard xy-coordinate space from middle school. After we put on all the dots on our paper defined by , our goal is draw a line that minimizes the sum of squared y-distances from to the line defined by . Since we can think of each as a collection of squares of which we’re trying to minimize the total area.
Two feature case (K=2)
When we now have points that live in . Writing down each point as the tuple should convey the idea that the part defines the location of the point along the “base” of the graph, i.e. the xy-coordinates, while the coordinate pins it down to a specific location along the z-axis. Since we see that defines the plane of possible predictions and is the vertical distance along the z-axis to the plane. Again, these squared vertical distances define a collection of squares whose aggregate area we want to minimize.
Higher dimensions (K>2)
I wrote out case K=2 in a way that visualizing dimensions that aren’t visualizable should be intuitive. Recapping, defines the “base” of the point given by while pins the point to an exact location along that final orthogonal (“vertical”) axis. We find the that traces out that best hyperplane (the surface of the hyperplane is given by ). In least squares land, the “best” hyperplane is the hyperplane where no other hyperplane could make the area of our collection of squares any smaller.
The Column Interpretation (Advanced)
Minimizing
What does it mean to minimize ? Note that minimizing is the same as minimizing because the square-root operator is a monotonic transformation on . A monotonic transformation is any transformation that preserves the order of the set it’s acting upon. In our case, if and is monotonic transformation then . Thus,
Now, which is the definition of euclidean length. Euclidean length is just an extension of the idea of length in and . Therefore we know we’re trying to minimize the length of the error vector.
Choosing
The following derivation should make it clear that multiplies the columns of to produce a vector of predictions that is close to the observed outcomes .
Recall our original set up:
Which is equivalent to:
Multiplying a vector by a scalar has the action of scaling the vector. Vector addition has the action of putting vectors “tip-to-tail”. Thus, the goal of OLS is to select that orients the column vectors of in the way that minimizes the length of the vector . Where is the vector that connects the prediction vector, , to the outcome vector, .
OLS Projection Matrices
There are a couple famous projection matrices associated with OLS.
The first projection matrix is called the prediction maker.
Recall . Now:
Where is the prediction maker.
We can verify is projection matrix. . We call it the prediction maker because generates our vector of predictions.
Learn to recognize in terms of .
The second projection matrix is called the residual maker.
Where is the residual maker.
We can quickly verify that is a projection matrix. . We call the residual maker because .
Orthogonality of and .
We saw that and that where and are projection matrices. It’s easy to see that . Therefore the projection matrices map to orthogonal subspaces.
Orthogonality is the generalization of perpendicular. One interpretation for perpendular is that the vectors for a right-angle with each other. Noting that and that , it becomes clear that , , and form a right triangle in with as the hypotenuse.
In conclusion, we can say that maps the column vectors of to a single vector whose tip is directly “below” .