In the picture below, the left side equation is the one my teacher wrote for sample SD, and the right side equation is the one I found online. Which is correct?
Which is the correct equation for estimating sample variance?
44 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail AtThere are 2 best solutions below
On
These are actually formulas for sample variance, not "sample SD" (standard deviation) as in the body of your text.
As pointed out by others. these formulas are the same. However, what they didn't tell you is that they are the same in exact arithmetic, i.e., in infinite precision.
In finite precision, as on a computer, the first listed formula can be very inaccurate, and in the extreme, but on actual realistic computations, can come out negative, which would be a theoretical impossibility if carried out in exact arithmetic.
People think the first formula is clever, and allows the sample variance to be calculated in one pass of the data, i.e., without first calculating the sample mean. But in doing so, it can be very inaccurate, especially if the mean is of large magnitude relative to the actual sample variance.
You can get the best of both worlds, however, by employing more sophisticated methods, which in effect, subtract off a running estimate of the mean as they go along, with appropriate factors introduced to make it come out right. This results in an algorithm in which non-negative numbers are always being added, rather than the catastrophic cancellation possible form the first formula in subtracting two large, almost equal numbers. See for instance https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm .

They are the same. \begin{align*} S^2 &= \dfrac{\sum_{i=1}^n (X_i - \overline{X})^2}{n-1} \\ &= \dfrac{\sum_{i=1}^n \left( X_i^2 - 2 X_i \overline{X} + \overline{X}^2 \right)}{n-1} \\ &= \dfrac{\sum_{i=1}^n X_i^2 }{n-1} -2 \overline{X}\dfrac{\sum_{i=1}^n X_i }{n-1} + \dfrac{\sum_{i=1}^n \overline{X}^2 }{n-1} \\ &= \dfrac{\sum_{i=1}^n X_i^2 }{n-1} -2 \overline{X}\dfrac{n \overline{X}}{n-1} + \dfrac{n \overline{X}^2 }{n-1} \\ &= \dfrac{\sum_{i=1}^n X_i^2 }{n-1} - \frac{n \overline{X}^2}{n-1} \\ &= \frac{\left( \sum_{i=1}^n X_i^2 \right) - n \overline{X}^2}{n-1} \end{align*}