MIT 18.650 — Lecture 24
Linear Regression II
§ Variance of the LS Solution
Here's an alternative way of presenting the assumptions we made about the relationship between feature vectors and response variables from Lecture 23.
Assumption. For some true unknown , we have , where for some (unknown) constant .
Under this model, the maximum-likelihood estimator is . But what's the variance of this estimator? How far does it tend to be off from the true value ?
Remark. Recall that the estimator is still an MLE, so all the properties of MLE—consistency, asymptotic normality—still hold. (But finding the asymptotic variance isn't as straightforward as computing the Fisher information.)
Theorem. (LS Variance) We have .
Proof: More generally, it is true that the vector satisfies , where . Thus,
The rest of the proof is just multivariate Gaussian properties; recall Lecture 6, or more fundamentally, the properties of covariance matrices from Lecture 5.
The mean of the RHS is clearly , whereas the covariance is:
Yeah, the computations look terrible, but at least it matches what the theorem promised.
§ Linear Regression Confidence Intervals
We know the variance now, so surely computing confidence intervals and performing tests should be easy, right?
There's still a problem: we don't know , so the variance being still doesn't tell us anything yet. But—in a similar fashion as bootstrapping—there's a trick to use the training data to estimate .
Theorem. (Estimating Regression Variance) Given the training data and , we may compute the vector . Then the estimator is an unbiased estimator for .
Remark. This is a very technically dense proof, but the fundamental ideas are relatively straightforward.

The above is an image outlining the ideas of the proof for and .
The orange subspace is the column span of , with vector lying on it.
We assume this subspace has dimension .
The vector is the result of taking and adding -dimensional Gaussian noise .
The foot of the altitude of onto the orange plane is , and is the altitude vector itself.
Crucially, only of the “directions” of Gaussian noise point orthogonally to the orange -dimensional subspace.
It is only these directions of noise that contribute to the squared length of .
Thus, we might expect the squared length of to be the sum of copies of .
That's why we might expect ; in general, the coefficient of would be . The technical complexity of the proof comes from having to formalize the notion of “directions of noise”.
Proof: The first step is to rewrite as the “orthogonal component” of the overall Gaussian noise .
Lemma 1. Let denote the map given by projecting vectors onto the column space of . Then .
Proof: Recalling from Lecture 23 that , we can rewrite the definition of like so:
However, because already lies on the column space of —that is, because . Then all that remains is the term, as promised.
Define the matrix ; think of not as a projection map, but as an “altitude” map. Then we seek to show that , where .
To proceed, we'll need some deeper linear algebra tricks; refer to 18.701 Notes for reference.
Lemma 2. The matrix diagonalizes as , where:
The matrix is orthogonal.
The matrix is diagonal with zeroes and ones.
Proof: Note that is a real symmetric matrix, so the Spectral theorem applies. This, alone, already guarantees us that is expressible in the form with orthogonal and diagonal.
It remains to study , or equivalently, to study the spectrum of . Recall that for the -dimensional subspace of , the map takes vectors in to their “altitudes” onto . Therefore,
Every vector along has eigenvalue zero.
Every vector along (the -dimensional subspace of vectors orthogonal to ) has eigenvalue one.
This implies the spectrum of contains zeroes and ones, proving the lemma's promise about .
Denote (that is, expressed in the eigenbasis of ). Using Lemma 2, we can rewrite like so:
Note that the step comes from the orthogonality of ; rotating via multiplication by does not change its magnitude. Now just one more lemma.
Lemma 3. We have and (the same moments as ). By corollary, for all .
Proof: The point is that is orthogonal, so , making the covariance unchanged.
By Lemma 3, taking expectations on both sides yields:
Exactly terms have , and the rest have , so the summation evaluates to , as promised.
With all that out of the way… we can now construct confidence intervals and perform hypothesis tests with .
Remark. Most of the time, these tests will ask for whether or for some particular entry of . This translates to asking whether the information communicated by the entry of a feature vector says anything about the response that the other entries do not already say.
§ Affine Linear Regression
Suppose I have a collection of data points on the coordinate plane, and I'd like to draw their line of best fit. In other words, I would like to find parameters for which .
This is not the same as a one-dimensional linear regression, as that would only produce a model . Fortunately, there's an easy adjustment we can make to linear regression to generalize it to affine models as well.
Idea. Pad every feature vector with an extra , extending it to . Then:
So drawing a line of best fit when the feature dimension is is secretly a two-dimensional linear regression, where the first entry of communicates the -intercept, and the second entry communicates the slope.
§ 1D Linear Regression and Correlation
Definition. Given one-dimensional data and , we may compute their sample variances and sample covariances like so:
Definition. The correlation coefficient between the and the is defined as .
It turns out that in the case of one-dimensional line-of-best-fit (or 2D linear regression), we have the following:
Theorem. (1D Linear Regression Slope) In a one-dimensional line-of-best-fit , we have .
Proof: Details omitted; the proof is just unenlightening computation.
Now let denote the value of predicted by the line-of-best-fit (in contrast to the true value ).
Theorem. (Correlation and Regression) We have that .
Proof: More computation; omitted.
And that's why AP Statistics makes you interpret the correlation coefficient by writing, “The constant represents the percent of the variation in the response that is explained by the linear relationship with the feature vector.”