Linear regression with one regressor \(\vec{z}_{\cdot 1}\) and intercept \(\theta_0\), \(n=6\) (regression parameters denoted \(\theta_0, \theta_1\)). Orange points are the sample points \((z_{1,i}, X_i)\). Green points are the regression points \((z_{1,i}, \widehat{X}_i)\). The total area of the violet squares equals \(\operatorname{TSS}\), and of the red ones β \(\operatorname{RSS}\).
Linear Regression
This lecture note is still being edited: the text may contain typos, inaccuracies, and locally underdeveloped passages. If you find something, please let the author know (contact information on the course page).
In this chapter \(\vec{X}\) denotes the observations.
1 Problem statement
In this chapter we consider a fairly special but widely applicable problem in the theory of estimating statistical parameters. The observation in this problem is no longer a sample (a collection of independent random variables), but a vector made up of random variables whose distributions may differ.
1.1 Linear regression without an intercept
In general, we are given a bag of coins of \(k\) different types, \(\theta_{1}\) is the mass of a type-1 coin, \(\ldots\), \(\theta_{k}\) is the mass of a type-\(k\) coin. The researcher estimates the masses of the coins. To do this, they weigh combinations of coins \(n\) times: at step \(i \in \left\{ 1,\ldots , n\right\}\) they weigh \(z_{i,1}\) coins of type 1, \(\ldots\), \(z_{i,k}\) coins of type \(k\). If the scale operates without error, then the measurement values will equal linear combinations of \(\theta_{1}, \ldots , \theta_{k}\). But since errors are nevertheless present, the observed quantity obtained at the \(i\)-th weighing \((i \in \{ 1, \ldots , n\} )\) equals
\[ X_i = z_{i, 1} \theta _{1}+\ldots +z_{i, k} \theta _{k}+\varepsilon _{i}, \]
where \(z_{i, j} \in \mathbb {R}\) are known coefficients of the linear combination, \(k\) is the number of coins participating in the \(i\)-th weighing, and \(\varepsilon_{i}\) is the measurement error at the \(i\)-th weighing. The full sample \(\vec{X}\):
\[ \begin{align} \begin{pmatrix} X_1 \\ X_2 \\ \vdots \\ X_n \end{pmatrix} & = \underbrace{\begin{pmatrix} z_{1, 1} \theta _{1}+\ldots +z_{1, k} \theta _{k} \\ z_{2, 1} \theta _{1}+\ldots +z_{2, k} \theta _{k} \\ \vdots \\ z_{n, 1} \theta _{1}+\ldots +z_{n, k} \theta _{k} \end{pmatrix}}_{= \vec{z}_{\cdot 1} \theta _1 + \ldots + \vec{z}_{\cdot k} \theta _k} + \underbrace{\begin{pmatrix} \varepsilon _1 \\ \varepsilon _2 \\ \vdots \\ \varepsilon _n \end{pmatrix}}_{=\vec{\varepsilon }} \end{align} \]
in short:
\[ \vec{X} = \mathbf{z}\vec{\theta } + \vec{\varepsilon }, \]
where
\[ \begin{align} \vec{z}_{\cdot 1} & = \begin{pmatrix} z_{1,1} \\ z_{2,1} \\ \vdots \\ z_{n,1} \end{pmatrix}, \ldots , \vec{z}_{\cdot k} = \begin{pmatrix} z_{1,k} \\ z_{2,k} \\ \vdots \\ z_{n,k} \end{pmatrix}, \\ \mathbf{z} = (\vec{z}_{\cdot 1} \; \vec{z}_{\cdot 2} \; \ldots \; \vec{z}_{\cdot k} ) & = \begin{pmatrix} z_{1,1} & z_{1,2} & \ldots & z_{1,k} \\ z_{2,1} & z_{2,2} & \ldots & z_{2,k} \\ \vdots & \vdots & \vdots & \vdots \\ z_{n,1} & z_{n,2} & \ldots & z_{n,k} \end{pmatrix}, \\ \vec{\theta } & = \begin{pmatrix} \theta _1 \\ \vdots \\ \theta _k \end{pmatrix}, \quad \vec{l} = \mathbf{z}\vec{\theta } \end{align} \]
\(X_i\) is called the dependent variable, \(z_{i,1}, \ldots , z_{i,k}\) are called the independent variables or regressors, and \(\varepsilon_i\) is called the error or residual. Note that \(z_{i,1}, \ldots , z_{i,k}\) are known non-random values, even though they are called independent variables. The only random component in the model is the error \(\varepsilon_i\), and it is through this that \(X_i\) is random.
Suppose the column vectors \(\vec{z}_{\cdot 1} , \vec{z}_{\cdot 2} , \ldots , \vec{z}_{\cdot k}\) are linearly dependent. Let \(\vec{z}_{\cdot i_1}, \vec{z}_{\cdot i_2}, \ldots , \vec{z}_{\cdot i_{k'}}\) be a maximal linearly independent subset of \(\vec{z}_{\cdot 1} , \ldots , \vec{z}_{\cdot k}\). One can prove that the original model and the model \(\vec{X} = \vec{x}_{i_1}\theta_{\cdot i_1} + \ldots + \vec{z}_{\cdot i_{k'}}\theta_{i_{k'}} + \vec{\varepsilon }\) are equivalent, in the sense that whatever method we choose for estimating the unknown coefficients and the quality of the regression (more on this below), the quality of the model turns out the same in both cases. Going forward, for brevity we will assume that the original collection \(\vec{z}_{\cdot 1} , \ldots , \vec{z}_{\cdot k}\) is already linearly independent by itself. Moreover, we will assume that the regressors are collectively nontrivial, namely that the space \(L := \operatorname {span}(\vec{z}_{\cdot 1} , \ldots , \vec{z}_{\cdot k} )\) contains no vector consisting solely of constants. Regression with a constant regressor is discussed in the next section.
As a rule, \(k\) is much smaller than \(n\), and the matrix \(\mathbf{z}\) ends up extremely stretched vertically. The problem consists of estimating the true values \(\theta_{1}, \ldots , \theta_{k}\) from the observation \(X_{1}, \ldots , X_{n}\).
The observation \(\vec{X} = (X_1, \ldots , X_n)^T\) is a random vector from \(\mathbb {R}^{n}\), where \(\vec{l} = \vec{l}(\vec{\theta }) := \mathbf{z}\vec{\theta }\) is a fixed unknown vector, and \(\vec{\varepsilon }\) is a random vector.
About the vector \(\vec{l} = \mathbf{z}\vec{\theta }\) we know that \(\vec{l} = \mathbf{z}\vec{\theta } \in L\), where
\[ L=\left\langle \vec{z}_{\cdot 1}, \ldots , \vec{z}_{\cdot k}\right\rangle = \operatorname {span}\left(\vec{z}_{\cdot 1}, \ldots , \vec{z}_{\cdot k}\right) \]
is a given linear subspace of \(\mathbb {R}^{n}\) of dimension \(k<n\) (\(\vec{z}_{\cdot 1}, \ldots , \vec{z}_{\cdot k}\) are basis column vectors of the space \(L\)). The parameters of the linear regression model described above are \(\vec{\theta }\) and \(\sigma^{2}\), whose estimation is discussed below.
Note that in this case, strictly speaking, according to our definition \(\vec{X}\) is not a sample of size \(n\), since the components of \(\vec{X}\) may have different distributions. However, \(\vec{X}\) can be viewed as a sample of size \(1\) from an \(n\)-dimensional distribution with parameters \(\vec{\theta }, \sigma^2\). Therefore, even in the absence of independence, one can, for example, speak of the existence of a likelihood function, apply factorization criteria to search for sufficient statistics, and so on. The likelihood function in this case is simply the density of the \(n\)-dimensional vector \(\vec{X}\).
1.2 Linear regression with an intercept
The model
\[ X_i = \theta _0 + z_{i, 1} \theta _{1}+\ldots +z_{i, k} \theta _{k}+\varepsilon _{i}. \]
is called linear regression with an intercept. \(\theta_0\) is called the intercept of the regression. We have
\[ \begin{align} \vec{X} = \begin{pmatrix} X_1 \\ X_2 \\ \vdots \\ X_n \end{pmatrix} & = \begin{pmatrix} 1 & z_{1,1} & \ldots & z_{1,k} \\ 1 & z_{2,1} & \ldots & z_{2,k} \\ \vdots & \vdots & \vdots \\ 1 & z_{n,1} & \ldots & z_{n,k} \end{pmatrix} \cdot \begin{pmatrix} \theta _0 \\ \theta _1 \\ \vdots \\ \theta _k \end{pmatrix} + \begin{pmatrix} \varepsilon _1 \\ \varepsilon _2 \\ \vdots \\ \varepsilon _n \end{pmatrix} = \\ & = \vec{z}_{\cdot 0}\theta _0 + \vec{z}_{\cdot 1} \theta _1 + \ldots + \vec{z}_{\cdot k} \theta _k + \vec{\varepsilon } = \\ & = \mathbf{z}\vec{\theta } + \vec{\varepsilon } \end{align} \]
The vector of ones \(\vec{z}_{\cdot 0} = (1, \ldots , 1)^T\) is conveniently denoted \(\overrightarrow {1}\).
1.3 Conditions on the errors \(\vec{\varepsilon }\)
The following conditions are typically imposed on the error vector \(\vec{\varepsilon }\): it is square-integrable (expectations and variances exist), and moreover
\(\mathbb {E}\left[\vec{\varepsilon }\right] = \overrightarrow {0} \in \mathbb {R}^{n}\), i.e. all errors are centered;
\(\operatorname {Var}\left[\vec{\varepsilon }\right] = \sigma^2 \mathbf{I}_n\), where \(\operatorname {Var}\left[\vec{\varepsilon }\right]\) is the covariance matrix of the vector \(\vec{\varepsilon }\), and \(\mathbf{I}_{n}\) is the \(n \times n\) identity matrix. That is, all errors have the same variance \(\sigma^2\) and different errors are uncorrelated. This property is also called homoscedasticity, from Greek α½ΞΌΟΟ (homos, βsameβ) + ΟκΡδαΟΟΟΟ (skedastos, βscatteredβ).
In practice these conditions on the errors are far from always satisfied, but often the original model can be reduced to one in which the conditions on the errors do hold. For example, under homoscedasticity the condition of centered errors can be relaxed: suppose \(\mathbb {E}\left[\vec{\varepsilon }\right] = \mu \overrightarrow {1}\), i.e. all errors have the same, but now unknown, nonzero expectation. Then from the model \(X_i = \theta_0 + z_{i, 1} \theta_{1}+\ldots +z_{i, k} \theta_{k}+\varepsilon_{i}\) we can pass to the model
\[ X_i = \theta '_0 + z_{i, 1} \theta _{1}+\ldots +z_{i, k} \theta _{k}+\varepsilon '_{i} \]
where
\[ \theta '_0 := \theta _0 + \mu , \quad \varepsilon _i' := \varepsilon _i - \mu . \]
In this model, the errors \(\varepsilon '\) have become centered. For more on reducing a model to standard form, see the problems below.
2 Ordinary least squares (OLS) in parameter estimation
So, the problem of estimating the vector \(\vec{\theta }\) can be solved using the method of ordinary least squares (OLS). The least-squares estimate of the parameters equals
\[ \widehat{\vec{\theta }}_{\text{OLS}} \; := \; \operatorname *{arg\, min}_{\vec{\theta } \in \mathbb {R}^{k}}\left\| \vec{X} -\mathbf{z}\vec{\theta }\right\| ^2 \]
Further,
\(\widehat{\vec{X}}_{\text{OLS}} =\mathbf{z} \cdot \widehat{\vec{\theta }}_{\text{OLS}} = \vec{X}_{L}\) (the orthogonal projection of \(\vec{X}\) onto \(L\)),
\(\widehat{\vec{\varepsilon }}_{\text{OLS}} = \vec{X} - \widehat{\vec{X}}_{\text{OLS}} = \vec{X} - \vec{X}_{L} = \vec{X}_{L^\perp }\) (the orthogonal projection onto \(L^{\perp }\)).
Going forward, for brevity, whenever we speak of estimates of the parameters, observations, and errors, we will assume that estimation is performed by OLS and write \(\widehat{\vec{\theta }}, \widehat{\vec{X}}, \widehat{\vec{\varepsilon }}\) instead of \(\widehat{\vec{\theta }}_{\text{OLS}} , \widehat{\vec{X}}_{\text{OLS}} , \widehat{\vec{\varepsilon }}_{\text{OLS}}\), although, generally speaking, there are other ways to estimate \(\vec{\theta }\), model the sample, and model the errors.
2.1 Explicit formula for the OLS estimate
Letβs find an explicit formula for \(\widehat{\vec{\theta }}\). Letβs solve a problem from linear algebra.
Altogether, the OLS estimation formula for linear regression is:
\[ \widehat{\vec{\theta }} = \widehat{\vec{\theta }}(\vec{X}) = \left(\mathbf{z}^T\mathbf{z}\right)^{-1}\mathbf{z}^T \cdot \vec{X} \]
2.2 Geometry of OLS: regression without an intercept
Geometry of OLS regression without an intercept (Three.js version): \(\overrightarrow X\) is the vector of observations, \(\widehat{\overrightarrow X}=\overrightarrow X_L=\mathbf z\widehat{\overrightarrow\theta}\) is its orthogonal projection onto \(L=\operatorname{span}(\overrightarrow z_{\cdot 1},\ldots,\overrightarrow z_{\cdot k})\), and \(\widehat{\overrightarrow\varepsilon}\) is the error vector. The right angle at vertex \(B\) of triangle \(OBA\) illustrates that \(X-\widehat X\perp L\); the coefficient of determination is \(R^2=\cos^2\varphi=\operatorname{ESS}/\operatorname{TSS}\), where \(\varphi=\angle AOB\) β the larger it is, the closer \(\varphi\) is to zero, and the better the linear model. The labels are genuinely rendered LaTeX (KaTeX), anchored to their line/vector and rotated along it; they stay in place as you rotate the scene with the mouse. The mouse wheel zooms.
Consider the graph @LinearRegr:GraphRegrWoParam. By the Pythagorean theorem we have
\[ \left\| \vec{X}\right\| ^2 = \left\| \widehat{\vec{X}}\right\| ^2 + \left\| \widehat{\vec{\varepsilon }}\right\| ^2 \]
The total sum of squares of the observations \(\left\| \vec{X}\right\|^2\) is called the total sum of squares, denoted \(\operatorname {TSS}\):
\[ \operatorname {TSS} := \left\| \vec{X}\right\| ^2 = \sum _{i=1}^n X_i^2 \]
The sum of squares of the estimated observations \(\left\| \widehat{\vec{X}}\right\|^2\) is called the explained sum of squares, denoted \(\operatorname {ESS}\):
\[ \operatorname {ESS} := \left\| \widehat{\vec{X}}\right\| ^2 = \sum _{i=1}^n \widehat{X}_i^2 \]
The sum of squares of the errors \(\left\| \widehat{\vec{\varepsilon }}\right\|^2\) is called the residual sum of squares, denoted \(\operatorname {RSS}\):
\[ \operatorname {RSS} := \left\| \widehat{\vec{\varepsilon }}\right\| ^2 = \left\| \vec{X} - \widehat{\vec{X}}\right\| ^2 = \sum _{i=1}^n \left(X_i - \widehat{X}_i\right)^2 \]
By the Pythagorean theorem, the total sum of squares splits into the explained sum of squares and the sum of squares of the error estimates:
\[ \operatorname {TSS} = \operatorname {ESS} + \operatorname {RSS} \]
2.2.1 Coefficient of determination
The better the OLS-fitted regression describes the behavior of the dependent variable \(\vec{X}\), the smaller the length of the error vector \(\widehat{\vec{\varepsilon }} = \vec{X} - \vec{X}_{L}\) should be compared to the length of the observation vector \(\vec{X}\). The quantity
\[ R^2 := 1 - \frac{\left\| \widehat{\vec{\varepsilon }}\right\| ^2}{\left\| \vec{X}\right\| ^2} = 1 - \frac{\sum _{i=1}^n \left(X_i - \widehat{X}_i\right)^2}{\sum _{i=1}^n X_i^2} \]
is called the coefficient of determination.
The coefficient of determination takes values between \(0\) and \(1\). The closer it is to \(1\), the better the regression.
Various formulas for the coefficient of determination:
\[ \begin{align} R^2 & = 1 - \frac{\left\| \widehat{\vec{\varepsilon }}\right\| ^2}{\left\| \vec{X}\right\| ^2} = 1 - \frac{\operatorname {RSS}}{\operatorname {TSS}} = \\ & = 1 - \frac{\sum _{i=1}^n \left(X_i - \widehat{X}_i\right)^2}{\sum _{i=1}^n X_i^2} = \\ & = \frac{\operatorname {ESS}}{\operatorname {TSS}} = \frac{\left\| \widehat{\vec{X}}\right\| ^2}{\left\| \vec{X}\right\| ^2} = \frac{\sum _{i=1}^n \widehat{X}_i^2}{\sum _{i=1}^n X_i^2} \end{align} \]
The coefficient of determination has several closely related interpretations. On one hand it is the fraction of the spread in the dependent variable \(\vec{X}\) that our model has managed to βexplainβ: \(\operatorname {ESS}/\operatorname {TSS}\).
On the other hand, one can say that our fitted model \(\widehat{\vec{X}}\) is being compared to the only model available for explaining \(\vec{X}\) in the absence of regressors β the model \(\vec{X} = \overrightarrow {0} + \vec{\varepsilon }\), i.e. \(\vec{X}\) is simply noise made of independent, identically distributed, centered errors. In this approach, the coefficient of determination is one minus the ratio of the spread in the first model to the spread in the second:
\[ 1 - \frac{\operatorname {RSS}}{\operatorname {TSS}} \]
The closer it is to one, the better our model performs compared to the most trivial model.
A simple model against which more complex models are compared is called a reference model or baseline model (English benchmark model). In this case the baseline model is independent, identically distributed noise. \(\operatorname {TSS}\) is the sum of squares of the errors when using such a model. \(\operatorname {ESS}\) is the sum of squares of the difference between the baseline model and our model.
2.3 Geometry of OLS: regression with an intercept
With an intercept \(\theta_0\) present, the baseline model for comparisons changes. Now, in the absence of regressors, the best model for explaining \(\vec{X}\) is the model of a constant \(\theta_0\) plus noise \(\vec{\varepsilon }\). The estimate of \(\theta_0\) minimizing the sum of squared errors in such a model is the sample mean \(\overline{X}\). The baseline model for modeling \(\vec{X}\):
\[ \left(\overline{X}, \ldots , \overline{X}\right)^T = \overline{X} \cdot \overrightarrow {1}, \]
where \(\overrightarrow {1} = (1, \ldots , 1)^T\) is the vector in \(\mathbb {R}^{n}\) made up of ones.
\(\operatorname {TSS}\), \(\operatorname {ESS}\) are, respectively, the sum of squares of the errors when using the baseline model and the sum of squares of the difference between the baseline model and our model. Their computation now also changes. The computation of \(\operatorname {RSS}\) remains the same.
Total sum of squares:
\[ \operatorname {TSS} = \left\| \vec{X} - \overline{X}\cdot \overrightarrow {1}\right\| ^2 = \sum _{i=1}^n (X_i - \overline{X})^2 \]
Explained sum of squares:
\[ \operatorname {ESS} = \left\| \widehat{\vec{X}} - \overline{X}\cdot \overrightarrow {1}\right\| ^2 = \sum _{i=1}^n (\widehat{X}_i- \overline{X})^2 \]
Residual sum of squares:
\[ \operatorname {RSS} = \left\| \vec{X} - \widehat{\vec{X}}\right\| ^2 = \sum _{i=1}^n \left(X_i - \widehat{X}_i\right)^2 \]
Geometry of OLS regression with an intercept (Three.js version): \(D\) is the point of the baseline model \(\overline X\cdot\overrightarrow 1\), \(A\) is the vector of observations \(\overrightarrow X\), \(B\) is its projection \(\widehat{\overrightarrow X}=\overrightarrow X_L=\mathbf z\widehat{\overrightarrow\theta}\) onto \(L\). The right angle at vertex \(B\) of triangle \(DBA\) illustrates that \(X-\widehat X\perp L\); the coefficient of determination is \(R^2=\cos^2\varphi=\operatorname{ESS}/\operatorname{TSS}\), where \(\varphi=\angle ADB\) β the larger it is, the closer \(\varphi\) is to zero, and the better the linear model. The labels are genuinely rendered LaTeX (KaTeX), anchored to their line/vector and rotated along it; they stay in place as you rotate the scene with the mouse. The mouse wheel zooms.
Consider the graph @LinearRegr:GraphRegrWithParam. By the Pythagorean theorem for triangle \(ABD\) we again have (recall that \(\widehat{\vec{X}} = \vec{X}_{L}\) when the model is fitted by OLS):
\[ \begin{align} \operatorname {TSS} & = \left\| \vec{X} - \overline{X}\cdot \overrightarrow {1}\right\| ^2 = \left|AD\right|^2 = \\ & = \left|BD\right|^2 + \left|AB\right|^2 = \left\| \widehat{\vec{X}} - \overline{X}\cdot \overrightarrow {1}\right\| ^2 + \left\| \vec{X} - \widehat{\vec{X}}\right\| ^2 = \\ & = \operatorname {ESS} + \operatorname {RSS} \end{align} \]
Coefficient of determination:
\[ \begin{align} R^2 & = 1 - \frac{\operatorname {RSS}}{\operatorname {TSS}} = 1 - \frac{\sum _{i=1}^n \left(X_i - \widehat{X}_i\right)^2}{\sum _{i=1}^n (X_i - \overline{X})^2} = \\ & = \frac{\operatorname {ESS}}{\operatorname {TSS}} = \frac{\sum _{i=1}^n \left(\overline{X} - \widehat{X}_i\right)^2}{\sum _{i=1}^n (X_i - \overline{X})^2} \end{align} \]
For the same sample, the coefficient of determination for the model with an intercept can turn out to be either larger or smaller than the coefficient of determination of the model without one, despite the fact that the first model is obviously more flexible.
2.4 Properties of the OLS estimates
Recall, \(\widehat{\vec{\theta }} = \left(\mathbf{z}^T\mathbf{z}\right)^{-1}\mathbf{z}^T\vec{X}\). Denote by \(\widetilde{k}\) the number of columns of the matrix \(\mathbf{z}\):
\[ \widetilde{k} := \begin{cases} k, & \text{ if the regression has no intercept }\theta _0;\\ k+1 , & \text{ if the regression has an intercept }\theta _0. \end{cases} \]
Expectation and covariance matrix of \(\widehat{\vec{\theta }}\):
\[ \mathbb {E}_{\vec{\theta }, \sigma ^2}\left[\widehat{\vec{\theta }}\right] = \vec{\theta }, \qquad \operatorname {Var}_{\vec{\theta }, \sigma ^2}\left[\widehat{\vec{\theta }}\right] = \sigma ^2 \left(\mathbf{z}^T \mathbf{z}\right)^{-1} \]
Thus, the ordinary least squares estimator is unbiased.
Knowing the covariance matrix of the vector \(\widehat{\vec{\theta }}\), we can find the expectation of the (squared) distance from \(\vec{X}\) to the subspace \(L \subset \mathbb {R}^{n}\):
\[ \mathbb {E}_{\vec{\theta }, \sigma ^2}\left[\left\| \vec{X} - \underbrace{\mathbf{z}\widehat{\vec{\theta }}}_{=\vec{X}_{L} = \widehat{\vec{X}}}\right\| ^2\right] = \mathbb {E}_{\vec{\theta }, \sigma ^2}\left[\left\| \underbrace{\widehat{\vec{\varepsilon }}}_{=\vec{X}_{L^\perp }}\right\| ^2\right] = \mathbb {E}_{\vec{\theta }, \sigma ^2}\left[\operatorname {RSS}\right] = \left(n-\widetilde{k}\right)\sigma ^2 \]
This last equality gives an unbiased estimator of the parameter \(\sigma^{2}\):
\[ \widehat{\sigma ^{2}} := \frac{1}{n-\widetilde{k}}\left\| \vec{X}-\mathbf{z} \widehat{\vec{\theta }}\right\| ^{2} = \frac{\operatorname {RSS}}{n-\widetilde{k}}. \]
Sampling distribution of the OLS estimator
The cloud shows estimates \((\hat\theta_0,\hat\theta_1)\) over \(800\) independent repetitions of the experiment \(X_i=\theta_0+\theta_1 z_i+\varepsilon_i\), \(\varepsilon_i\sim\mathcal N(0,\sigma^2)\); the star is the true \(\theta=(2,\,0.5)\); the red ellipse is the theoretical \(95\%\) ellipse of the covariance matrix \(\sigma^2(\vec z^T\vec z)^{-1}\).
3 Gaussian linear regression
We will devote the second half of this chapter exclusively to a special case of the linear regression model of exceptional practical importance, namely the Gaussian linear model. This is the linear regression model \(\vec{X}=\mathbf{z}\vec{\theta }+\vec{\varepsilon }\), in which the errors are distributed according to a multivariate Gaussian law:
\[ \vec{\varepsilon } \sim \mathscr {N}\left(\overrightarrow {0}, \sigma ^2 \mathbf{I}_n\right) \]
Recall that \(\mathbf{z}\vec{\theta }\) is a non-random \(n\)-dimensional vector, so
\[ \vec{X} \sim \mathscr {N}\left(\mathbf{z}\vec{\theta }, \; \sigma ^{2} \mathbf{I}_{n}\right) \]
As already mentioned, \(\vec{X}\) can be viewed as a sample of size \(1\) from an \(n\)-dimensional distribution, in this case Gaussian. It has density with respect to Lebesgue measure on \(\mathbb {R}^{n}\):
\[ \begin{align} f_{\vec{\theta }, \sigma ^2}(\vec{x}) & = \frac{1}{\sqrt{(2\pi \sigma ^2)^n}} \mathrm{exp}\left(-\frac{1}{2\sigma ^2}\left(\vec{x} - \mathbf{z}\vec{\theta }\right)^T \left(\vec{x} - \mathbf{z}\vec{\theta }\right)\right) = \\ & = \frac{1}{\sqrt{(2\pi \sigma ^2)^n}} \mathrm{exp}\left(-\frac{1}{2\sigma ^2} \left\| \vec{x} - \mathbf{z}\vec{\theta }\right\| ^2\right), \qquad \vec{x} \in \mathbb {R}^{n} \end{align} \]
3.1 Complete, sufficient statistic. Optimal estimators
From the standard regression model it is known that the statistics
\[ \begin{align} \widehat{\vec{\theta }} & = \operatorname *{arg\, min}_{\vec{t} \in \mathbb {R}^{k}} \left\| \vec{X} - \mathbf{z}\vec{t}\right\| = \left(\mathbf{z}^T\mathbf{z}\right)^{-1}\mathbf{z}^T \vec{X}, \\ \widehat{\sigma ^2} & = \frac{1}{n-\widetilde{k}} \left\| \vec{X} - \mathbf{z}\widehat{\vec{\theta }}\right\| ^2 = \frac{1}{n-\widetilde{k}} \left\| \vec{X} - \vec{X}_{L}\right\| ^2 = \\ & = \frac{1}{n-\widetilde{k}}\left\| \vec{X}_{L^\perp }\right\| ^2 = \frac{1}{n -\tilde{k}}\operatorname {RSS} \end{align} \]
are unbiased estimators of \(\vec{\theta }, \sigma^2\). They are functions of the complete, sufficient statistic, and hence, by the Lehmann-ScheffΓ© theorem, \(\widehat{\vec{\theta }}, \widehat{\sigma^2}\) are optimal estimators of \(\vec{\theta }, \sigma^2\) in the Gaussian regression model.
3.2 Confidence intervals for the parameters
We have constructed point unbiased estimates of the parameters of the linear model, which in the Gaussian case turned out to be optimal. Let us now construct confidence intervals for these parameters.
Consider a motivating example.
Densities of \(\chi^2_k\) and \(T_k\)
Left: densities of \(\chi^2_k\) for \(k=1,2,3,5,10\). Right: densities of \(T_k\) for \(k=1,3,10\) and the limiting \(\mathcal N(0,1)\) (dashed). The black/teal curve on each panel is the current \(k\) from the slider, recomputed continuously.
In general, the following theorem holds.
In the general case \(\vec{X} \sim \mathscr {N}\left(\mathbf{z}\vec{\theta }, \sigma^2 \mathbf{I}_n\right)\), we need to construct confidence intervals for the components of \(\vec{\theta }\) and for \(\sigma^2\). Let
\[ L = \begin{cases} \operatorname {span}\left(\vec{z}_{\cdot 1}, \vec{z}_{\cdot 2}, \ldots , \vec{z}_{\cdot k}\right), & \text{if the model has no intercept } \theta _0 \\ \operatorname {span}\left(\overrightarrow {1}, \vec{z}_{\cdot 1}, \vec{z}_{\cdot 2}, \ldots , \vec{z}_{\cdot k}\right), & \text{if the model has an intercept } \theta _0 \end{cases} \]
Then the vectors \(\vec{X}_{L}, \vec{X}_{L^\perp }\) are independent Gaussian random vectors.
\(\widehat{\vec{\theta }}\) is linearly dependent on \(\vec{X}_{L}\),
\(\widehat{\sigma^2}\) is a function of \(\vec{X}_{L^\perp }\)
Hence \(\widehat{\vec{\theta }}, \widehat{\sigma^2}\) are independent. We have already computed above the expectation and covariance matrix of \(\widehat{\vec{\theta }} = \left(\mathbf{z}^T\mathbf{z}\right)^{-1}\mathbf{z}^T \vec{X}\): \(\mathbb {E}\left[\widehat{\vec{\theta }}\right] = \vec{\theta }\), \(\operatorname {Var}\left[\widehat{\vec{\theta }}\right] = \sigma^2 (\mathbf{z}^T \mathbf{z})^{-1}\); in the Gaussian case this means
\[ \widehat{\vec{\theta }} \sim \mathscr {N}\left(\vec{\theta }, \sigma ^2 (\mathbf{z}^T \mathbf{z})^{-1}\right). \]
Further,
\[ \begin{align} \vec{X}_{L^\perp } & = \vec{X} - \mathbf{z}\widehat{\vec{\theta }}, \qquad \mathbb {E}\left[\vec{X}_{L^\perp }\right] = \mathbb {E}\left[\vec{X} - \mathbf{z} \widehat{\vec{\theta }}\right] = \mathbf{z}\vec{\theta } - \mathbf{z}\vec{\theta } = \vec{0}, \\ \frac{1}{\sigma ^2} \left\| \vec{X}_{L^\perp } - \mathbb {E}\left[\vec{X}_{L^\perp }\right]\right\| ^2 & = \frac{1}{\sigma ^2 } \left\| \vec{X}_{L^\perp }\right\| ^2 = \frac{n-\widetilde{k}}{\sigma ^2}\widehat{\sigma ^2} \sim \chi ^2_{n-\widetilde{k}}. \end{align} \]
Let \(\left(\mathbf{z}^T\mathbf{z}\right)^{-1} =: (a_{i,j})\). Then
\[ \frac{\widehat{\vec{\theta }} - \vec{\theta }}{\sqrt{\sigma ^2}} \sim \mathscr {N}\left(\overrightarrow {0}, (\mathbf{z}^T \mathbf{z})^{-1}\right), \qquad \frac{\widehat{\vec{\theta }}_i - \theta _i}{\sqrt{a_{i,i}\sigma ^2}} \sim \mathscr {N}\left(0, 1\right), \; \forall i \in \left\{ 1,\ldots ,\widetilde{k}\right\} \]
In total, \(\frac{\widehat{\vec{\theta }}_i - \theta_i}{\sqrt{a_{i,i}\sigma^2}}, \frac{n-\widetilde{k}}{\sigma^2}\widehat{\sigma^2}\) are 2 independent random variables, where the first is distributed as \(\mathscr {N}\left(0, 1\right)\) and the second as \(\chi^2_{n-\widetilde{k}}\). Then, by the definition of Studentβs distribution, we have
\[ \begin{align} \frac{\frac{\widehat{\vec{\theta }}_i - \theta _i}{\sqrt{a_{i,i}\sigma ^2}}}{\sqrt{\frac{n-\widetilde{k}}{\sigma ^2}\widehat{\sigma ^2}} / \sqrt{n-\widetilde{k}}} = \frac{\widehat{\vec{\theta }}_i - \theta _i}{\sqrt{a_{i,i}\widehat{\sigma ^2}}} & \sim T_{n-\widetilde{k}} \end{align} \]
4 Regression with random regressors
The researcher does not always have the ability to control the regressors \(\mathbf{z}\). In general, they too can be treated as random:
\[ \vec{X} = \mathbf{Z}\vec{\theta } + \vec{\varepsilon }, \]
where \(\mathbf{Z}\) is a random element with values in the space \(\mathbb {R}^{n \times \widetilde{k}}\). The assumptions on the errors here are the same as in Section 1.3, but all expectations become conditional on \(\mathbf{Z}\):
\(\mathbb {E}\left[ \vec{\varepsilon } \mid \mathbf{Z} \right] = \overrightarrow {0} \in \mathbb {R}^{n}\);
\(\operatorname {Var}\left[ \vec{\varepsilon } \mid \mathbf{Z} \right] = \mathbb {E}\left[ \vec{\varepsilon }\vec{\varepsilon }^T \mid \mathbf{Z} \right] - \mathbb {E}\left[ \vec{\varepsilon } \mid \mathbf{Z} \right] \cdot \mathbb {E}\left[ \vec{\varepsilon }^T \mid \mathbf{Z} \right] = \sigma^2 \mathbf{I}_n\).
All the results obtained above remain valid if we replace expectations and distributions with conditional expectations and conditional distributions given \(\mathbf{Z}\). For example, in the case of Gaussian regression we now have \(\operatorname {Law}\left(\widehat{\vec{\theta }} \mid \mathbf{Z}\right) = \mathscr {N}\left(\vec{\theta }, \sigma^2 \left(\mathbf{Z}^T\mathbf{Z}\right)^{-1}\right)\).
The difference is, for example, that it is no longer so simple to obtain the unconditional distribution \(\operatorname {Law}\left(\widehat{\vec{\theta }}\right)\), since the distribution of \(\mathbf{Z}\) may be arbitrary. However, if the conditional distribution does not depend on \(\mathbf{Z}\), as, for example, in these cases:
\[ \operatorname {Law}\left(\frac{n-\widetilde{k}}{\sigma ^2}\widehat{\sigma ^2} \mid \mathbf{Z}\right)[\bigg] = \chi ^2_{n-\widetilde{k}}, \qquad \operatorname {Law}\left(\frac{\widehat{\vec{\theta }}_i - \theta _i}{\sqrt{a_{i,i}\widehat{\sigma ^2}}} \mid \mathbf{Z}\right)[\bigg] = T_{n-\widetilde{k}}, \]
then we can pass from the conditional distribution to the unconditional one:
\[ \operatorname {Law}\left(\frac{n-\widetilde{k}}{\sigma ^2}\widehat{\sigma ^2} \right) = \chi ^2_{n-\widetilde{k}}, \qquad \operatorname {Law}\left(\frac{\widehat{\vec{\theta }}_i - \theta _i}{\sqrt{a_{i,i}\widehat{\sigma ^2}}}\right) = T_{n-\widetilde{k}} \]