I don't understand the following derivation:

$$ e_i = y_i - ax_i - b$$

$$ e_i = (y_i - \bar{y}) - a(x_i - \bar{x}) - (b - \bar{y} + a \bar{x}) $$

I don't really understand what they do and why they do it.

To clarify:

$e_i = y_i - \hat{y}_i$, where $ \hat{y}_i$ is the regression function I believe it's called.

  • $\begingroup$ What they do is clear: both rhs are indeed equal. Why they do it depends on what you are trying to prove. And you're the only one to know that. $\endgroup$
    – Julien
    Commented Mar 24, 2013 at 13:04
  • $\begingroup$ @julien Then my question reduces to: Why are they equal? $\endgroup$ Commented Mar 24, 2013 at 13:05
  • $\begingroup$ Oh wait, herp de derp. That's really simple. $\endgroup$ Commented Mar 24, 2013 at 13:05

2 Answers 2


Some of the notation is not fully standard, and in particular, you seem not to be distinguishing between the (unobservable) errors $e_i$ and the (observable) residuals $\hat e_i$.

The usual notation runs like this:

  • $\bar x =$ the average of $x_i$, $i=1,\ldots, n$
  • $\bar y =$ the average of $y_i$, $i=1,\ldots, n$
  • $y_i = ax_i+b+e_i$, where $e_i$ is the $i$th error. The values of $a$ and $b$ are unobservable because you see only the sample $(y_i,x_i)$, $i=1,\ldots,n$ and not the whole population, and $e_i$ is unobservable because $a$ and $b$ are unobservable.
  • $\hat a$ and $\hat b$ are the least-squares estimates of $a$ and $b$. The least-squares estimates are observable because you can compute them base on the sample $(y_i,x_i)$, $i=1,\ldots,n$. They satisfy $\bar y=a\bar x + b$, i.e. the least-squares line passes through the point that is the average of $(y_i,x_i)$, $i=1,\ldots,n$.
  • $\hat y_i = \hat a x_i + \hat b =$ the $i$th "fitted value".
  • $\hat e_i=y_i-\hat y_i=$ the $i$th residual, not to be confused with the $i$th error. The residuals $\hat e_i$ are observable whereas the errors $e_i$ are not. The residuals necsessarily satisfy the two linear constraints $\hat e_1+\cdots+\hat e_n=0$ and $x_1 \hat e_1+\cdots + x_n \hat e_n=0$, whereas the errors, on the other hand, are often taken to be independent.
  • The "regression function" is $x\mapsto y=ax+b$, whereas the fitted value $\hat y_i$ is the value of the regression function when the input is $x_i$.
  • $\begingroup$ Hmm, I directly copied this from the sheets I was handed at school. The sheets don't seem too professional and $\hat{e}_i$ isn't mentioned anywhere. What you're saying does make sense though, I need to watch out. $\endgroup$ Commented Mar 24, 2013 at 13:34
  • $\begingroup$ What sort of course are you taking and who's teaching it? $\endgroup$ Commented Mar 24, 2013 at 13:36
  • $\begingroup$ Well, I don't like to be an ass but it is an accelerated math class for which students are handpicked. The teacher is our most competent high school math teacher, but I think it's safe to say everybody in that class is smarter than him. He usually prints parts of free university courses and hands them out. This semester it was about linear algebra, linear regression and linear programming. I knew linear algebra from self-studying quantum mechanics, and the other 2 bored me, so I'm ashamed to say I slacked this entire semester, so now I'm catching up. Tl;dr - the class s*cks. $\endgroup$ Commented Mar 24, 2013 at 13:45
  • $\begingroup$ It seems I am guilty of an "error". In one of the bullet points I wrote "where $e_i$ is the $i$th residual". I should of course have written "where $e_i$ is the $i$th error". $\endgroup$ Commented Mar 25, 2013 at 21:54

Sorry people, I asked to soon:

$$ e_i = (y_i - \bar{y}) - a(x_i - \bar{x}) - (b - \bar{y} + a \bar{x}) = y_i - \bar{y} - ax_i + a\bar{x} - b + \bar{y} - a\bar{x} = y_i - ax_i - b$$

They just want to rewrite it to $$ e_i = (y_i - \bar{y}) - a(x_i - \bar{x}) - (b - \bar{y} + a \bar{x}) $$ because that is per definition $$ v_i - au_i - (b - \bar{y} + a\bar{x})$$ and that simpler expression will help with finding the regression line.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .