I'm trying to understand the gap statistic used for optimal choice of $k$ in k-means clustering. I'm trying to understand part of the explanation which includes this equality:
$D_k=\sum_{ij}\Vert x_i-x_j\Vert^2=2n\sum_{i}\Vert x_i-\mu\Vert^2$
Where $\sum_{ij}\Vert x_i-x_j\Vert^2$ is the sum of pairwise distances in a cluster and $\mu$ is the centroid for that cluster. I don't understand how that is derived.
I've had a look at this question (Link between variance and pairwise distances within a variable) and the answer makes sense to me.
Assuming our data is centered about the (known) mean, which it is, by definition of the centroid, then the equality holds:
$\sum_{ij}(X_i-X_j)^2=2\sum X_i^2$
But I don't see how $2\sum X_i^2 = 2n\sum_{i}\Vert x_i-\mu\Vert^2$
If $2\sum X_i^2 = 2\operatorname{Var}(X)$
Then wouldn't $2\sum X_i^2 = \frac{2}{n}\sum_i(x_i-\mu)^2$?