# Proofs involving ordinary least squares

The purpose of this page is to provide supplementary materials for the ordinary least squares article, reducing the load of the main article with mathematics and improving its accessibility, while at the same time retaining the completeness of exposition.

## Least squares estimator for β = b

Using matrix notation, the sum of squared residuals is given by

${\displaystyle S(b)=(y-Xb)'(y-Xb)\,}$

Where ${\displaystyle '}$ denotes the matrix transpose.

Since this is a quadratic expression, the vector which gives the global minimum may be found via matrix calculus by differentiating with respect to the vector b (using denominator layout) and setting equal to zero:

${\displaystyle 0={\frac {dS}{db}}({\hat {\beta }})={\frac {d}{db}}{\bigg (}y'y-b'X'y-y'Xb+b'X'Xb{\bigg )}{\bigg |}_{b={\hat {\beta }}}=-2X'y+2X'X{\hat {\beta }}}$

By assumption matrix X has full column rank, and therefore X'X is invertible and the least squares estimator for β is given by

${\displaystyle {\hat {\beta }}=(X'X)^{-1}X'y\,}$

## Unbiasedness and variance of ${\displaystyle {\hat {\beta }}}$

Plug y =  + ε into the formula for ${\displaystyle {\hat {\beta }}}$ and then use the Law of iterated expectation:

{\displaystyle {\begin{aligned}\operatorname {E} [\,{\hat {\beta }}]&=\operatorname {E} {\Big [}(X'X)^{-1}X'(X\beta +\varepsilon ){\Big ]}\\&=\beta +\operatorname {E} {\Big [}(X'X)^{-1}X'\varepsilon {\Big ]}\\&=\beta +\operatorname {E} {\Big [}\operatorname {E} {\Big [}(X'X)^{-1}X'\varepsilon |X{\Big ]}{\Big ]}\\&=\beta +\operatorname {E} {\Big [}(X'X)^{-1}X'\operatorname {E} [\varepsilon |X]{\Big ]}&=\beta ,\\\end{aligned}}}

where E[ε|X] = 0 by assumptions of the model.

For the variance, let ${\displaystyle \sigma ^{2}I}$ denote the covariance matrix of ${\displaystyle \varepsilon }$. Then,

{\displaystyle {\begin{aligned}\operatorname {E} [\,({\hat {\beta }}-\beta )({\hat {\beta }}-\beta )^{T}]&=\operatorname {E} {\Big [}((X'X)^{-1}X'\varepsilon )((X'X)^{-1}X'\varepsilon )^{T}{\Big ]}\\&=\operatorname {E} {\Big [}(X'X)^{-1}X'\varepsilon \varepsilon 'X(X'X)^{-1}{\Big ]}\\&=\operatorname {E} {\Big [}(X'X)^{-1}X'\sigma ^{2}X(X'X)^{-1}{\Big ]}\\&=\operatorname {E} {\Big [}\sigma ^{2}(X'X)^{-1}X'X(X'X)^{-1}{\Big ]}\\&=\sigma ^{2}(X'X)^{-1},\end{aligned}}}

where we used the fact that ${\displaystyle {\hat {\beta }}-\beta }$ is just an affine transformation of ${\displaystyle \varepsilon }$ by the matrix ${\displaystyle (X'X)^{-1}X'}$ ( see article on the multivariate normal distribution under the affine transformation section).

For a simple linear regression model, where ${\displaystyle \beta =[\beta _{0},\beta _{1}]^{T}}$ (${\displaystyle \beta _{0}}$ is the y-intercept and ${\displaystyle \beta _{1}}$ is the slope), one obtains

{\displaystyle {\begin{aligned}\sigma ^{2}(X'X)^{-1}&=\sigma ^{2}\left(\sum x_{i}x_{i}'\right)^{-1}\\&=\sigma ^{2}\left(\sum (1,x_{i})'(1,x_{i})\right)^{-1}\\&=\sigma ^{2}\left(\sum {\begin{pmatrix}1&x_{i}\\x_{i}&x_{i}^{2}\end{pmatrix}}\right)^{-1}\\&=\sigma ^{2}{\begin{pmatrix}n&\sum x_{i}\\\sum x_{i}&\sum x_{i}^{2}\end{pmatrix}}^{-1}\\&=\sigma ^{2}\cdot {\frac {1}{n\sum x_{i}^{2}-(\sum x_{i})^{2}}}{\begin{pmatrix}\sum x_{i}^{2}&-\sum x_{i}\\-\sum x_{i}&n\end{pmatrix}}\\&=\sigma ^{2}\cdot {\frac {1}{n\sum _{i=1}^{n}{(x_{i}-{\bar {x}})^{2}}}}{\begin{pmatrix}\sum x_{i}^{2}&-\sum x_{i}\\-\sum x_{i}&n\end{pmatrix}}\\\end{aligned}}}
{\displaystyle {\begin{aligned}\operatorname {Var} (\beta _{1})&={\frac {\sigma ^{2}}{\sum _{i=1}^{n}(x_{i}-{\bar {x}})^{2}}}.\end{aligned}}}

## Expected value of ${\displaystyle {\hat {\sigma }}^{2}}$

First we will plug in the expression for y into the estimator, and use the fact that X'M = MX = 0 (matrix M projects onto the space orthogonal to X):

${\displaystyle {\hat {\sigma }}^{2}={\tfrac {1}{n}}y'My={\tfrac {1}{n}}(X\beta +\varepsilon )'M(X\beta +\varepsilon )={\tfrac {1}{n}}\varepsilon 'M\varepsilon }$

Now we can recognize ε'Mε as a 1×1 matrix, such matrix is equal to its own trace. This is useful because by properties of trace operator, tr(AB)=tr(BA), and we can use this to separate disturbance ε from matrix M which is a function of regressors X:

${\displaystyle \operatorname {E} \,{\hat {\sigma }}^{2}={\tfrac {1}{n}}\operatorname {E} {\big [}\operatorname {tr} (\varepsilon 'M\varepsilon ){\big ]}={\tfrac {1}{n}}\operatorname {tr} {\big (}\operatorname {E} [M\varepsilon \varepsilon ']{\big )}}$

Using the Law of iterated expectation this can be written as

${\displaystyle \operatorname {E} \,{\hat {\sigma }}^{2}={\tfrac {1}{n}}\operatorname {tr} {\Big (}\operatorname {E} {\big [}M\,\operatorname {E} [\varepsilon \varepsilon '|X]{\big ]}{\Big )}={\tfrac {1}{n}}\operatorname {tr} {\big (}\operatorname {E} [\sigma ^{2}MI]{\big )}={\tfrac {1}{n}}\sigma ^{2}\operatorname {E} {\big [}\operatorname {tr} \,M{\big ]}}$

Recall that M = I − P where P is the projection onto linear space spanned by columns of matrix X. By properties of a projection matrix, it has p = rank(X) eigenvalues equal to 1, and all other eigenvalues are equal to 0. Trace of a matrix is equal to the sum of its characteristic values, thus tr(P)=p, and tr(M) = n − p. Therefore,

${\displaystyle \operatorname {E} \,{\hat {\sigma }}^{2}={\frac {n-p}{n}}\sigma ^{2}}$

Note: in the later section “Maximum likelihood” we show that under the additional assumption that errors are distributed normally, the estimator ${\displaystyle {\hat {\sigma }}^{2}}$ is proportional to a chi-squared distribution with n – p degrees of freedom, from which the formula for expected value would immediately follow. However the result we have shown in this section is valid regardless of the distribution of the errors, and thus has importance on its own.

## Consistency and asymptotic normality of ${\displaystyle {\hat {\beta }}}$

Estimator ${\displaystyle {\hat {\beta }}}$ can be written as

${\displaystyle {\hat {\beta }}={\big (}{\tfrac {1}{n}}X'X{\big )}^{-1}{\tfrac {1}{n}}X'y=\beta +{\big (}{\tfrac {1}{n}}X'X{\big )}^{-1}{\tfrac {1}{n}}X'\varepsilon =\beta \;+\;{\bigg (}{\frac {1}{n}}\sum _{i=1}^{n}x_{i}x'_{i}{\bigg )}^{\!\!-1}{\bigg (}{\frac {1}{n}}\sum _{i=1}^{n}x_{i}\varepsilon _{i}{\bigg )}}$

We can use the law of large numbers to establish that

${\displaystyle {\frac {1}{n}}\sum _{i=1}^{n}x_{i}x'_{i}\ {\xrightarrow {p}}\ \operatorname {E} [x_{i}x_{i}']={\frac {Q_{xx}}{n}},\qquad {\frac {1}{n}}\sum _{i=1}^{n}x_{i}\varepsilon _{i}\ {\xrightarrow {p}}\ \operatorname {E} [x_{i}\varepsilon _{i}]=0}$

By Slutsky's theorem and continuous mapping theorem these results can be combined to establish consistency of estimator ${\displaystyle {\hat {\beta }}}$:

${\displaystyle {\hat {\beta }}\ {\xrightarrow {p}}\ \beta +Q_{xx}^{-1}\cdot 0=\beta }$

The central limit theorem tells us that

${\displaystyle {\frac {1}{\sqrt {n}}}\sum _{i=1}^{n}x_{i}\varepsilon _{i}\ {\xrightarrow {d}}\ {\mathcal {N}}{\big (}0,\,V{\big )},}$ where ${\displaystyle V=\operatorname {Var} [x_{i}\varepsilon _{i}]=\operatorname {E} [\,\varepsilon _{i}^{2}x_{i}x'_{i}\,]=\operatorname {E} {\big [}\,\operatorname {E} [\varepsilon _{i}^{2}\mid x_{i}]\;x_{i}x'_{i}\,{\big ]}=\sigma ^{2}{\frac {Q_{xx}}{n}}}$

Applying Slutsky's theorem again we'll have

${\displaystyle {\sqrt {n}}({\hat {\beta }}-\beta )={\bigg (}{\frac {1}{n}}\sum _{i=1}^{n}x_{i}x'_{i}{\bigg )}^{\!\!-1}{\bigg (}{\frac {1}{\sqrt {n}}}\sum _{i=1}^{n}x_{i}\varepsilon _{i}{\bigg )}\ {\xrightarrow {d}}\ Q_{xx}^{-1}n\cdot {\mathcal {N}}{\big (}0,\sigma ^{2}{\frac {Q_{xx}}{n}}{\big )}={\mathcal {N}}{\big (}0,\sigma ^{2}Q_{xx}^{-1}n{\big )}}$

## Maximum likelihood approach

Maximum likelihood estimation is a generic technique for estimating the unknown parameters in a statistical model by constructing a log-likelihood function corresponding to the joint distribution of the data, then maximizing this function over all possible parameter values. In order to apply this method, we have to make an assumption about the distribution of y given X so that the log-likelihood function can be constructed. The connection of maximum likelihood estimation to OLS arises when this distribution is modeled as a multivariate normal.

Specifically, assume that the errors ε have multivariate normal distribution with mean 0 and variance matrix σ2I. Then the distribution of y conditionally on X is

${\displaystyle y|X\ \sim \ {\mathcal {N}}(X\beta ,\,\sigma ^{2}I)}$

and the log-likelihood function of the data will be

{\displaystyle {\begin{aligned}{\mathcal {L}}(\beta ,\sigma ^{2}|X)&=\ln {\bigg (}{\frac {1}{(2\pi )^{n/2}(\sigma ^{2})^{n/2}}}e^{-{\frac {1}{2}}(y-X\beta )'(\sigma ^{2}I)^{-1}(y-X\beta )}{\bigg )}\\&=-{\frac {n}{2}}\ln 2\pi -{\frac {n}{2}}\ln \sigma ^{2}-{\frac {1}{2\sigma ^{2}}}(y-X\beta )'(y-X\beta )\end{aligned}}}

Differentiating this expression with respect to β and σ2 we'll find the ML estimates of these parameters:

{\displaystyle {\begin{aligned}&{\frac {\partial {\mathcal {L}}}{\partial \beta '}}=-{\frac {1}{2\sigma ^{2}}}{\Big (}-2X'y+2X'X\beta {\Big )}=0\quad \Rightarrow \quad {\hat {\beta }}=(X'X)^{-1}X'y\\&{\frac {\partial {\mathcal {L}}}{\partial \sigma ^{2}}}=-{\frac {n}{2}}{\frac {1}{\sigma ^{2}}}+{\frac {1}{2\sigma ^{4}}}(y-X\beta )'(y-X\beta )=0\quad \Rightarrow \quad {\hat {\sigma }}^{2}={\frac {1}{n}}(y-X{\hat {\beta }})'(y-X{\hat {\beta }})={\frac {1}{n}}S({\hat {\beta }})\end{aligned}}}

We can check that this is indeed a maximum by looking at the Hessian matrix of the log-likelihood function.

### Finite-sample distribution

Since we have assumed in this section that the distribution of error terms is known to be normal, it becomes possible to derive the explicit expressions for the distributions of estimators ${\displaystyle {\hat {\beta }}}$ and ${\displaystyle {\hat {\sigma }}^{2}}$:

${\displaystyle {\hat {\beta }}=(X'X)^{-1}X'y=(X'X)^{-1}X'(X\beta +\varepsilon )=\beta +(X'X)^{-1}X'{\mathcal {N}}(0,\sigma ^{2}I)}$
${\displaystyle {\hat {\beta }}|X\ \sim \ {\mathcal {N}}(\beta ,\,\sigma ^{2}(X'X)^{-1}).}$

Similarly the distribution of ${\displaystyle {\hat {\sigma }}^{2}}$ follows from

{\displaystyle {\begin{aligned}{\hat {\sigma }}^{2}&={\tfrac {1}{n}}(y-X(X'X)^{-1}X'y)'(y-X(X'X)^{-1}X'y)\\[5pt]&={\tfrac {1}{n}}(My)'My\\[5pt]&={\tfrac {1}{n}}(X\beta +\varepsilon )'M(X\beta +\varepsilon )\\[5pt]&={\tfrac {1}{n}}\varepsilon 'M\varepsilon ,\end{aligned}}}

where ${\displaystyle M=I-X(X'X)^{-1}X'}$ is the symmetric projection matrix onto subspace orthogonal to X, and thus MX = X'M = 0. We have argued before that this matrix rank n – p, and thus by properties of chi-squared distribution,

${\displaystyle {\tfrac {n}{\sigma ^{2}}}{\hat {\sigma }}^{2}|X=(\varepsilon /\sigma )'M(\varepsilon /\sigma )\ \sim \ \chi _{n-p}^{2}}$

Moreover, the estimators ${\displaystyle {\hat {\beta }}}$ and ${\displaystyle {\hat {\sigma }}^{2}}$ turn out to be independent (conditional on X), a fact which is fundamental for construction of the classical t- and F-tests. The independence can be easily seen from following: the estimator ${\displaystyle {\hat {\beta }}}$ represents coefficients of vector decomposition of ${\displaystyle {\hat {y}}=X{\hat {\beta }}=Py=X\beta +P\varepsilon }$ by the basis of columns of X, as such ${\displaystyle {\hat {\beta }}}$ is a function of . At the same time, the estimator ${\displaystyle {\hat {\sigma }}^{2}}$ is a norm of vector divided by n, and thus this estimator is a function of . Now, random variables (, ) are jointly normal as a linear transformation of ε, and they are also uncorrelated because PM = 0. By properties of multivariate normal distribution, this means that and are independent, and therefore estimators ${\displaystyle {\hat {\beta }}}$ and ${\displaystyle {\hat {\sigma }}^{2}}$ will be independent as well.