# 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!

• Hint: the first column of $\mathbf{X}$ is all $1$'s Mar 31, 2019 at 4:11
• Sorry, I still did not grasp the idea. Can you provide a full answer?
– user242554
Mar 31, 2019 at 4:40
• Possible duplicate of Do these residuals sum to zero? Mar 31, 2019 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.