# How to calculate the specific Standard Error relevant for a specific point estimate within a linear regression?

My objective is to actually get to the Standard Error for every point estimate of a linear regression. I originally thought that the Standard Error of a linear regression model was constant. And, that it was simply equal to the square root of the Mean Squared Deviation of the residual. That's why the model's Standard Error is also referred to as the RMSE.

I now understand that when you construct a Confidence Interval around the trendline of estimates... at each point estimate, the applicable Standard Error is different from the overall model's Standard Error or RMSE as described above.

The first part of my question, is how do you calculate this specific Standard Error at a specific point estimate? Could one provide a link to a numerical example to facilitate my interpretation of the formula?

I understand that such Standard Errors have a predictable pattern. They are much lower than the model's overall Standard Error for values fairly close to the Mean value. And, they are larger from the same model's Standard Error as you go further away from the Mean value. As a result, Confidence Intervals are not parallel to the regression trendline. Instead, they curve like an hourglass shape.

My second part to this overall question is: How come the resulting hourglass shape of the resulting Confidence Interval as depicted does not break the linear regression assumption that the variance of residuals remain constant across observations (the heteroskedasticity thing)?

The first part of my question, is how do you calculate this specific Standard Error at a specific point estimate?

You don't specify if you mean simple linear or multiple regression. I'll assume the general case. Let's do it at a point $x^* = (1,x_1^*,x_2^*,...,x_p^*)$

$$\text{Var}(\hat y^*) = \text{Var}(x^*\hat\beta)= \text{Var}(x^*(X^TX)^{-1}X^T y)$$

$$= x^*(X^TX)^{-1}X^T \text{Var}(y) X(X^TX)^{-1}x^{*T}$$ $$= \sigma^2 x^*(X^TX)^{-1}X' I X(X^TX)^{-1}x^{*T}$$ $$= \sigma^2 x^*(X^TX)^{-1}x^{*T}$$

If $h^*_{ii} = [x^*(X^TX)^{-1}x^{*T}]_{ii}$ then $\text{Var}(\hat y_i) = \sigma^2 h^*_{ii}$.

Of course, $\sigma^2$ is unknown and must be estimated.

The standard error is the square root of that estimated variance up above.

Could one provide a link to a numerical example to facilitate my interpretation of the formula?

I'll try to dig one up.

My second part to this overall question is: How come the resulting hourglass shape of the resulting Confidence Interval as depicted does not break the linear regression assumption that the variance of residuals remain constant across observations (the heteroskedasticity thing)?

1) it's a confidence interval for where the mean is, not the variance of the data; it reflects our uncertainty in the parameters as they feed through (via the design, $X$) to the the estimate of the mean. Something assumed true for one thing not being true for a different thing doesn't violate the assumption for the first thing.

2) Your statement "the linear regression assumption that the variance of residuals remain constant across observations" is factually incorrect (though I know what you're getting at). That is not an assumption of regression - in fact, outside specific cases, it's untrue for regression. What is assumed constant is the variance of the unobserved errors. The variance of the residuals is not constant. In fact it 'bows in' in opposite fashion to the way the variance above 'bows out', both due to the phenomenon of leverage.

Edits in response to followup questions:

Why would the variance bow in?

I'll do it algebraically and then expand on the explanation in the text above:

\begin{eqnarray} \text{Var}(y-\hat y) &=& \text{Var}(y) + \text{Var}(\hat y) - 2 \text{Cov}(y,\hat y)\\ &=&\sigma^2 I + \text{Var}(X \hat \beta) - 2 \text{Cov}(y,X \hat \beta)\\ &=&\sigma^2 I + \text{Var}(X (X^TX)^{-1}X^T y) - 2 \text{Cov}(y,X (X^TX)^{-1}X^T y)\\ &=&\sigma^2 I + X (X^TX)^{-1}X^T\text{Var}(y) X (X^TX)^{-1}X^T - 2 \text{Cov}(y, y)X (X^TX)^{-1}X^T\\ &=&\sigma^2 I + X (X^TX)^{-1}X^T(\sigma^2 I) X (X^TX)^{-1}X^T - 2 \sigma^2 I X (X^TX)^{-1}X^T\\ &=&\sigma^2 I + \sigma^2 X (X^TX)^{-1}X^T X (X^TX)^{-1}X^T - 2 \sigma^2 I X (X^TX)^{-1}X^T\\ &=&\sigma^2 I + \sigma^2 X (X^TX)^{-1}X^T - 2 \sigma^2 X (X^TX)^{-1}X^T\\ &=&\sigma^2 [I + X (X^TX)^{-1}X^T - 2 X (X^TX)^{-1}X^T]\\ &=&\sigma^2 [I - X (X^TX)^{-1}X^T]\\ &=& \sigma^2(I-H) \end{eqnarray}

where $H = X(X^TX)^{-1}X^T$. Therefore the variance of the $i^{\tt{th}}$ residual is $\sigma^2(1-h_{ii})$ where $h_{ii}$ is $H(i,i)$ (some texts will write that as $h_i$ instead).

As you see, it's smaller, when $h$ is larger... which is when the pattern of $x$-values is further from the center of the $x$'s. In simple regression $h$ is larger when $(x-\bar x)$ is larger.

Now as to why, note that $\hat y = Hy$ ($H$ is called the hat-matrix for this reason).

That is, the fit at the $i^{\tt{th}}$ observation responds to movements in $y_i$ in proportion to $h_{ii}$, or $\frac{\partial \hat{y}_i}{\partial y_i} = h_{ii}$. So when $h$ is larger, $y$ pulls the line more toward itself, making its residual smaller.

There's a more intuitive discussion in the context of simple linear regression here that may help motivate it for you.

I interpret that as large errors near the Mean with smaller errors away from the Mean.

No, we're not discussing errors, they have constant variance. We're discussing residuals. They are not the errors and don't have constant variance; they're related but different.

The bit of material I have read on the subject, suggests just the opposite...

Can you point me to something that does this? Recall that we're discussing the residual variability here.

Additionally, how would you define heteroskedasticity?

Having non-constant variance. That is, when the regression assumption about the variance being constant doesn't hold, you have heteroskedasticity.

See Wikipedia: http://en.wikipedia.org/wiki/Heteroscedasticity

And, what do you mean by the variance of unobserved errors?

You don't observe the errors, but the model assumes they have constant variance, $\sigma^2$. The "variance of unobserved errors" is thus simply "$\sigma^2$".

How can you measure those since they are unobserved?

Individually, you can't, at least not very well. You can roughly estimate them by the residuals, but they don't even have the same variance, as we saw. However, you can estimate their variance reasonably well from the residuals, if you appropriately adjust for the fact that the residuals are on average smaller than the errors.

• Glen b, thanks for a very informative answer. I am not sure if I understand your comments under 2). Why would variance bows in? I interpret that as large errors near the Mean with smaller errors away from the Mean. The bit of material I have read on the subject, suggests just the opposite... the bows out thing hourglass shape. Additionally, how would you define heteroskedasticity? And, what do you mean by the variance of unobserved errors? How can you measure those since they are unobserved? – Sympa Aug 16 '13 at 16:41