Visualizing the workhorse model for regression analysis.
A linear model can be expressed in the form:
yy=Xbb+ee
Where yy∈RN, X∈RN×K, bb∈RK, and ee∈RN.
Mathematically, the equation yy=Xbb+ee is nothing more than a statement until we define what the problem is. In OLS, we're given yy and X and asked to find b. What criteria defines bb? We say we want to minimize the squared error terms.
Minimizing the squared error terms by select bb can be thought of in two ways.
Selecting bb to minimize i=1∑Nei2=i=1∑N(yi−xxi′bb)2=i=1∑N(yi−y^i)2. We write this problem as:
bargmini=1∑Nei2
Selecting b to minimize ee′ee=(yy−Xbb)′(yy−Xbb)=(yy−y^y^)′(yy−y^y^). We write this as:
bbargminee′ee
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 i=1∑Nei2=i=1∑N(yi−xxi′bb)2 is intuitive and, consequentially, the first way students are taught to think about regression. Consider row i of the N rows that form the yy=Xbb+ee.
By convention X with each row representing and "observation" with each column representing some "feature" of the observation. Each xi has the corresponding scalar outcome yi. We can make a tuple (xxi,yi) and plot it in the space RK+1.
One features case (K=1)
When we only have one feature our points live in R2. This is our standard xy-coordinate space from middle school. After we put on all the dots on our paper defined by (xi,yi), our goal is draw a line that minimizes the sum of squared y-distances from (xi,yi) to the line defined by (xi,xib)=(xi,y^i). Since ei2=(yi−y^i)2 we can think of each ei2 as a collection of squares of which we're trying to minimize the total area.
Two feature case (K=2)
When x∈R2 we now have points that live in R3. Writing down each point as the tuple ([x1i,x2i],yi)=(xxi,yi) should convey the idea that the part x defines the location of the point along the "base" of the graph, i.e. the xy-coordinates, while the y coordinate pins it down to a specific location along the z-axis. Since ei=yi−xxi′bb we see that x′b defines the plane of possible predictions and ei 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, x defines the "base" of the point given by (xi,yi) while y pins the point to an exact location along that final orthogonal ("vertical") axis. We find the b that traces out that best hyperplane (the surface of the hyperplane is given by x′b). 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 ee′ee
What does it mean to minimize ee′ee? Note that minimizing ee′ee is the same as minimizing ee′ee because the square-root operator is a monotonic transformation on ee′ee. A monotonic transformation is any transformation T(⋅) that preserves the order of the set it's acting upon. In our case, if ee1′ee1>ee2′ee2 and T(⋅) is monotonic transformation then T(ee1′ee1)>T(ee2′ee2). Thus,
bbargminee′ee≡bbargminee′ee
Now, ee′ee=∑ei which is the definition of euclidean length. Euclidean length is just an extension of the idea of length in R2 and R3. Therefore we know we're trying to minimize the length of the error vector.
Choosing bb
The following derivation should make it clear that bb multiplies the columns of X to produce a vector of predictions yy^ that is close to the observed outcomes yy.
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 bb that orients the column vectors of X in the way that minimizes the length of the vector ee. Where ee is the vector that connects the prediction vector, y^y^, to the outcome vector, yy.
The first projection matrix is called the prediction maker.
Recall bb=(X′X)−1X′yy. Now:
y^y^=Xbb=X(X′X)−1X′yy=Pyy
Where P=X(X′X)−1X′ is the prediction maker.
We can verify P is projection matrix. PP=[X(X′X)−1X′][X(X′X)−1X′]=X(X′X)−1X′=P. We call it the prediction maker because Pyy generates our vector of predictions.
Learn to recognize P in terms of X.
The second projection matrix is called the residual maker.
ee=yy−y^y^=yy−Pyy=(I−P)yy=Myy
Where M=I−P=I−X(X′X)−1X′ is the residual maker.
We can quickly verify that M is a projection matrix. MM=(I−P)(I−P)=I−2P+P=I−P=M. We call M the residual maker because Myy=ee.
Orthogonality of y^y^ and ee.
We saw that yy^=Pyy and that ee=Myy=(I−P)yy where P and M are projection matrices. It's easy to see that PM=MP=0. 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 yy^⊥ee and that yy=yy^+ee, it becomes clear that yy, yy^, and ee form a right triangle in RN with yy as the hypotenuse.
In conclusion, we can say that bb maps the column vectors of X to a single vector whose tip is directly "below" yy.