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

-

## 2 Answers

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$.

-

1
But note that the first formula is less prone to round-off error. – onestop Nov 12 '10 at 13:25
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 14, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9554784893989563, "perplexity_flag": "middle"}