# How to compute sample variance from sample moments

Given $X_1, \dots , X_n$ i.i.d. and the two sample moments $$M_1 = \frac{1}{n} \sum_{i = 1}^{n} X_i = \bar{X}$$ and $$M_2 = \frac{1}{n} \sum_{i = 1}^{n} X_i^2$$ how can I compute: $$S^2 = \frac{1}{n} \sum_{i = 1}^{n} (X_i - \bar{X})^2$$ such as: $$S^2 = f(M_1, M_2)$$

Thank you.

-
Hint: This has nothing to do with statistics and could have been tagged (algebra) or (polynomials). –  Did Jun 13 '12 at 11:13
ok, got it. Thank you did. –  Aslan986 Jun 13 '12 at 11:21
This has to do with statistics in that the derived formula is commonly used for computing the variance estiamte. –  Michael Chernick Jun 13 '12 at 18:34

$S^2 = \frac{1}{n}\sum_{i=1}^n (X_i - M_1)^2 = \frac{1}{n}\sum_{i=1}^n (X_i^2 - 2 X_i M_1 + M_1^2) =$
$= \frac{1}{n}\sum_{i=1}^n X_i^2 - 2 M_1 \frac{1}{n}\sum_{i=1}^n X_i + \frac{1}{n}\sum_{i=1}^n M_1^2 =$
$= M_2 - 2M_1^2 + M_1^2 = M_2 - M_1^2$