# 24.1. Least Squares Linear Predictor#

In this section we are going to see if we can identify the best among all linear predictors of one numerical variable based on another, regardless of the joint distribution of the two variables.

For jointly distributed random variables \(X\) and \(Y\), you know that \(E(Y \mid X)\) is the least squares predictor of \(Y\) based on functions of \(X\). We will now *restrict the allowed functions to linear functions* and see if we can find the best among those. In later sections we will see the connection between this best linear predictor, the best among all predictors, and the bivariate normal distribution.

## See More

## 24.1.1. Minimizing Mean Squared Error#

Let \(h(X) = aX + b\) for constants \(a\) and \(b\), and let \(MSE(a, b)\) denote \(MSE(h)\).

To find the *least squares linear predictor*, we have to minimize this MSE over all \(a\) and \(b\). We will do this using calculus, in two steps:

Fix \(a\) and find the value \(b_a^*\) that minimizes \(MSE(a, b)\) for that fixed value of \(a\).

Then plug in the minimizing value \(b_a^*\) in place of \(b\) and minimize \(MSE(a, b_a^*)\) with respect to \(a\).

### 24.1.1.1. Step 1#

Fix \(a\) and minimize \(MSE(a, b)\) with respect to \(b\).

Differentiate this with respect to \(b\).

Set this equal to 0 and solve to see that the minimizing value of \(b\) for the fixed value of \(a\) is

### 24.1.1.2. Step 2#

Now we have to minimize the following function with respect to \(a\):

The derivative with respect to \(a\) is \(-2Cov(X, Y) + 2aVar(X)\). Thus the minimizing value of \(a\) is

At this point we should check that what we have is a minimum, not a maximum, but based on your experience with prediction you might just be willing to accept that we have a minimum. If you’re not, then differentiate again and look at the sign of the resulting function.

## 24.1.2. Slope and Intercept of the Regression Line#

The least squares straight line is called the *regression line*.You now have a proof of its equation, familiar to you from Data 8. Let \(r_{X,Y}\) be the correlation between \(X\) and \(Y\) and let \(\sigma_X\) and \(\sigma_Y\) be the standard deviations of \(X\) and \(Y\) respectively. As you know, \(r_{X,Y} = \frac{Cov(X,Y)}{\sigma_X\sigma_Y}\). So the slope and intercept are given by

## 24.1.3. Regression in Standard Units#

If both \(X\) and \(Y\) are measured in standard units, then the slope of the regression line is the correlation \(r_{X,Y}\) and the intercept is 0.

In other words, given that \(X = x\) standard units, the predicted value of \(Y\) is \(r_{X,Y}x\) standard units. When \(r_{X,Y}\) is positive but not 1, this result is called the *regression effect*: the predicted value of \(Y\) is closer to 0 than the given value of \(X\).

## 24.1.4. The Line and the Joint Distribution#

The calculations above show that *regardless of the joint distribution of \(X\) and \(Y\)*, that is, regardless of the relation between \(X\) and \(Y\),

The equation of the regression line holds.

The regression line goes through the point \((E(X), E(Y))\).

There is a unique best straight line predictor among all straight lines. If the relation between \(X\) and \(Y\) isn’t roughly linear then you won’t want to use the best straight line for predictions, because the best straight line is only the best among a bad class of predictors. But it exists.

## 24.1.5. The Regression Line for Data#

In Data 8, the setting for simple linear regression was that we had a deterministic set of points \(\{(x_i, y_i): 1 \le i \le n\}\) and we were using a line of the from \(y = ax+b\) as our predictor.

The equation of the regression line based on the data is a special case of the random variable calculations of this section. The mean squared error of the prediction is easily seen to be equal to \(MSE(a, b)\) as defined in this section for a randomly picked point:

for \((X, Y)\) picked uniformly at random from the set \(\{(x_i, y_i): 1 \le i \le n\}\).

We have already found the minimizing values of \(a\) and \(b\). The least-squares slope and intercept are

where the quantities on the right are calculated based on the uniform distribution. For example,

That’s the average of the \(y\)-values. The variance is

by plugging in \(E(Y) = \bar{y}\) and using the uniform distribution again. So also \(\sigma_X^2 = \frac{1}{n} \sum_{i=1}^n (x_i - \bar{x})^2\) and