Content deleted Content added
Dave.rudolf (talk | contribs) →Easiest online algorithm yet.: new section |
|||
Line 206:
: Btw, I don't understand your comment at the beginning since the problematic division is outside the loop. [[User:McKay|McKay]] ([[User talk:McKay|talk]]) 01:02, 10 April 2009 (UTC)
::: It should not say "else variance = 0". That implies the sample variance is 0 when ''n'' = 1. That is incorrect. The sample variance is undefined in that case. [[User:Michael Hardy|Michael Hardy]] ([[User talk:Michael Hardy|talk]]) 01:18, 10 April 2009 (UTC)
== Easiest online algorithm yet. ==
Hi all,
I was looking at Murray Spiegel's [http://www.amazon.com/Schaums-Outline-Probability-Statistics-Spiegel/dp/0071350047 Probability and Statistics] (1994), and it lists this formulation for variance:
<math>Var(X) = E[X^2]-(E[X])^2.</math>
[http://mathworld.wolfram.com/StandardDeviation.html Mathworld] had a similar formulation for standard deviation. This all means that, as long as you keep running tabs of:
- sum of all samples
- sum of squares of all samples
- number of samples
then you have an easy way to compute the variance as you go. You also have an easy way to combine the variances of two populations. Just add the sums (and sums of squares) and the counts. Bam! :)
|