I am trying to show that variance estimator $\frac{1}{n}\sum_{i=1}^{n}(X_i-\bar{X})^2$ is biased. I have an example in the book, and there is one step of this derivation I cannot understand:
$\frac{1}{n^2}E \left (\sum_{i=1}^{n}(X_i-\mu) \right)^2 = \frac{1}{n^2}E \left (\sum_{i=1}^{n}(X_i-\mu)^2+2\sum_{i=1}^{n-1}\sum_{j>i}(X_i-\mu)(X_j-\mu) \right )$
Where E is expected value, $\mu$ is population expected value, X is random variable.
Let’s get the clutter out of the way: let $x_i=X_i-\mu$, so that what you’re trying to show reduces to
$$\left(\sum_{i=1}^nx_i\right)^2=\sum_{i=1}^nx_i^2+2\sum_{i=1}^{n-1}\sum_{j>i}x_ix_j\;.\tag{1}$$
You’d probably see what’s going on if you took $n=4$, say, and wrote everything out longhand, without the summation notation, but let’s see if we can do it in general. Let $z=\sum_{i=1}^nx_i$. Then
$$\begin{align*} \left(\sum_{i=1}^nx_i\right)^2&=\left(\sum_{i=1}^nx_i\right)\left(\sum_{i=1}^nx_i\right)\\\\ &=\left(\sum_{i=1}^nx_i\right)z\\\\ &=\sum_{i=1}^nx_iz\\\\ &=\sum_{i=1}^n\left(x_i\sum_{j=1}^nx_j\right)\\\\ &=\sum_{i=1}^n\left(\sum_{j=1}^nx_ix_j\right)\\\\ &=\sum_{i=1}^n\sum_{j=1}^nx_ix_j\;. \end{align*}$$
In other words, the lefthand side of $(1)$ is just the sum of all possible products $x_ix_j$ as $i$ and $j$ range independently from $1$ through $n$.
These products can be naturally organized in a square array:
$$\begin{array}{cc} \color{red}{x_1x_1}&x_1x_2&x_1x_3&\dots&x_1x_n\\ x_2x_1&\color{red}{x_2x_2}&x_2x_3&\dots&x_2x_n\\ x_3x_1&x_3x_2&\color{red}{x_3x_3}&\dots&x_3x_n\\ \vdots&\vdots&\vdots&\color{red}{\ddots}&\vdots\\ x_nx_1&x_nx_2&x_nx_3&\dots&\color{red}{x_nx_n} \end{array}$$
The terms down the main diagonal are the ones of the form $x_ix_i=x_i^2$; their sum is
$$\sum_{i=1}^nx_i^2\;,$$
the first term on the righthand side of $(1)$. The products are symmetric across the main diagonal: if $1\le i<j\le n$, the product $x_ix_j$ is above the diagonal and is equal to the product $x_jx_i$ below the diagonal. Thus, the sum of the terms off the main diagonal is twice the sum of the terms above it. And that is simply the sum of all products $x_ix_j$ in which $i<j$, so it’s
$$\sum_{1\le i<j\le n}x_ix_j\;.$$
Break this up by the possible values of $i$: the largest row number that has an entry above the diagonal is $n-1$, so $i$ actually runs from $1$ to $n-1$, and for each $i$ we must have $j$ starting at $i$ and running across to column $n$. Thus, the sum of the elements above the diagonal is
$$\sum_{1\le i<j\le n}x_ix_j=\sum_{i=1}^{n-1}\sum_{j=i+1}^nx_ix_j\;,$$ written just a little sloppily as $$\sum_{i=1}^{n-1}\sum_{j>i}x_ix_j$$ in $(1)$.
Doubling that gives the total of the products off the diagonal, and $(1)$ is established.