# Sum of squares two ways, how are they connected?

The standard sum of squares as I know it is:

Σ (X-m)2

where m is the mean. I ran into a different one which can be written two ways:

Σ(X2) - (ΣX)2/n = Σ(X2) - m ΣX

I believe the latter is called the "correction term for the mean" (e.g. here). My algebra seems to be inadequate to show these are equivalent, so I was looking for a derivation. Thanks.

-

Expanding the square we get:

$\sum_i(X_i-m)^2 = \sum_i(X_i^2 + m^2 - 2 X_i m)$

Thus,

$\sum_i(X_i-m)^2 = \sum_i{X_i^2} + \sum_i{m^2} - 2 \sum_i{X_i m}$

Since $m$ is a constant, we have:

$\sum_i(X_i-m)^2 = \sum_i{X_i^2} + n m^2 - 2 m \sum_i{X_i}$

But,

$\sum_i{X_i} = n m$.

Thus,

$\sum_i(X_i-m)^2 = \sum_i{X_i^2} + n m^2 - 2 n m^2$

Which on simplifying gets us:

$\sum_i(X_i-m)^2 = \sum_i{X_i^2} - n m^2$

Thus, we get can rewrite the rhs of the above in two ways:

$\sum_i{X_i^2} - m (n m) = \sum_i{X_i^2} - m \sum_i{X_i}$

(as $n m = \sum_i{X_i}$)

and

$\sum_i{X_i^2} - n (m)^2 = \sum_i{X_i^2} - \frac{(\sum_i{X_i})^2}{n}$

(as $m = \frac{\sum_i{X_i}}{n}$)

-
Thanks. Very pretty. –  telliott99 Nov 11 '10 at 15:29
Although the formula are equal, the practical difference is ease-of-calculation if you're doing it by hand. If all I had was a piece of paper and a pencil, I'd prefer the second formula--- $\sum X^2$ and $\sum X$ together take less time and are less error prone to calculate than $\sum (X - m)^2$.