One definition of the Residual Sum of Squares is:
$$ S_r = (y-X\hat{\beta})^T(y-X\hat{\beta}) $$
And I think I understand it.
Now I have seen a different definition:
$$ S_r = y^Ty- \hat{\beta}^TX^TX\hat{\beta} $$
I think they supposed to be equal but I can't see why.
I can write (I leave out the \hat on $\beta$ to make the typing easier):
$$ \begin{aligned} S_r &= y^T(y-X\beta) - \beta^TX^T(y-X\beta)\\ &= y^Ty - y^TX\beta - \beta^TX^T y + \beta^TX^TX\beta \end{aligned} $$
and then to make both equations equal I would need to see that $\beta^TX^TX\beta = \beta^TX^T y$ which I don't.
How, do you show that the equations are equal?
n <- 10; x <- seq(-2, 2, length.out=n); beta <- c(1,-2); y <- beta[1] + beta[2]*x + rnorm(n); fit <- lm(y ~ x); Sr.1 <- sum(resid(fit)^2); Sr.2 <- sum(y^2) - sum(predict(fit)^2); print(c(RSS.1=Sr.1, RSS.2=Sr.2))
This is just the Pythagorean Theorem: the first formula is the square of one leg of a right triangle while the second formula subtracts the square of the other leg from the square of the hypotenuse. $\endgroup$