Algebraic manipulation question coming from Method of Moments application So today in my statistical inference class the professor wrote on the board:
Using the Method of Moments:
$$\sigma^2 = E[Y_1^2|\theta] - E[Y_1|\theta]^2$$
$$= \frac{1}{n}\sum_{j = 1}^{n}{Y_j^2} - \left( \frac{1}{n}\sum_{j = 1}^{n}{Y_j}\right)^2$$
$$= \frac{1}{n}\sum_{j = 1}^{n}{\left( Y_j - \bar{Y}\right)^2 }$$
where $\bar{Y} = \frac{1}{n}\sum_{j = 1}^{n}Y_j$(average values of Y's)
I am confused at how he arrived at the last equation from the one above that and I've been trying to figure it out.
Here's what I have so far:
$$= \frac{1}{n}\sum_{j = 1}^{n}{Y_j^2} - \left( \frac{1}{n}\sum_{j = 1}^{n}{Y_j}\right)^2$$
$$ = \frac{1}{n}\sum_{j = 1}^{n}{Y_j^2} - \frac{1}{n^2}\left(n\bar Y\right)^2$$
$$ = \frac{1}{n}\sum_{j = 1}^{n}{Y_j^2} - \bar Y^2$$
Which is fundamentally different that the equation that my professor had on the board. My equation takes the difference of squares while his takes the square of a difference and then sums those up...
Where did I go so wrong? Is there just some statistical insight that I don't know and haven't used?
 A: Perhaps it's easier to go the other way around. Let $S^2$ be the sample variance and note
\begin{align*}
S^2 &= \frac{1}{n}\sum_{j=1}^n(Y_j-\bar Y)^2 \\
&= \frac{1}{n}\sum_{j=1}^n(Y_j^2-2\bar Y Y_j + \bar Y^2)\\
&= \frac{1}{n}\left(\sum_{j=1}^nY_j^2-2\bar Y \left(\sum_{j=1}^n Y_j\right) + n\bar Y^2\right)\\
&= \frac{1}{n}\left(\sum_{j=1}^nY_j^2-2\bar Y (n \bar Y) + n\bar Y^2\right)\\
& = \frac{1}{n}\sum_{j=1}^nY_j^2 - \bar Y^2.
\end{align*}
Essentially the Method of Moments here is suggesting to estimate $\sigma^2$ by $S^2$, where the two population moments $E(Y_1^2|\theta),E(Y_1|\theta)$ are replaced by the corresponding sample moments.
A: Let's define $c:=\bar{Y}=\frac{1}{n}\sum_{j=1}^nY_j$. As already mentioned in the comments, it holds $\sum_{j=1}c=nc$ for a constant $c\in\mathbb{R}$.
It is easy to see, that
$$
\begin{aligned}
\left( Y_j - \bar{Y}\right)^2&=Y_j^2-2\bar{Y}Y_j+\bar{Y}^2=Y_j^2-2cY_j+c^2\\
\end{aligned}$$
From this, one finds
$$
\begin{aligned}
\sum_{j=1}^n\left( Y_j - \bar{Y}\right)^2&=\sum_{j=1}^nY_j^2-2c\sum_{j=1}^nY_j+\sum_{j=1}^n c^2\\
&=\sum_{j=1}^nY_j^2-2c(nc)+nc^2\\
&=\sum_{j=1}^nY_j^2 -nc^2.\\
\end{aligned}$$
This implies
$$
\begin{aligned}
\frac{1}{n}\sum_{j=1}^n\left( Y_j - \bar{Y}\right)^2
&=\left(\frac{1}{n}\sum_{j=1}^nY_j^2 \right) -c^2\\
&=\left(\frac{1}{n}\sum_{j=1}^nY_j^2 \right) -\left(\frac{1}{n}\sum_{j=1}^n Y_j \right)^2.\\
\end{aligned}$$
However, it is also true, that
$$
\begin{aligned}
\sum_{j=1}^n\left( Y_j - \bar{Y}\right)^2&=\sum_{j=1}^nY_j^2 -nc^2\\
&=\sum_{j=1}^nY_j^2 -\sum_{j=1}^nc^2\\
&=\sum_{j=1}^nY_j^2 -\sum_{j=1}^n\bar{Y}^2\\
&= \sum_{j=1}^n(Y_j^2-\bar{Y}^2),
\end{aligned}$$
such that
$$
\begin{aligned}
\frac{1}{n}\sum_{j=1}^n\left( Y_j - \bar{Y}\right)^2&= \frac{1}{n}\sum_{j=1}^n(Y_j^2-\bar{Y}^2).
\end{aligned}$$
