In a Coursera lecture on multi-variable linear regression with three variables, the professor shows that the sum of the residuals for y* residuals for x) / sum residuals x^2 equals the coefficient for y regressed on x.
Can someone explains why this is so? The relevant code used is below:
$ > n = 100; x = rnorm(n); x2 = rnorm(n); x3 = rnorm(n)
2 ## Generate the data
3 > y = 1 + x + x2 + x3 + rnorm(n, sd = .1)
4 ## Get the residuals having removed X2 and X3 from X1 and Y
5 > ey = resid(lm(y ~ x2 + x3))
6 > ex = resid(lm(x ~ x2 + x3))
7 ## Fit regression through the origin with the residuals
8 > sum(ey * ex) / sum(ex ^ 2)
9 [1] 1.009
10 ## Double check with lm
11 > coef(lm(ey ~ ex - 1))
12 ex
13 1.009
14 ## Fit the full linear model to show that it agrees
15 coef(lm(y ~ x + x2 + x3))
16 (Intercept) x x2 x3
17 1.0202 1.0090 0.9787 1.0064 $