Multiple Linear Regression
Multiple linear regression generalizes simple linear regression from one predictor to predictors per observation. With observations where each holds the predictor values for observation , the model is
or equivalently with absorbing the intercept and . Stacking all observations into matrix form,
where , is the design matrix whose row is , and is the vector of noise terms.The OLS estimator is the closed-form minimizer of :
The inverse exists when the columns of are linearly independent, which requires at minimum. Geometrically, is the orthogonal projection of onto the column space of . The residual vector is perpendicular to every predictor. The plain never falls when a predictor is added. The adjusted R-squared corrects for this when fits have different numbers of predictors.Multicollinearity is close to singular and the OLS estimator becomes numerically unstable. Small changes in produce large swings in , and individual coefficient standard errors become very large. Individual coefficients can flip sign from one sample to the next while the joint fit remains stable. The standard remedies are dropping correlated predictors, pre-processing with PCA, or moving to ridge regression. Ridge adds to , which stabilizes the inverse.
When predictors are highly correlated,
Intuition
Multiple linear regression is the same idea as simple regression, scaled up. It finds the coefficient vector that makes the linear combination of predictors closest to the response in squared-error sense. The matrix formula is the multidimensional version of the slope formula from simple regression. In it, plays the role of , and plays the role of .
Geometrically, the fitted vector is a linear combination of the predictors. It therefore lies in the column space of . The residual vector is the part of that the predictors cannot explain. The OLS criterion picks the unique in the column space that minimizes the residual length. By elementary geometry, this is the orthogonal projection of onto the column space (10. Projection Theorem). The orthogonality condition is exactly the matrix equation that produces the closed-form solution.
The animation tilts a plane from the flat fit to the least-squares plane over two predictors. Each stick is one residual , the vertical gap to the plane.
\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\newcommand{\pf}[1]{\filldraw[draw=black, fill=black] (#1) circle (2.3pt);}
\newcommand{\ph}[1]{\filldraw[draw=black, thick, fill=white] (#1) circle (2.1pt);}
\newcommand{\rs}[3]{\draw[#1, very thick] (#2) -- (#3);}
\newcommand{\rd}[3]{\draw[#1, very thick, dashed] (#2) -- (#3);}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}]
\draw (6.28,-2.4) -- (6.92,-2.4);
\draw[dashed] (6.28,-1.86) -- (6.92,-1.86) node[right] {\footnotesize OLS minimum};
\node at (6.60,1.25) {SSE};
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.4s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.31,-0.61) -- (2.82,0.81) -- (-1.31,1.32) -- (-2.82,-0.09) -- cycle;
\draw[mid] (1.69,-0.25) -- (-2.44,0.26);
\draw[mid] (0.28,-0.48) -- (1.79,0.93);
\draw[mid] (2.07,0.10) -- (-2.07,0.61);
\draw[mid] (-0.75,-0.35) -- (0.75,1.06);
\draw[mid] (2.44,0.45) -- (-1.69,0.97);
\draw[mid] (-1.79,-0.22) -- (-0.28,1.19);
\draw[->] (1.31,-2.95) -- (3.16,-1.22);
\draw[->] (1.31,-2.95) -- (-4.06,-2.28);
\draw[->] (-3.13,-2.40) -- (-3.13,2.57);
\node at (2.91,-2.11) {$x_1$};
\node at (-1.60,-2.83) {$x_2$};
\node at (-3.13,2.94) {$y$};
\rd{cold}{-0.96,0.73}{-0.96,0.73}\ph{-0.96,0.73}
\rd{cold}{-1.70,0.00}{-1.70,0.47}\ph{-1.70,0.00}
\rd{cold}{-0.84,-0.31}{-0.84,0.23}\ph{-0.84,-0.31}
\rd{cold}{-0.65,-0.00}{-0.65,0.14}\ph{-0.65,-0.00}
\rs{hot}{-1.10,1.26}{-1.10,0.94}\pf{-1.10,1.26}
\rs{hot}{1.61,1.92}{1.61,0.78}\pf{1.61,1.92}
\rs{hot}{1.65,0.93}{1.65,0.60}\pf{1.65,0.93}
\rs{hot}{-0.79,0.62}{-0.79,0.56}\pf{-0.79,0.62}
\rs{hot}{0.99,2.19}{0.99,0.68}\pf{0.99,2.19}
\rs{cold}{-1.90,-0.69}{-1.90,0.33}\pf{-1.90,-0.69}
\rs{cold}{-1.59,-0.81}{-1.59,0.18}\pf{-1.59,-0.81}
\rs{cold}{-1.89,-0.94}{-1.89,0.10}\pf{-1.89,-0.94}
\rs{hot}{0.64,0.99}{0.64,0.30}\pf{0.64,0.99}
\rs{hot}{1.30,0.85}{1.30,0.21}\pf{1.30,0.85}
\rs{cold}{-1.31,-0.45}{-1.31,0.04}\pf{-1.31,-0.45}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,0.80);
\node[anchor=east] at (6.18,0.80) {$12.49$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.83 + 0.00\,x_1 + 0.00\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Start flat at $\hat y = \bar y$. Then $\mathrm{SSE} = \mathrm{SST} = 12.49$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.4s = "true", 2.64s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.31,-0.62) -- (2.82,0.91) -- (-1.31,1.35) -- (-2.82,-0.18) -- cycle;
\draw[mid] (1.69,-0.24) -- (-2.44,0.20);
\draw[mid] (0.28,-0.51) -- (1.79,1.02);
\draw[mid] (2.07,0.14) -- (-2.07,0.58);
\draw[mid] (-0.75,-0.40) -- (0.75,1.13);
\draw[mid] (2.44,0.53) -- (-1.69,0.96);
\draw[mid] (-1.79,-0.29) -- (-0.28,1.24);
\draw[->] (1.31,-2.95) -- (3.16,-1.22);
\draw[->] (1.31,-2.95) -- (-4.06,-2.28);
\draw[->] (-3.13,-2.40) -- (-3.13,2.57);
\node at (2.91,-2.11) {$x_1$};
\node at (-1.60,-2.83) {$x_2$};
\node at (-3.13,2.94) {$y$};
\rd{cold}{-0.96,0.73}{-0.96,0.73}\ph{-0.96,0.73}
\rd{cold}{-1.70,0.00}{-1.70,0.44}\ph{-1.70,0.00}
\rd{cold}{-0.84,-0.31}{-0.84,0.21}\ph{-0.84,-0.31}
\rd{cold}{-0.65,-0.00}{-0.65,0.12}\ph{-0.65,-0.00}
\rs{hot}{-1.10,1.26}{-1.10,0.95}\pf{-1.10,1.26}
\rs{hot}{1.61,1.92}{1.61,0.85}\pf{1.61,1.92}
\rs{hot}{1.65,0.93}{1.65,0.66}\pf{1.65,0.93}
\rs{hot}{-0.79,0.62}{-0.79,0.56}\pf{-0.79,0.62}
\rs{hot}{0.99,2.19}{0.99,0.73}\pf{0.99,2.19}
\rs{cold}{-1.90,-0.69}{-1.90,0.29}\pf{-1.90,-0.69}
\rs{cold}{-1.59,-0.81}{-1.59,0.14}\pf{-1.59,-0.81}
\rs{cold}{-1.89,-0.94}{-1.89,0.05}\pf{-1.89,-0.94}
\rs{hot}{0.64,0.99}{0.64,0.32}\pf{0.64,0.99}
\rs{hot}{1.30,0.85}{1.30,0.24}\pf{1.30,0.85}
\rs{cold}{-1.31,-0.45}{-1.31,-0.01}\pf{-1.31,-0.45}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,0.51);
\node[anchor=east] at (6.18,0.51) {$11.38$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.82 + 0.03\,x_1 - 0.02\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {OLS tilts the plane along $x_1$ and $x_2$. The residuals shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.64s = "true", 2.88s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.31,-0.64) -- (2.82,1.17) -- (-1.31,1.41) -- (-2.82,-0.40) -- cycle;
\draw[mid] (1.69,-0.19) -- (-2.44,0.05);
\draw[mid] (0.28,-0.58) -- (1.79,1.23);
\draw[mid] (2.07,0.26) -- (-2.07,0.50);
\draw[mid] (-0.75,-0.52) -- (0.75,1.29);
\draw[mid] (2.44,0.71) -- (-1.69,0.96);
\draw[mid] (-1.79,-0.46) -- (-0.28,1.35);
\draw[->] (1.31,-2.95) -- (3.16,-1.22);
\draw[->] (1.31,-2.95) -- (-4.06,-2.28);
\draw[->] (-3.13,-2.40) -- (-3.13,2.57);
\node at (2.91,-2.11) {$x_1$};
\node at (-1.60,-2.83) {$x_2$};
\node at (-3.13,2.94) {$y$};
\rd{cold}{-0.96,0.73}{-0.96,0.74}\ph{-0.96,0.73}
\rd{cold}{-1.70,0.00}{-1.70,0.36}\ph{-1.70,0.00}
\rd{cold}{-0.84,-0.31}{-0.84,0.16}\ph{-0.84,-0.31}
\rd{cold}{-0.65,-0.00}{-0.65,0.07}\ph{-0.65,-0.00}
\rd{cold}{-1.31,-0.45}{-1.31,-0.11}\ph{-1.31,-0.45}
\rs{hot}{-1.10,1.26}{-1.10,0.97}\pf{-1.10,1.26}
\rs{hot}{1.61,1.92}{1.61,1.02}\pf{1.61,1.92}
\rs{hot}{1.65,0.93}{1.65,0.82}\pf{1.65,0.93}
\rs{hot}{-0.79,0.62}{-0.79,0.55}\pf{-0.79,0.62}
\rs{hot}{0.99,2.19}{0.99,0.85}\pf{0.99,2.19}
\rs{cold}{-1.90,-0.69}{-1.90,0.18}\pf{-1.90,-0.69}
\rs{cold}{-1.59,-0.81}{-1.59,0.04}\pf{-1.59,-0.81}
\rs{cold}{-1.89,-0.94}{-1.89,-0.09}\pf{-1.89,-0.94}
\rs{hot}{0.64,0.99}{0.64,0.37}\pf{0.64,0.99}
\rs{hot}{1.30,0.85}{1.30,0.33}\pf{1.30,0.85}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-0.15);
\node[anchor=east] at (6.18,-0.15) {$8.79$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.79 + 0.12\,x_1 - 0.08\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {OLS tilts the plane along $x_1$ and $x_2$. The residuals shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.88s = "true", 3.12s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.31,-0.68) -- (2.82,1.52) -- (-1.31,1.50) -- (-2.82,-0.70) -- cycle;
\draw[mid] (1.69,-0.13) -- (-2.44,-0.15);
\draw[mid] (0.28,-0.68) -- (1.79,1.51);
\draw[mid] (2.07,0.42) -- (-2.07,0.40);
\draw[mid] (-0.75,-0.69) -- (0.75,1.51);
\draw[mid] (2.44,0.97) -- (-1.69,0.95);
\draw[mid] (-1.79,-0.69) -- (-0.28,1.50);
\draw[->] (1.31,-2.95) -- (3.16,-1.22);
\draw[->] (1.31,-2.95) -- (-4.06,-2.28);
\draw[->] (-3.13,-2.40) -- (-3.13,2.57);
\node at (2.91,-2.11) {$x_1$};
\node at (-1.60,-2.83) {$x_2$};
\node at (-3.13,2.94) {$y$};
\rd{cold}{-0.96,0.73}{-0.96,0.75}\ph{-0.96,0.73}
\rd{cold}{1.65,0.93}{1.65,1.03}\ph{1.65,0.93}
\rd{cold}{-1.70,0.00}{-1.70,0.26}\ph{-1.70,0.00}
\rd{cold}{-1.90,-0.69}{-1.90,0.04}\ph{-1.90,-0.69}
\rd{cold}{-0.84,-0.31}{-0.84,0.09}\ph{-0.84,-0.31}
\rd{cold}{-0.65,-0.00}{-0.65,0.00}\ph{-0.65,-0.00}
\rd{cold}{-1.31,-0.45}{-1.31,-0.26}\ph{-1.31,-0.45}
\rs{hot}{-1.10,1.26}{-1.10,1.01}\pf{-1.10,1.26}
\rs{hot}{1.61,1.92}{1.61,1.27}\pf{1.61,1.92}
\rs{hot}{-0.79,0.62}{-0.79,0.55}\pf{-0.79,0.62}
\rs{hot}{0.99,2.19}{0.99,1.02}\pf{0.99,2.19}
\rs{cold}{-1.59,-0.81}{-1.59,-0.11}\pf{-1.59,-0.81}
\rs{cold}{-1.89,-0.94}{-1.89,-0.27}\pf{-1.89,-0.94}
\rs{hot}{0.64,0.99}{0.64,0.45}\pf{0.64,0.99}
\rs{hot}{1.30,0.85}{1.30,0.44}\pf{1.30,0.85}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-0.88);
\node[anchor=east] at (6.18,-0.88) {$5.93$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.75 + 0.24\,x_1 - 0.16\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {OLS tilts the plane along $x_1$ and $x_2$. The residuals shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.12s = "true", 3.36s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.31,-0.71) -- (2.82,1.91) -- (-1.31,1.59) -- (-2.82,-1.03) -- cycle;
\draw[mid] (1.69,-0.06) -- (-2.44,-0.37);
\draw[mid] (0.28,-0.79) -- (1.79,1.83);
\draw[mid] (2.07,0.60) -- (-2.07,0.28);
\draw[mid] (-0.75,-0.87) -- (0.75,1.75);
\draw[mid] (2.44,1.25) -- (-1.69,0.94);
\draw[mid] (-1.79,-0.95) -- (-0.28,1.67);
\draw[->] (1.31,-2.95) -- (3.16,-1.22);
\draw[->] (1.31,-2.95) -- (-4.06,-2.28);
\draw[->] (-3.13,-2.40) -- (-3.13,2.57);
\node at (2.91,-2.11) {$x_1$};
\node at (-1.60,-2.83) {$x_2$};
\node at (-3.13,2.94) {$y$};
\rd{cold}{-0.96,0.73}{-0.96,0.77}\ph{-0.96,0.73}
\rd{cold}{1.65,0.93}{1.65,1.27}\ph{1.65,0.93}
\rd{cold}{-1.70,0.00}{-1.70,0.15}\ph{-1.70,0.00}
\rd{cold}{-1.90,-0.69}{-1.90,-0.12}\ph{-1.90,-0.69}
\rd{cold}{-1.59,-0.81}{-1.59,-0.26}\ph{-1.59,-0.81}
\rd{cold}{-0.84,-0.31}{-0.84,0.02}\ph{-0.84,-0.31}
\rd{cold}{-1.89,-0.94}{-1.89,-0.47}\ph{-1.89,-0.94}
\rd{cold}{-1.31,-0.45}{-1.31,-0.42}\ph{-1.31,-0.45}
\rs{hot}{-1.10,1.26}{-1.10,1.05}\pf{-1.10,1.26}
\rs{hot}{1.61,1.92}{1.61,1.53}\pf{1.61,1.92}
\rs{hot}{-0.79,0.62}{-0.79,0.54}\pf{-0.79,0.62}
\rs{hot}{0.99,2.19}{0.99,1.21}\pf{0.99,2.19}
\rs{hot}{0.64,0.99}{0.64,0.53}\pf{0.64,0.99}
\rs{hot}{-0.65,-0.00}{-0.65,-0.07}\pf{-0.65,-0.00}
\rs{hot}{1.30,0.85}{1.30,0.56}\pf{1.30,0.85}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.45);
\node[anchor=east] at (6.18,-1.45) {$3.72$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.71 + 0.36\,x_1 - 0.25\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {OLS tilts the plane along $x_1$ and $x_2$. The residuals shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.36s = "true", 3.6s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.31,-0.74) -- (2.82,2.26) -- (-1.31,1.68) -- (-2.82,-1.33) -- cycle;
\draw[mid] (1.69,0.01) -- (-2.44,-0.58);
\draw[mid] (0.28,-0.89) -- (1.79,2.11);
\draw[mid] (2.07,0.76) -- (-2.07,0.17);
\draw[mid] (-0.75,-1.04) -- (0.75,1.97);
\draw[mid] (2.44,1.51) -- (-1.69,0.93);
\draw[mid] (-1.79,-1.18) -- (-0.28,1.82);
\draw[->] (1.31,-2.95) -- (3.16,-1.22);
\draw[->] (1.31,-2.95) -- (-4.06,-2.28);
\draw[->] (-3.13,-2.40) -- (-3.13,2.57);
\node at (2.91,-2.11) {$x_1$};
\node at (-1.60,-2.83) {$x_2$};
\node at (-3.13,2.94) {$y$};
\rd{cold}{-0.96,0.73}{-0.96,0.78}\ph{-0.96,0.73}
\rd{cold}{1.65,0.93}{1.65,1.48}\ph{1.65,0.93}
\rd{cold}{-1.70,0.00}{-1.70,0.05}\ph{-1.70,0.00}
\rd{cold}{-1.90,-0.69}{-1.90,-0.26}\ph{-1.90,-0.69}
\rd{cold}{-1.59,-0.81}{-1.59,-0.41}\ph{-1.59,-0.81}
\rd{cold}{-0.84,-0.31}{-0.84,-0.05}\ph{-0.84,-0.31}
\rd{cold}{-1.89,-0.94}{-1.89,-0.66}\ph{-1.89,-0.94}
\rs{hot}{-1.10,1.26}{-1.10,1.09}\pf{-1.10,1.26}
\rs{hot}{1.61,1.92}{1.61,1.78}\pf{1.61,1.92}
\rs{hot}{-0.79,0.62}{-0.79,0.54}\pf{-0.79,0.62}
\rs{hot}{0.99,2.19}{0.99,1.38}\pf{0.99,2.19}
\rs{hot}{0.64,0.99}{0.64,0.60}\pf{0.64,0.99}
\rs{hot}{-0.65,-0.00}{-0.65,-0.14}\pf{-0.65,-0.00}
\rs{hot}{1.30,0.85}{1.30,0.68}\pf{1.30,0.85}
\rs{hot}{-1.31,-0.45}{-1.31,-0.56}\pf{-1.31,-0.45}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.75);
\node[anchor=east] at (6.18,-1.75) {$2.52$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.67 + 0.48\,x_1 - 0.33\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {OLS tilts the plane along $x_1$ and $x_2$. The residuals shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.6s = "true", 3.84s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.31,-0.77) -- (2.82,2.52) -- (-1.31,1.74) -- (-2.82,-1.55) -- cycle;
\draw[mid] (1.69,0.05) -- (-2.44,-0.73);
\draw[mid] (0.28,-0.96) -- (1.79,2.32);
\draw[mid] (2.07,0.88) -- (-2.07,0.10);
\draw[mid] (-0.75,-1.16) -- (0.75,2.13);
\draw[mid] (2.44,1.70) -- (-1.69,0.92);
\draw[mid] (-1.79,-1.35) -- (-0.28,1.94);
\draw[->] (1.31,-2.95) -- (3.16,-1.22);
\draw[->] (1.31,-2.95) -- (-4.06,-2.28);
\draw[->] (-3.13,-2.40) -- (-3.13,2.57);
\node at (2.91,-2.11) {$x_1$};
\node at (-1.60,-2.83) {$x_2$};
\node at (-3.13,2.94) {$y$};
\rd{cold}{-0.96,0.73}{-0.96,0.79}\ph{-0.96,0.73}
\rd{cold}{1.61,1.92}{1.61,1.95}\ph{1.61,1.92}
\rd{cold}{1.65,0.93}{1.65,1.64}\ph{1.65,0.93}
\rd{cold}{-1.90,-0.69}{-1.90,-0.37}\ph{-1.90,-0.69}
\rd{cold}{-1.59,-0.81}{-1.59,-0.51}\ph{-1.59,-0.81}
\rd{cold}{-0.84,-0.31}{-0.84,-0.10}\ph{-0.84,-0.31}
\rd{cold}{-1.89,-0.94}{-1.89,-0.79}\ph{-1.89,-0.94}
\rs{hot}{-1.10,1.26}{-1.10,1.11}\pf{-1.10,1.26}
\rs{hot}{-0.79,0.62}{-0.79,0.53}\pf{-0.79,0.62}
\rs{hot}{-1.70,0.00}{-1.70,-0.02}\pf{-1.70,0.00}
\rs{hot}{0.99,2.19}{0.99,1.51}\pf{0.99,2.19}
\rs{hot}{0.64,0.99}{0.64,0.65}\pf{0.64,0.99}
\rs{hot}{-0.65,-0.00}{-0.65,-0.19}\pf{-0.65,-0.00}
\rs{hot}{1.30,0.85}{1.30,0.76}\pf{1.30,0.85}
\rs{hot}{-1.31,-0.45}{-1.31,-0.67}\pf{-1.31,-0.45}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.85);
\node[anchor=east] at (6.18,-1.85) {$2.14$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.64 + 0.57\,x_1 - 0.39\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {OLS tilts the plane along $x_1$ and $x_2$. The residuals shrink.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.84s = "true", 6.44s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.31,-0.78) -- (2.82,2.62) -- (-1.31,1.77) -- (-2.82,-1.63) -- cycle;
\draw[mid] (1.69,0.07) -- (-2.44,-0.78);
\draw[mid] (0.28,-0.99) -- (1.79,2.41);
\draw[mid] (2.07,0.92) -- (-2.07,0.07);
\draw[mid] (-0.75,-1.21) -- (0.75,2.19);
\draw[mid] (2.44,1.77) -- (-1.69,0.92);
\draw[mid] (-1.79,-1.42) -- (-0.28,1.98);
\draw[->] (1.31,-2.95) -- (3.16,-1.22);
\draw[->] (1.31,-2.95) -- (-4.06,-2.28);
\draw[->] (-3.13,-2.40) -- (-3.13,2.57);
\node at (2.91,-2.11) {$x_1$};
\node at (-1.60,-2.83) {$x_2$};
\node at (-3.13,2.94) {$y$};
\rd{cold}{-0.96,0.73}{-0.96,0.79}\ph{-0.96,0.73}
\rd{cold}{1.61,1.92}{1.61,2.02}\ph{1.61,1.92}
\rd{cold}{1.65,0.93}{1.65,1.70}\ph{1.65,0.93}
\rd{cold}{-1.90,-0.69}{-1.90,-0.41}\ph{-1.90,-0.69}
\rd{cold}{-1.59,-0.81}{-1.59,-0.55}\ph{-1.59,-0.81}
\rd{cold}{-0.84,-0.31}{-0.84,-0.12}\ph{-0.84,-0.31}
\rd{cold}{-1.89,-0.94}{-1.89,-0.85}\ph{-1.89,-0.94}
\rs{hot}{-1.10,1.26}{-1.10,1.12}\pf{-1.10,1.26}
\rs{hot}{-0.79,0.62}{-0.79,0.53}\pf{-0.79,0.62}
\rs{hot}{-1.70,0.00}{-1.70,-0.05}\pf{-1.70,0.00}
\rs{hot}{0.99,2.19}{0.99,1.55}\pf{0.99,2.19}
\rs{hot}{0.64,0.99}{0.64,0.67}\pf{0.64,0.99}
\rs{hot}{-0.65,-0.00}{-0.65,-0.21}\pf{-0.65,-0.00}
\rs{hot}{1.30,0.85}{1.30,0.79}\pf{1.30,0.85}
\rs{hot}{-1.31,-0.45}{-1.31,-0.71}\pf{-1.31,-0.45}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {This is the OLS plane. No other plane has an SSE below $2.11$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.44s = "true", 6.69s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.25,-0.79) -- (2.85,2.60) -- (-1.25,1.77) -- (-2.85,-1.61) -- cycle;
\draw[mid] (1.65,0.06) -- (-2.45,-0.76);
\draw[mid] (0.22,-0.99) -- (1.83,2.39);
\draw[mid] (2.05,0.91) -- (-2.05,0.08);
\draw[mid] (-0.80,-1.20) -- (0.80,2.18);
\draw[mid] (2.45,1.75) -- (-1.65,0.93);
\draw[mid] (-1.83,-1.40) -- (-0.22,1.98);
\draw[->] (1.25,-2.96) -- (3.21,-1.25);
\draw[->] (1.25,-2.96) -- (-4.08,-2.25);
\draw[->] (-3.16,-2.37) -- (-3.16,2.60);
\node at (2.90,-2.13) {$x_1$};
\node at (-1.66,-2.81) {$x_2$};
\node at (-3.16,2.97) {$y$};
\rd{cold}{-0.93,0.74}{-0.93,0.80}\ph{-0.93,0.74}
\rd{cold}{1.64,1.90}{1.64,2.01}\ph{1.64,1.90}
\rd{cold}{1.67,0.91}{1.67,1.69}\ph{1.67,0.91}
\rd{cold}{-1.90,-0.67}{-1.90,-0.39}\ph{-1.90,-0.67}
\rd{cold}{-1.60,-0.80}{-1.60,-0.54}\ph{-1.60,-0.80}
\rd{cold}{-0.85,-0.31}{-0.85,-0.11}\ph{-0.85,-0.31}
\rd{cold}{-1.91,-0.92}{-1.91,-0.83}\ph{-1.91,-0.92}
\rs{hot}{-1.06,1.27}{-1.06,1.13}\pf{-1.06,1.27}
\rs{hot}{-0.78,0.62}{-0.78,0.54}\pf{-0.78,0.62}
\rs{hot}{-1.69,0.02}{-1.69,-0.04}\pf{-1.69,0.02}
\rs{hot}{1.01,2.18}{1.01,1.55}\pf{1.01,2.18}
\rs{hot}{0.64,0.98}{0.64,0.67}\pf{0.64,0.98}
\rs{hot}{-0.67,0.01}{-0.67,-0.21}\pf{-0.67,0.01}
\rs{hot}{1.29,0.84}{1.29,0.78}\pf{1.29,0.84}
\rs{hot}{-1.34,-0.44}{-1.34,-0.70}\pf{-1.34,-0.44}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Turn the view: the plane rises along $x_1$ and falls along $x_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.69s = "true", 6.94s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (1.05,-0.80) -- (2.93,2.53) -- (-1.05,1.79) -- (-2.93,-1.54) -- cycle;
\draw[mid] (1.52,0.03) -- (-2.46,-0.71);
\draw[mid] (0.06,-0.99) -- (1.93,2.34);
\draw[mid] (1.99,0.86) -- (-1.99,0.12);
\draw[mid] (-0.94,-1.17) -- (0.94,2.16);
\draw[mid] (2.46,1.70) -- (-1.52,0.96);
\draw[mid] (-1.93,-1.36) -- (-0.06,1.97);
\draw[->] (1.05,-2.97) -- (3.35,-1.33);
\draw[->] (1.05,-2.97) -- (-4.12,-2.15);
\draw[->] (-3.23,-2.30) -- (-3.23,2.68);
\node at (2.87,-2.20) {$x_1$};
\node at (-1.81,-2.77) {$x_2$};
\node at (-3.23,3.05) {$y$};
\rd{cold}{-0.85,0.75}{-0.85,0.81}\ph{-0.85,0.75}
\rd{cold}{1.71,1.86}{1.71,1.97}\ph{1.71,1.86}
\rd{cold}{-1.90,-0.63}{-1.90,-0.35}\ph{-1.90,-0.63}
\rd{cold}{1.71,0.88}{1.71,1.65}\ph{1.71,0.88}
\rd{cold}{-1.63,-0.76}{-1.63,-0.50}\ph{-1.63,-0.76}
\rd{cold}{-0.87,-0.29}{-0.87,-0.09}\ph{-0.87,-0.29}
\rd{cold}{-1.95,-0.87}{-1.95,-0.79}\ph{-1.95,-0.87}
\rs{hot}{-0.94,1.28}{-0.94,1.15}\pf{-0.94,1.28}
\rs{hot}{-1.66,0.05}{-1.66,-0.00}\pf{-1.66,0.05}
\rs{hot}{-0.73,0.64}{-0.73,0.55}\pf{-0.73,0.64}
\rs{hot}{1.07,2.16}{1.07,1.52}\pf{1.07,2.16}
\rs{hot}{0.63,0.97}{0.63,0.66}\pf{0.63,0.97}
\rs{hot}{-0.70,0.02}{-0.70,-0.19}\pf{-0.70,0.02}
\rs{hot}{-1.39,-0.41}{-1.39,-0.67}\pf{-1.39,-0.41}
\rs{hot}{1.25,0.81}{1.25,0.76}\pf{1.25,0.81}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Turn the view: the plane rises along $x_1$ and falls along $x_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 6.94s = "true", 7.19s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (0.76,-0.81) -- (3.02,2.43) -- (-0.76,1.80) -- (-3.02,-1.44) -- cycle;
\draw[mid] (1.33,-0.00) -- (-2.45,-0.63);
\draw[mid] (-0.18,-0.97) -- (2.07,2.27);
\draw[mid] (1.89,0.81) -- (-1.89,0.18);
\draw[mid] (-1.13,-1.13) -- (1.13,2.12);
\draw[mid] (2.45,1.62) -- (-1.33,0.99);
\draw[mid] (-2.07,-1.28) -- (0.18,1.96);
\draw[->] (0.76,-2.99) -- (3.52,-1.46);
\draw[->] (0.76,-2.99) -- (-4.15,-2.02);
\draw[->] (-3.30,-2.19) -- (-3.30,2.79);
\node at (2.79,-2.29) {$x_1$};
\node at (-2.03,-2.69) {$x_2$};
\node at (-3.30,3.17) {$y$};
\rd{cold}{-0.74,0.77}{-0.74,0.83}\ph{-0.74,0.77}
\rd{cold}{-1.88,-0.57}{-1.88,-0.29}\ph{-1.88,-0.57}
\rd{cold}{1.81,1.80}{1.81,1.91}\ph{1.81,1.80}
\rd{cold}{1.76,0.82}{1.76,1.59}\ph{1.76,0.82}
\rd{cold}{-1.66,-0.71}{-1.66,-0.45}\ph{-1.66,-0.71}
\rd{cold}{-0.90,-0.26}{-0.90,-0.06}\ph{-0.90,-0.26}
\rd{cold}{-2.00,-0.81}{-2.00,-0.72}\ph{-2.00,-0.81}
\rs{hot}{-0.76,1.30}{-0.76,1.16}\pf{-0.76,1.30}
\rs{hot}{-1.61,0.10}{-1.61,0.05}\pf{-1.61,0.10}
\rs{hot}{-0.67,0.66}{-0.67,0.57}\pf{-0.67,0.66}
\rs{hot}{1.14,2.12}{1.14,1.48}\pf{1.14,2.12}
\rs{hot}{-0.76,0.05}{-0.76,-0.16}\pf{-0.76,0.05}
\rs{hot}{-1.47,-0.36}{-1.47,-0.62}\pf{-1.47,-0.36}
\rs{hot}{0.60,0.95}{0.60,0.64}\pf{0.60,0.95}
\rs{hot}{1.19,0.78}{1.19,0.72}\pf{1.19,0.78}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Turn the view: the plane rises along $x_1$ and falls along $x_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.19s = "true", 7.44s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (0.40,-0.81) -- (3.09,2.31) -- (-0.40,1.81) -- (-3.09,-1.32) -- cycle;
\draw[mid] (1.07,-0.03) -- (-2.41,-0.54);
\draw[mid] (-0.47,-0.94) -- (2.21,2.19);
\draw[mid] (1.74,0.75) -- (-1.74,0.24);
\draw[mid] (-1.34,-1.07) -- (1.34,2.06);
\draw[mid] (2.41,1.53) -- (-1.07,1.03);
\draw[mid] (-2.21,-1.19) -- (0.47,1.93);
\draw[->] (0.40,-3.00) -- (3.69,-1.61);
\draw[->] (0.40,-3.00) -- (-4.13,-1.87);
\draw[->] (-3.35,-2.06) -- (-3.35,2.93);
\node at (2.67,-2.39) {$x_1$};
\node at (-2.27,-2.60) {$x_2$};
\node at (-3.35,3.31) {$y$};
\rd{cold}{-0.58,0.79}{-0.58,0.85}\ph{-0.58,0.79}
\rd{cold}{-1.84,-0.50}{-1.84,-0.22}\ph{-1.84,-0.50}
\rd{cold}{-1.67,-0.64}{-1.67,-0.38}\ph{-1.67,-0.64}
\rd{cold}{1.90,1.73}{1.90,1.83}\ph{1.90,1.73}
\rd{cold}{-2.03,-0.73}{-2.03,-0.64}\ph{-2.03,-0.73}
\rd{cold}{-0.91,-0.22}{-0.91,-0.03}\ph{-0.91,-0.22}
\rs{hot}{-0.54,1.32}{-0.54,1.18}\pf{-0.54,1.32}
\rs{hot}{-1.52,0.16}{-1.52,0.10}\pf{-1.52,0.16}
\rs{hot}{-0.58,0.68}{-0.58,0.59}\pf{-0.58,0.68}
\rs{cold}{1.79,0.75}{1.79,1.52}\pf{1.79,0.75}
\rs{hot}{1.22,2.08}{1.22,1.43}\pf{1.22,2.08}
\rs{hot}{-1.54,-0.29}{-1.54,-0.56}\pf{-1.54,-0.29}
\rs{hot}{-0.81,0.09}{-0.81,-0.13}\pf{-0.81,0.09}
\rs{hot}{0.56,0.93}{0.56,0.62}\pf{0.56,0.93}
\rs{hot}{1.11,0.74}{1.11,0.69}\pf{1.11,0.74}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Turn the view: the plane rises along $x_1$ and falls along $x_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.44s = "true", 7.69s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.00,-0.80) -- (3.11,2.19) -- (0.00,1.80) -- (-3.11,-1.19) -- cycle;
\draw[mid] (0.78,-0.05) -- (-2.33,-0.45);
\draw[mid] (-0.78,-0.90) -- (2.33,2.09);
\draw[mid] (1.56,0.70) -- (-1.56,0.30);
\draw[mid] (-1.56,-1.00) -- (1.56,1.99);
\draw[mid] (2.33,1.44) -- (-0.78,1.05);
\draw[mid] (-2.33,-1.10) -- (0.78,1.89);
\draw[->] (-0.00,-2.99) -- (3.81,-1.78);
\draw[->] (-0.00,-2.99) -- (-4.04,-1.71);
\draw[->] (-3.34,-1.93) -- (-3.34,3.08);
\node at (2.49,-2.50) {$x_1$};
\node at (-2.49,-2.50) {$x_2$};
\node at (-3.34,3.45) {$y$};
\rd{cold}{-0.40,0.80}{-0.40,0.86}\ph{-0.40,0.80}
\rd{cold}{-1.76,-0.44}{-1.76,-0.15}\ph{-1.76,-0.44}
\rd{cold}{-1.66,-0.58}{-1.66,-0.32}\ph{-1.66,-0.58}
\rd{cold}{-2.03,-0.65}{-2.03,-0.56}\ph{-2.03,-0.65}
\rd{cold}{-0.92,-0.18}{-0.92,0.01}\ph{-0.92,-0.18}
\rd{cold}{1.98,1.65}{1.98,1.75}\ph{1.98,1.65}
\rs{hot}{-0.28,1.32}{-0.28,1.18}\pf{-0.28,1.32}
\rs{hot}{-1.40,0.21}{-1.40,0.16}\pf{-1.40,0.21}
\rs{hot}{-0.47,0.69}{-0.47,0.61}\pf{-0.47,0.69}
\rs{hot}{1.29,2.02}{1.29,1.38}\pf{1.29,2.02}
\rs{hot}{-1.59,-0.23}{-1.59,-0.49}\pf{-1.59,-0.23}
\rs{cold}{1.80,0.68}{1.80,1.45}\pf{1.80,0.68}
\rs{hot}{-0.86,0.12}{-0.86,-0.09}\pf{-0.86,0.12}
\rs{hot}{0.51,0.92}{0.51,0.60}\pf{0.51,0.92}
\rs{hot}{1.00,0.71}{1.00,0.65}\pf{1.00,0.71}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Turn the view: the plane rises along $x_1$ and falls along $x_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.69s = "true", 7.94s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.40,-0.77) -- (3.09,2.07) -- (0.40,1.77) -- (-3.09,-1.07) -- cycle;
\draw[mid] (0.47,-0.06) -- (-2.21,-0.36);
\draw[mid] (-1.07,-0.84) -- (2.41,2.00);
\draw[mid] (1.34,0.65) -- (-1.34,0.35);
\draw[mid] (-1.74,-0.92) -- (1.74,1.92);
\draw[mid] (2.21,1.36) -- (-0.47,1.06);
\draw[mid] (-2.41,-1.00) -- (1.07,1.84);
\draw[->] (-0.40,-2.96) -- (3.87,-1.94);
\draw[->] (-0.40,-2.96) -- (-3.89,-1.56);
\draw[->] (-3.29,-1.80) -- (-3.29,3.22);
\node at (2.27,-2.59) {$x_1$};
\node at (-2.67,-2.39) {$x_2$};
\node at (-3.29,3.59) {$y$};
\rd{cold}{-0.22,0.81}{-0.22,0.87}\ph{-0.22,0.81}
\rd{cold}{-1.65,-0.37}{-1.65,-0.09}\ph{-1.65,-0.37}
\rd{cold}{-1.62,-0.51}{-1.62,-0.25}\ph{-1.62,-0.51}
\rd{cold}{-2.00,-0.57}{-2.00,-0.48}\ph{-2.00,-0.57}
\rd{cold}{-0.91,-0.15}{-0.91,0.05}\ph{-0.91,-0.15}
\rd{cold}{2.02,1.57}{2.02,1.68}\ph{2.02,1.57}
\rs{hot}{-0.02,1.31}{-0.02,1.18}\pf{-0.02,1.31}
\rs{hot}{-1.26,0.26}{-1.26,0.20}\pf{-1.26,0.26}
\rs{hot}{-0.35,0.70}{-0.35,0.62}\pf{-0.35,0.70}
\rs{hot}{-1.61,-0.16}{-1.61,-0.42}\pf{-1.61,-0.16}
\rs{hot}{-0.89,0.16}{-0.89,-0.05}\pf{-0.89,0.16}
\rs{hot}{1.34,1.97}{1.34,1.33}\pf{1.34,1.97}
\rs{cold}{1.77,0.61}{1.77,1.39}\pf{1.77,0.61}
\rs{hot}{0.45,0.90}{0.45,0.59}\pf{0.45,0.90}
\rs{hot}{0.87,0.68}{0.87,0.62}\pf{0.87,0.68}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Turn the view: the plane rises along $x_1$ and falls along $x_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 7.94s = "true", 8.19s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.76,-0.73) -- (3.02,1.97) -- (0.76,1.73) -- (-3.02,-0.97) -- cycle;
\draw[mid] (0.18,-0.05) -- (-2.07,-0.29);
\draw[mid] (-1.33,-0.79) -- (2.45,1.91);
\draw[mid] (1.13,0.62) -- (-1.13,0.38);
\draw[mid] (-1.89,-0.85) -- (1.89,1.85);
\draw[mid] (2.07,1.30) -- (-0.18,1.05);
\draw[mid] (-2.45,-0.91) -- (1.33,1.79);
\draw[->] (-0.76,-2.93) -- (3.87,-2.09);
\draw[->] (-0.76,-2.93) -- (-3.69,-1.44);
\draw[->] (-3.19,-1.70) -- (-3.19,3.34);
\node at (2.03,-2.65) {$x_1$};
\node at (-2.79,-2.28) {$x_2$};
\node at (-3.19,3.71) {$y$};
\rd{cold}{-1.52,-0.33}{-1.52,-0.04}\ph{-1.52,-0.33}
\rd{cold}{-0.05,0.80}{-0.05,0.86}\ph{-0.05,0.80}
\rd{cold}{-1.94,-0.50}{-1.94,-0.41}\ph{-1.94,-0.50}
\rd{cold}{-1.55,-0.46}{-1.55,-0.20}\ph{-1.55,-0.46}
\rd{cold}{-0.88,-0.12}{-0.88,0.08}\ph{-0.88,-0.12}
\rd{cold}{2.02,1.50}{2.02,1.61}\ph{2.02,1.50}
\rs{hot}{0.22,1.30}{0.22,1.16}\pf{0.22,1.30}
\rs{hot}{-1.11,0.29}{-1.11,0.24}\pf{-1.11,0.29}
\rs{hot}{-0.24,0.71}{-0.24,0.62}\pf{-0.24,0.71}
\rs{hot}{-1.61,-0.10}{-1.61,-0.37}\pf{-1.61,-0.10}
\rs{hot}{-0.90,0.19}{-0.90,-0.02}\pf{-0.90,0.19}
\rs{hot}{1.36,1.93}{1.36,1.28}\pf{1.36,1.93}
\rs{cold}{1.73,0.55}{1.73,1.33}\pf{1.73,0.55}
\rs{hot}{0.39,0.89}{0.39,0.58}\pf{0.39,0.89}
\rs{hot}{0.74,0.66}{0.74,0.60}\pf{0.74,0.66}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Turn the view: the plane rises along $x_1$ and falls along $x_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.19s = "true", 8.44s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-1.05,-0.68) -- (2.93,1.89) -- (1.05,1.68) -- (-2.93,-0.89) -- cycle;
\draw[mid] (-0.06,-0.04) -- (-1.93,-0.25);
\draw[mid] (-1.52,-0.73) -- (2.46,1.84);
\draw[mid] (0.94,0.60) -- (-0.94,0.40);
\draw[mid] (-1.99,-0.79) -- (1.99,1.79);
\draw[mid] (1.93,1.25) -- (0.06,1.04);
\draw[mid] (-2.46,-0.84) -- (1.52,1.74);
\draw[->] (-1.05,-2.89) -- (3.82,-2.20);
\draw[->] (-1.05,-2.89) -- (-3.49,-1.35);
\draw[->] (-3.07,-1.61) -- (-3.07,3.43);
\node at (1.81,-2.70) {$x_1$};
\node at (-2.87,-2.20) {$x_2$};
\node at (-3.07,3.81) {$y$};
\rd{cold}{-1.41,-0.29}{-1.41,-0.01}\ph{-1.41,-0.29}
\rd{cold}{0.09,0.79}{0.09,0.85}\ph{0.09,0.79}
\rd{cold}{-1.87,-0.45}{-1.87,-0.36}\ph{-1.87,-0.45}
\rd{cold}{-1.49,-0.42}{-1.49,-0.16}\ph{-1.49,-0.42}
\rd{cold}{-0.85,-0.09}{-0.85,0.10}\ph{-0.85,-0.09}
\rd{cold}{2.01,1.44}{2.01,1.55}\ph{2.01,1.44}
\rs{hot}{0.42,1.28}{0.42,1.14}\pf{0.42,1.28}
\rs{hot}{-0.97,0.32}{-0.97,0.26}\pf{-0.97,0.32}
\rs{hot}{-0.14,0.71}{-0.14,0.62}\pf{-0.14,0.71}
\rs{hot}{-1.59,-0.06}{-1.59,-0.32}\pf{-1.59,-0.06}
\rs{hot}{-0.91,0.22}{-0.91,0.01}\pf{-0.91,0.22}
\rs{hot}{1.36,1.89}{1.36,1.24}\pf{1.36,1.89}
\rs{cold}{1.67,0.50}{1.67,1.28}\pf{1.67,0.50}
\rs{hot}{0.34,0.89}{0.34,0.57}\pf{0.34,0.89}
\rs{hot}{0.62,0.65}{0.62,0.59}\pf{0.62,0.65}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Turn the view: the plane rises along $x_1$ and falls along $x_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.44s = "true", 8.69s = "false", 12.09s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-1.25,-0.65) -- (2.85,1.84) -- (1.25,1.65) -- (-2.85,-0.84) -- cycle;
\draw[mid] (-0.22,-0.03) -- (-1.83,-0.22);
\draw[mid] (-1.65,-0.70) -- (2.45,1.79);
\draw[mid] (0.80,0.60) -- (-0.80,0.41);
\draw[mid] (-2.05,-0.74) -- (2.05,1.75);
\draw[mid] (1.83,1.22) -- (0.22,1.03);
\draw[mid] (-2.45,-0.79) -- (1.65,1.70);
\draw[->] (-1.25,-2.86) -- (3.77,-2.28);
\draw[->] (-1.25,-2.86) -- (-3.33,-1.29);
\draw[->] (-2.97,-1.56) -- (-2.97,3.48);
\node at (1.66,-2.73) {$x_1$};
\node at (-2.90,-2.14) {$x_2$};
\node at (-2.97,3.86) {$y$};
\rd{cold}{-1.32,-0.27}{-1.32,0.02}\ph{-1.32,-0.27}
\rd{cold}{0.19,0.79}{0.19,0.85}\ph{0.19,0.79}
\rd{cold}{-1.81,-0.42}{-1.81,-0.33}\ph{-1.81,-0.42}
\rd{cold}{-1.43,-0.40}{-1.43,-0.13}\ph{-1.43,-0.40}
\rd{cold}{-0.83,-0.08}{-0.83,0.12}\ph{-0.83,-0.08}
\rd{cold}{1.98,1.41}{1.98,1.51}\ph{1.98,1.41}
\rs{hot}{0.55,1.26}{0.55,1.12}\pf{0.55,1.26}
\rs{hot}{-0.88,0.33}{-0.88,0.27}\pf{-0.88,0.33}
\rs{hot}{-0.08,0.71}{-0.08,0.62}\pf{-0.08,0.71}
\rs{hot}{-1.57,-0.03}{-1.57,-0.29}\pf{-1.57,-0.03}
\rs{hot}{-0.90,0.24}{-0.90,0.02}\pf{-0.90,0.24}
\rs{hot}{1.36,1.87}{1.36,1.22}\pf{1.36,1.87}
\rs{hot}{0.30,0.89}{0.30,0.57}\pf{0.30,0.89}
\rs{cold}{1.62,0.47}{1.62,1.26}\pf{1.62,0.47}
\rs{hot}{0.54,0.64}{0.54,0.59}\pf{0.54,0.64}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Turn the view: the plane rises along $x_1$ and falls along $x_2$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 8.69s = "true", 12.09s = "true", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-1.31,-0.64) -- (2.82,1.82) -- (1.31,1.64) -- (-2.82,-0.82) -- cycle;
\draw[mid] (-0.28,-0.02) -- (-1.79,-0.21);
\draw[mid] (-1.69,-0.68) -- (2.44,1.78);
\draw[mid] (0.75,0.59) -- (-0.75,0.41);
\draw[mid] (-2.07,-0.73) -- (2.07,1.73);
\draw[mid] (1.79,1.21) -- (0.28,1.02);
\draw[mid] (-2.44,-0.77) -- (1.69,1.69);
\draw[->] (-1.31,-2.84) -- (3.75,-2.31);
\draw[->] (-1.31,-2.84) -- (-3.27,-1.27);
\draw[->] (-2.93,-1.54) -- (-2.93,3.50);
\node at (1.60,-2.74) {$x_1$};
\node at (-2.91,-2.12) {$x_2$};
\node at (-2.93,3.88) {$y$};
\rd{cold}{-1.28,-0.26}{-1.28,0.02}\ph{-1.28,-0.26}
\rd{cold}{0.23,0.78}{0.23,0.84}\ph{0.23,0.78}
\rd{cold}{-1.79,-0.41}{-1.79,-0.32}\ph{-1.79,-0.41}
\rd{cold}{-1.41,-0.39}{-1.41,-0.13}\ph{-1.41,-0.39}
\rd{cold}{-0.82,-0.07}{-0.82,0.12}\ph{-0.82,-0.07}
\rd{cold}{1.97,1.39}{1.97,1.50}\ph{1.97,1.39}
\rs{hot}{0.59,1.26}{0.59,1.12}\pf{0.59,1.26}
\rs{hot}{-0.84,0.33}{-0.84,0.28}\pf{-0.84,0.33}
\rs{hot}{-0.05,0.71}{-0.05,0.62}\pf{-0.05,0.71}
\rs{hot}{-1.56,-0.02}{-1.56,-0.28}\pf{-1.56,-0.02}
\rs{hot}{-0.90,0.25}{-0.90,0.03}\pf{-0.90,0.25}
\rs{hot}{1.35,1.86}{1.35,1.21}\pf{1.35,1.86}
\rs{hot}{0.29,0.89}{0.29,0.57}\pf{0.29,0.89}
\rs{cold}{1.61,0.46}{1.61,1.25}\pf{1.61,0.46}
\rs{hot}{0.51,0.64}{0.51,0.58}\pf{0.51,0.64}
\filldraw[draw=black, fill=hot] (6.38,-2.4) rectangle (6.82,-1.86);
\node[anchor=east] at (6.18,-1.86) {$2.11$};
\node[anchor=west] at (4.2,3.0) {$\hat y = 2.62 + 0.60\,x_1 - 0.41\,x_2$};
\node[anchor=west] at (-3.9,-3.55) {Each residual $e_i = y_i - \hat y_i$ is the vertical gap to the plane. Red: $e_i > 0$.};
\end{scope}
\end{tikzpicture}
\end{document}Properties
(Rank-Deficient Designs) Without full column rank, OLS has infinitely many solutions, and all of them give the same fitted values.
When or columns are collinear, the inverse of fails to exist and the problem is ill-posed without regularization. The normal equations still have solutions, because lies in the column space of . Adding any vector from the null space of to a solution gives another solution. Every solution produces the same , since the projection onto the column space is unique. The fitted values are identified, and the individual coefficients are not. The pseudoinverse picks the solution with the smallest norm, . Ridge regression gives a unique solution for every , and it approaches as .
(Hat Matrix) The fitted values are a linear projection of the response.
Defining the hat matrix , the fitted values are , justifying the name (it puts the “hat” on ). The hat matrix is the orthogonal projector onto the column space of . It is symmetric and idempotent (). Its trace equals , the number of fitted parameters and the rank of the projection. The diagonal entries are the leverages of each observation. Each measures how much observation ‘s own response influences its own fitted value, since . The leverages lie between and and average . Large leverages identify points whose removal could significantly change the fit.
The animation shows least squares as a projection for observations. Each axis is one observation, and the columns and span a plane. The closest point of that plane to is , where the residual is perpendicular to the plane.
\usepackage{tikz}
\usetikzlibrary{animations, arrows.meta}
\begin{document}
\definecolor{hot}{HTML}{D9483B}
\definecolor{cold}{HTML}{2F80ED}
\definecolor{mid}{HTML}{8A8A8A}
\begin{tikzpicture}[font=\small, >={Stealth[length=2.2mm]}]
\begin{scope}[animate = {myself: = {:visible = {0s = "true", 2.8s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.22,-2.20) -- (2.36,-0.76) -- (0.18,1.83) -- (-2.41,0.39) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.53,0.39) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.20,-1.15) -- (3.26,0.27);
\node[fill=white, inner sep=1pt] at (3.68,0.44) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.20,-1.15) -- (0.28,-1.87);
\draw[mid, ->] (0.28,-1.87) -- (0.86,-2.75);
\node[fill=white, inner sep=1pt] at (1.03,-3.00) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.20,-1.15) -- (-0.80,1.11);
\node[fill=white, inner sep=1pt] at (-0.89,1.46) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.20,-1.15) -- (1.03,-0.47);
\draw[->, very thick] (-0.20,-1.15) -- (-1.53,0.42);
\draw[->, very thick, cold] (-0.20,-1.15) -- (0.12,1.95);
\draw[hot, very thick] (0.18,0.58) -- (0.12,1.95);
\filldraw[draw=black, fill=hot] (0.18,0.58) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.12,1.95) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (1.08,-0.59) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.65,0.42) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (-0.03,2.05) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 1.02\,\mathbf 1 + 0.66\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.89$};
\node[anchor=west] at (-3.9,-3.8) {Each axis is one observation. The columns $\mathbf 1$ and $\mathbf x$ span a plane, $\mathrm{col}\,\mathbf X$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 2.8s = "true", 3.02s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.25,-2.20) -- (2.35,-0.76) -- (0.20,1.83) -- (-2.41,0.39) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.53,0.39) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.22,-1.15) -- (3.25,0.26);
\node[fill=white, inner sep=1pt] at (3.67,0.43) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.22,-1.15) -- (0.26,-1.87);
\draw[mid, ->] (0.26,-1.87) -- (0.86,-2.75);
\node[fill=white, inner sep=1pt] at (1.02,-3.00) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.22,-1.15) -- (-0.80,1.12);
\node[fill=white, inner sep=1pt] at (-0.89,1.46) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.22,-1.15) -- (1.02,-0.47);
\draw[->, very thick] (-0.22,-1.15) -- (-1.52,0.42);
\draw[->, very thick, cold] (-0.22,-1.15) -- (0.12,1.95);
\draw[hot, very thick] (0.10,0.58) -- (0.12,1.95);
\filldraw[draw=black, fill=hot] (0.10,0.58) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.12,1.95) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (1.07,-0.59) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.64,0.42) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (-0.03,2.05) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.97\,\mathbf 1 + 0.68\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.89$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.02s = "true", 3.24s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.33,-2.20) -- (2.33,-0.78) -- (0.26,1.83) -- (-2.39,0.41) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.51,0.41) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.26,-1.15) -- (3.21,0.24);
\node[fill=white, inner sep=1pt] at (3.63,0.41) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.26,-1.15) -- (0.23,-1.87);
\draw[mid, ->] (0.23,-1.87) -- (0.84,-2.76);
\node[fill=white, inner sep=1pt] at (1.01,-3.01) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.26,-1.15) -- (-0.80,1.12);
\node[fill=white, inner sep=1pt] at (-0.88,1.47) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.26,-1.15) -- (1.01,-0.47);
\draw[->, very thick] (-0.26,-1.15) -- (-1.51,0.43);
\draw[->, very thick, cold] (-0.26,-1.15) -- (0.13,1.95);
\draw[hot, very thick] (-0.13,0.55) -- (0.13,1.95);
\filldraw[draw=black, fill=hot] (-0.13,0.55) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.13,1.95) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (1.06,-0.59) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.63,0.43) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (-0.02,2.05) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.82\,\mathbf 1 + 0.72\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.88$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.24s = "true", 3.46s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.44,-2.19) -- (2.28,-0.80) -- (0.36,1.82) -- (-2.37,0.43) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.49,0.43) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.32,-1.15) -- (3.14,0.21);
\node[fill=white, inner sep=1pt] at (3.56,0.37) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.32,-1.15) -- (0.19,-1.88);
\draw[mid, ->] (0.19,-1.88) -- (0.81,-2.77);
\node[fill=white, inner sep=1pt] at (0.98,-3.02) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.32,-1.15) -- (-0.80,1.13);
\node[fill=white, inner sep=1pt] at (-0.87,1.48) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.32,-1.15) -- (0.98,-0.48);
\draw[->, very thick] (-0.32,-1.15) -- (-1.49,0.45);
\draw[->, very thick, cold] (-0.32,-1.15) -- (0.14,1.95);
\draw[hot, very thick] (-0.40,0.45) -- (0.14,1.95);
\filldraw[draw=black, fill=hot] (-0.40,0.45) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.14,1.95) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (1.03,-0.60) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.61,0.45) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (-0.01,2.05) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.61\,\mathbf 1 + 0.75\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.86$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.46s = "true", 3.68s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.59,-2.19) -- (2.23,-0.83) -- (0.48,1.82) -- (-2.34,0.46) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.46,0.46) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.40,-1.14) -- (3.06,0.17);
\node[fill=white, inner sep=1pt] at (3.48,0.32) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.40,-1.14) -- (0.13,-1.88);
\draw[mid, ->] (0.13,-1.88) -- (0.77,-2.78);
\node[fill=white, inner sep=1pt] at (0.95,-3.03) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.40,-1.14) -- (-0.79,1.14);
\node[fill=white, inner sep=1pt] at (-0.85,1.49) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.40,-1.14) -- (0.95,-0.50);
\draw[->, very thick] (-0.40,-1.14) -- (-1.46,0.46);
\draw[->, very thick, cold] (-0.40,-1.14) -- (0.15,1.95);
\draw[hot, very thick] (-0.57,0.29) -- (0.15,1.95);
\filldraw[draw=black, fill=hot] (-0.57,0.29) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.15,1.95) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (1.00,-0.62) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.58,0.46) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (-0.00,2.05) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.44\,\mathbf 1 + 0.71\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.84$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.68s = "true", 3.9s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.77,-2.18) -- (2.16,-0.87) -- (0.63,1.81) -- (-2.30,0.50) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.42,0.50) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.49,-1.14) -- (2.96,0.12);
\node[fill=white, inner sep=1pt] at (3.38,0.27) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.49,-1.14) -- (-0.01,-1.80);
\draw[mid, ->] (-0.01,-1.80) -- (0.72,-2.79);
\node[fill=white, inner sep=1pt] at (0.91,-3.04) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.49,-1.14) -- (-0.79,1.15);
\node[fill=white, inner sep=1pt] at (-0.84,1.50) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.49,-1.14) -- (0.91,-0.51);
\draw[->, very thick] (-0.49,-1.14) -- (-1.42,0.49);
\draw[->, very thick, cold] (-0.49,-1.14) -- (0.16,1.95);
\draw[hot, very thick] (-0.49,0.09) -- (0.16,1.95);
\filldraw[draw=black, fill=hot] (-0.49,0.09) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.16,1.95) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.96,-0.63) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.54,0.49) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.01,2.05) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.40\,\mathbf 1 + 0.60\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.81$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 3.9s = "true", 4.12s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-0.96,-2.16) -- (2.08,-0.90) -- (0.79,1.80) -- (-2.25,0.54) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.37,0.54) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.59,-1.13) -- (2.85,0.07);
\node[fill=white, inner sep=1pt] at (3.26,0.22) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.59,-1.13) -- (-0.09,-1.80);
\draw[mid, ->] (-0.09,-1.80) -- (0.67,-2.80);
\node[fill=white, inner sep=1pt] at (0.86,-3.06) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.59,-1.13) -- (-0.78,1.16);
\node[fill=white, inner sep=1pt] at (-0.81,1.52) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.59,-1.13) -- (0.86,-0.53);
\draw[->, very thick] (-0.59,-1.13) -- (-1.37,0.51);
\draw[->, very thick, cold] (-0.59,-1.13) -- (0.18,1.94);
\draw[hot, very thick] (-0.15,-0.05) -- (0.18,1.94);
\filldraw[draw=black, fill=hot] (-0.15,-0.05) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.18,1.94) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.91,-0.65) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.49,0.51) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.03,2.04) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.55\,\mathbf 1 + 0.46\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.79$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 4.12s = "true", 4.34s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-1.16,-2.14) -- (2.00,-0.94) -- (0.96,1.78) -- (-2.20,0.58) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.32,0.58) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.69,-1.11) -- (2.72,0.02);
\node[fill=white, inner sep=1pt] at (3.13,0.16) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.69,-1.11) -- (-0.17,-1.79);
\draw[mid, ->] (-0.17,-1.79) -- (0.61,-2.81);
\node[fill=white, inner sep=1pt] at (0.81,-3.07) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.69,-1.11) -- (-0.78,1.18);
\node[fill=white, inner sep=1pt] at (-0.79,1.53) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.69,-1.11) -- (0.81,-0.54);
\draw[->, very thick] (-0.69,-1.11) -- (-1.32,0.53);
\draw[->, very thick, cold] (-0.69,-1.11) -- (0.19,1.94);
\draw[hot, very thick] (0.26,-0.05) -- (0.19,1.94);
\filldraw[draw=black, fill=hot] (0.26,-0.05) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.19,1.94) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.86,-0.66) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.44,0.53) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.04,2.04) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.79\,\mathbf 1 + 0.37\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.77$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 4.34s = "true", 4.56s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-1.36,-2.12) -- (1.90,-0.98) -- (1.12,1.76) -- (-2.14,0.62) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.26,0.62) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.80,-1.10) -- (2.59,-0.03);
\node[fill=white, inner sep=1pt] at (3.00,0.10) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.80,-1.10) -- (-0.33,-1.70);
\draw[mid, ->] (-0.33,-1.70) -- (0.55,-2.82);
\node[fill=white, inner sep=1pt] at (0.76,-3.09) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.80,-1.10) -- (-0.77,1.19);
\node[fill=white, inner sep=1pt] at (-0.76,1.55) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.80,-1.10) -- (0.76,-0.56);
\draw[->, very thick] (-0.80,-1.10) -- (-1.27,0.56);
\draw[->, very thick, cold] (-0.80,-1.10) -- (0.21,1.94);
\draw[hot, very thick] (0.53,0.05) -- (0.21,1.94);
\filldraw[draw=black, fill=hot] (0.53,0.05) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.21,1.94) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.81,-0.68) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.39,0.56) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.06,2.04) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.97\,\mathbf 1 + 0.38\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.75$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 4.56s = "true", 4.78s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-1.56,-2.09) -- (1.81,-1.01) -- (1.29,1.74) -- (-2.08,0.66) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.20,0.66) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-0.90,-1.09) -- (2.45,-0.07);
\node[fill=white, inner sep=1pt] at (2.86,0.05) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-0.90,-1.09) -- (-0.41,-1.70);
\draw[mid, ->] (-0.41,-1.70) -- (0.49,-2.83);
\node[fill=white, inner sep=1pt] at (0.70,-3.10) {\footnotesize obs.\ 2};
\draw[mid, ->] (-0.90,-1.09) -- (-0.76,1.21);
\node[fill=white, inner sep=1pt] at (-0.74,1.56) {\footnotesize obs.\ 3};
\draw[->, very thick] (-0.90,-1.09) -- (0.70,-0.57);
\draw[->, very thick] (-0.90,-1.09) -- (-1.22,0.58);
\draw[->, very thick, cold] (-0.90,-1.09) -- (0.23,1.93);
\draw[hot, very thick] (0.55,0.17) -- (0.23,1.93);
\filldraw[draw=black, fill=hot] (0.55,0.17) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.23,1.93) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.75,-0.69) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.34,0.58) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.08,2.03) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.99\,\mathbf 1 + 0.44\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.74$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 4.78s = "true", 5s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-1.75,-2.07) -- (1.72,-1.04) -- (1.44,1.72) -- (-2.03,0.69) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.15,0.69) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-1.00,-1.07) -- (2.32,-0.11);
\node[fill=white, inner sep=1pt] at (2.72,0.00) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-1.00,-1.07) -- (-0.50,-1.69);
\draw[mid, ->] (-0.50,-1.69) -- (0.43,-2.84);
\node[fill=white, inner sep=1pt] at (0.65,-3.11) {\footnotesize obs.\ 2};
\draw[mid, ->] (-1.00,-1.07) -- (-0.75,1.22);
\node[fill=white, inner sep=1pt] at (-0.71,1.57) {\footnotesize obs.\ 3};
\draw[->, very thick] (-1.00,-1.07) -- (0.65,-0.58);
\draw[->, very thick] (-1.00,-1.07) -- (-1.17,0.60);
\draw[->, very thick, cold] (-1.00,-1.07) -- (0.24,1.93);
\draw[hot, very thick] (0.42,0.23) -- (0.24,1.93);
\filldraw[draw=black, fill=hot] (0.42,0.23) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.24,1.93) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.70,-0.70) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.29,0.60) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.09,2.03) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.91\,\mathbf 1 + 0.51\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.73$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5s = "true", 5.22s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-1.91,-2.04) -- (1.64,-1.07) -- (1.58,1.69) -- (-1.97,0.72) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.09,0.72) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-1.08,-1.05) -- (2.20,-0.15);
\node[fill=white, inner sep=1pt] at (2.60,-0.04) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-1.08,-1.05) -- (-0.57,-1.68);
\draw[mid, ->] (-0.57,-1.68) -- (0.38,-2.85);
\node[fill=white, inner sep=1pt] at (0.61,-3.12) {\footnotesize obs.\ 2};
\draw[mid, ->] (-1.08,-1.05) -- (-0.74,1.23);
\node[fill=white, inner sep=1pt] at (-0.69,1.58) {\footnotesize obs.\ 3};
\draw[->, very thick] (-1.08,-1.05) -- (0.61,-0.59);
\draw[->, very thick] (-1.08,-1.05) -- (-1.12,0.62);
\draw[->, very thick, cold] (-1.08,-1.05) -- (0.25,1.93);
\draw[hot, very thick] (0.29,0.22) -- (0.25,1.93);
\filldraw[draw=black, fill=hot] (0.29,0.22) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.25,1.93) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.66,-0.71) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.24,0.62) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.10,2.03) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.82\,\mathbf 1 + 0.54\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.72$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.22s = "true", 5.44s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-2.05,-2.01) -- (1.56,-1.09) -- (1.69,1.67) -- (-1.92,0.75) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.17,-2.01) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-1.15,-1.04) -- (2.09,-0.18);
\node[fill=white, inner sep=1pt] at (2.49,-0.07) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-1.15,-1.04) -- (-0.63,-1.67);
\draw[mid, ->] (-0.63,-1.67) -- (0.34,-2.85);
\node[fill=white, inner sep=1pt] at (0.57,-3.13) {\footnotesize obs.\ 2};
\draw[mid, ->] (-1.15,-1.04) -- (-0.73,1.24);
\node[fill=white, inner sep=1pt] at (-0.66,1.59) {\footnotesize obs.\ 3};
\draw[->, very thick] (-1.15,-1.04) -- (0.57,-0.60);
\draw[->, very thick] (-1.15,-1.04) -- (-1.07,0.63);
\draw[->, very thick, cold] (-1.15,-1.04) -- (0.26,1.92);
\draw[hot, very thick] (0.23,0.19) -- (0.26,1.92);
\filldraw[draw=black, fill=hot] (0.23,0.19) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.26,1.92) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.62,-0.72) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.19,0.63) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.11,2.02) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.78\,\mathbf 1 + 0.53\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.72$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.44s = "true", 5.66s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-2.16,-1.99) -- (1.50,-1.10) -- (1.78,1.65) -- (-1.88,0.77) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.28,-1.99) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-1.21,-1.03) -- (2.01,-0.20);
\node[fill=white, inner sep=1pt] at (2.40,-0.10) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-1.21,-1.03) -- (-0.68,-1.67);
\draw[mid, ->] (-0.68,-1.67) -- (0.30,-2.85);
\node[fill=white, inner sep=1pt] at (0.53,-3.14) {\footnotesize obs.\ 2};
\draw[mid, ->] (-1.21,-1.03) -- (-0.72,1.25);
\node[fill=white, inner sep=1pt] at (-0.65,1.60) {\footnotesize obs.\ 3};
\draw[->, very thick] (-1.21,-1.03) -- (0.53,-0.60);
\draw[->, very thick] (-1.21,-1.03) -- (-1.04,0.64);
\draw[->, very thick, cold] (-1.21,-1.03) -- (0.27,1.92);
\draw[hot, very thick] (0.24,0.16) -- (0.27,1.92);
\filldraw[draw=black, fill=hot] (0.24,0.16) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.27,1.92) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.58,-0.72) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.16,0.64) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.12,2.02) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.78\,\mathbf 1 + 0.51\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.72$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.66s = "true", 5.88s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-2.22,-1.98) -- (1.47,-1.11) -- (1.84,1.64) -- (-1.85,0.78) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.34,-1.98) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-1.24,-1.02) -- (1.95,-0.21);
\node[fill=white, inner sep=1pt] at (2.34,-0.11) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-1.24,-1.02) -- (-0.71,-1.66);
\draw[mid, ->] (-0.71,-1.66) -- (0.28,-2.86);
\node[fill=white, inner sep=1pt] at (0.51,-3.14) {\footnotesize obs.\ 2};
\draw[mid, ->] (-1.24,-1.02) -- (-0.72,1.25);
\node[fill=white, inner sep=1pt] at (-0.64,1.60) {\footnotesize obs.\ 3};
\draw[->, very thick] (-1.24,-1.02) -- (0.51,-0.61);
\draw[->, very thick] (-1.24,-1.02) -- (-1.02,0.65);
\draw[->, very thick, cold] (-1.24,-1.02) -- (0.27,1.92);
\draw[hot, very thick] (0.26,0.15) -- (0.27,1.92);
\filldraw[draw=black, fill=hot] (0.26,0.15) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.27,1.92) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.56,-0.73) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.14,0.65) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.12,2.02) {$\mathbf y$};
\node[anchor=west] at (4.2,1.6) {$\mathbf X\beta = 0.79\,\mathbf 1 + 0.50\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \mathbf X\beta\| = 1.71$};
\node[anchor=west] at (-3.9,-3.8) {A candidate $\mathbf X\beta$ moves in the plane. Red: the gap $\mathbf y - \mathbf X\beta$.};
\end{scope}
\begin{scope}[animate = {myself: = {:visible = {0s = "false", 5.88s = "true", 9.48s = "false", 9.48s = "false", repeats}}}]
\filldraw[draw=mid, thick, fill=white] (-2.25,-1.97) -- (1.45,-1.11) -- (1.86,1.64) -- (-1.84,0.78) -- cycle;
\node[inner sep=1pt, anchor=east] at (-2.37,-1.97) {$\mathrm{col}\,\mathbf X$};
\draw[mid, ->] (-1.26,-1.02) -- (1.93,-0.22);
\node[fill=white, inner sep=1pt] at (2.32,-0.12) {\footnotesize obs.\ 1};
\draw[mid, dashed] (-1.26,-1.02) -- (-0.72,-1.66);
\draw[mid, ->] (-0.72,-1.66) -- (0.27,-2.86);
\node[fill=white, inner sep=1pt] at (0.51,-3.14) {\footnotesize obs.\ 2};
\draw[mid, ->] (-1.26,-1.02) -- (-0.71,1.25);
\node[fill=white, inner sep=1pt] at (-0.63,1.60) {\footnotesize obs.\ 3};
\draw[->, very thick] (-1.26,-1.02) -- (0.51,-0.61);
\draw[->, very thick] (-1.26,-1.02) -- (-1.01,0.65);
\draw[->, very thick, cold] (-1.26,-1.02) -- (0.28,1.92);
\draw (0.28,0.35) -- (0.07,0.40) -- (0.07,0.19);
\draw[hot, very thick] (0.28,0.14) -- (0.28,1.92);
\filldraw[draw=black, fill=hot] (0.28,0.14) circle (2.6pt);
\filldraw[draw=black, fill=cold] (0.28,1.92) circle (2.6pt);
\node[fill=white, inner sep=1pt, anchor=north west] at (0.56,-0.73) {$\mathbf 1$};
\node[fill=white, inner sep=1pt, anchor=east] at (-1.13,0.65) {$\mathbf x$};
\node[fill=white, inner sep=1pt, anchor=east] at (0.13,2.02) {$\mathbf y$};
\node[fill=white, inner sep=1pt, anchor=west] at (0.46,-0.06) {$\hat{\mathbf y}$};
\node[fill=white, inner sep=1pt, anchor=west] at (0.43,1.03) {$\mathbf e$};
\node[anchor=west] at (4.2,1.6) {$\hat{\mathbf y} = 0.80\,\mathbf 1 + 0.50\,\mathbf x$};
\node[anchor=west] at (4.2,0.95) {$\|\mathbf y - \hat{\mathbf y}\| = 1.71$};
\node[anchor=west] at (-3.9,-3.8) {The gap is shortest at $\hat{\mathbf y}$. There $\mathbf e = \mathbf y - \hat{\mathbf y}$ is perpendicular to the plane, so $\mathbf X^T\mathbf e = \mathbf 0$.};
\end{scope}
\end{tikzpicture}
\end{document}(Gauss-Markov Theorem) OLS is the BLUE under uncorrelated, constant-variance noise.
If and , then OLS has the smallest variance among all linear unbiased estimators of . It is the best linear unbiased estimator (BLUE). “Smallest” means that is positive semidefinite for every other linear unbiased estimator . The result requires no distributional assumption beyond the first two moments. When the noise is correlated or heteroskedastic, with , the BLUE becomes the generalized least squares estimator
which weights observations by the inverse noise covariance.
(Residual Variance) is the unbiased estimator of .
The denominator is the degrees of freedom remaining after fitting parameters. The MLE under Gaussian noise is the corresponding biased estimator that divides by . Dividing by corrects for the lost degrees of freedom and produces an unbiased estimator. This is the variance estimator that goes into standard errors and -statistics.
(Inference Under Normality) The coefficient vector is jointly Gaussian.
Under , the estimator is exactly Gaussian: . Individual coefficients can be tested via under . Groups of coefficients are tested via -tests on nested models. Without Gaussianity, the same statistics are approximately Normal by the central limit theorem when is large.
(Spurious Regression) Regressing one trending variable on another can produce false significance.
Two unrelated variables can both trend over time, or both have unit-root behavior. An OLS regression of one on the other then often produces a high and small -values. This happens even though the variables share no real dependence, because the common trend is mistaken for a relationship. A regression of one time series on another therefore needs checks for trends and unit roots. The standard remedies are differencing the series, including a trend term explicitly, or testing for cointegration. See 2.4 Time Series Regression for the time-series-specific treatment.
(Iterative Computation by Gradient Descent) When or is too large for the closed form, gradient descent solves the same optimization.
Forming and inverting costs . For very large (millions of rows) or very large (thousands of features), this cost becomes prohibitive. Iterative methods such as gradient descent on ,
converge to the same OLS minimum at per step and avoid the matrix inversion entirely. Convergence needs a learning rate , where is the largest singular value of . This is the standard algorithm for fitting linear models on big data. Logistic regression and most of deep learning use the same algorithm with a different loss.
Examples
(Easy) Predicting House Price from Multiple Features
is sale price. The predictors are square footage, number of bedrooms, age, and distance to downtown, so plus an intercept. Fit OLS on houses.
How do we read the fit? has five entries. Each of the four slopes is the marginal effect of a one-unit change in its predictor, holding all others fixed. So is the predicted price increase per added bedroom, conditional on square footage, age, and distance staying constant. The standard error of each coefficient depends on . If bedrooms and square footage are highly correlated, both standard errors will be large. The data cannot cleanly attribute price increases to one or the other. The adjusted then compares this fit with smaller models, since it penalizes each added predictor.
The coefficient vector
(Medium) Polynomial Regression as a Special Case
Fit to a curved scatter plot.
Why is this still linear regression? function of is non-linear, the parameters enter linearly. Setting up the design matrix with columns recovers a multiple linear regression problem with . The OLS solution and all the inferential machinery apply unchanged. This is the standard way to fit non-linear shapes with linear regression. Pick a basis (polynomials, splines, sinusoids) and treat the basis evaluations as new predictors, as in 3.1b. Basis Function Regression.
Although the
(Medium) Geometric Derivation of the Normal Equations
Show that being the orthogonal projection of onto implies .
How does orthogonality give the formula? such that is perpendicular to every column of . In matrix form, . Substituting gives the normal equations . Inverting the Gram matrix, which needs full column rank, produces . The orthogonality condition is therefore the same matrix equation that defines the OLS solution.
The orthogonal projection is the unique vector in
See Also
- 3.1. Linear Regression, the simple-regression starting point.
- 3.1b. Basis Function Regression, for curves fit as multiple regression on transformed inputs.
- 3.3. Nonlinear Regression, when the response depends on parameters non-linearly.
- 3.2. Regularization, ridge and lasso for ill-conditioned or high-dimensional designs.
- 2.1.4. R-Squared, for the coefficient of determination and its adjusted version.
- 2.3.2. Cross-Validation, model-selection machinery for choosing predictor sets.
- 2.4 Time Series Regression, applying MLR to time-indexed data with correlated errors.
- 3.8.1 Bayesian Linear Regression, putting a prior on and reporting a posterior.