# Linear regression problem: how do I prove that $\sum_{i=1}^{n}(Y_{i} - \hat{Y}_{i}) = 0$? [closed]

If $$\textbf{X}\in\textbf{R}^{n\times p}$$ has full rank and $$\textbf{Y}\in\textbf{R}^{n\times 1}$$, prove that \begin{align*} \sum_{i=1}^{n}(Y_{i} - \hat{Y}_{i}) = 0 \end{align*}

where $$\hat{\textbf{Y}}$$ is the fitted value of the linear model $$\textbf{Y} = \textbf{X}\beta + \textbf{e}$$, $$\textbf{e}\sim\mathcal{N}_{n}(\textbf{0},\sigma^{2}\textbf{I}_{n})$$. Precisely speaking, $$\hat{\textbf{Y}} = \textbf{X}\hat{\beta}$$ such that $$\textbf{X}^{\prime}\textbf{X}\hat{\beta} = \textbf{X}^{\prime}\textbf{Y}$$. Can someone help me? Thanks!

## closed as off-topic by Michael Chernick, kjetil b halvorsen, Peter Flom♦Mar 31 at 12:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Self-study questions (including textbook exercises, old exam papers, and homework) that seek to understand the concepts are welcome, but those that demand a solution need to indicate clearly at what step help or advice are needed. For help writing a good self-study question, please visit the meta pages." – Michael Chernick, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

• Hint: the first column of $\mathbf{X}$ is all $1$'s – Francis Mar 31 at 4:11
• Sorry, I still did not grasp the idea. Can you provide a full answer? – user1337 Mar 31 at 4:40
• Possible duplicate of Do these residuals sum to zero? – kjetil b halvorsen Mar 31 at 12:43

$$\newcommand{\X}{\mathbf{X}}\newcommand{\Y}{\mathbf{Y}}\newcommand{\bhat}{\hat{\beta}}\newcommand{\yhat}{\hat{\Y}}\newcommand{\0}{\mathbf{0}}$$We know that $$\X'\Y =\X'\X\bhat,$$ so rearranging this, we have $$\X'\left(\Y - \X\bhat\right) = \0,\quad \text{i.e.}\quad \X'\left(\Y - \yhat\right) =\0.$$ Looking at the first component of both sides, we get (since the top row of $$\X'$$ is all $$1$$'s) using the definition of matrix multiplication that $$\sum\limits_{i=1}^{n}1\cdot \left(Y_i - \hat{Y}_i\right)=0,$$ which is the desired result.