| advertise add site services publishers database health videos | ![]() | about toolbar stats live show health store more stuff JOIN/LOGIN |
Talking Watch, Talking Watches, Talking Clock, Talking Bible, Talking... independentliving.com | Digital Radiographic Assessment of Tibiofemoral Joint Space Width: A... orthosupersite.com |
Editorial comment: it is actually the first formula that has precision problems when dealing with limited-precision arithmetic. If the difference between measurements and the mean is very small, then the first formula will yield precision problems, as information will be lost in the (xi - µ) operation. There is no such loss of significance in the intermediate operations of the second formula. -- ScottMoonen Editorial comment the second: in fact, the second formula is the one more commonly beset with problems. The first can have problems when the mean is very large relative to the variance, but this is relatively rare in practice and this problem also affects the second formula. Much more common is the situation where you have comparable mean and variance and a very large number of observations. In this case, the second formula will result in the subtraction of two very large numbers whose difference is relatively small (by a factor roughly equal to the number of observations). If you have one million observations, you lose roughly six significant figures with the second formula if you use ordinary floating point arithmetic. -- TedDunning comment: The problem may occur
To be precise we have to specify the instrument and the nature of the data. -- DickBeldin Ted, what do you mean by ordinary floating point arithmetic? Are talking about precision with repsect to register width, or is there an implicit reference to some "non-ordinary" scheme, that is, non-IEEE? Thanks. I thought the reference was pretty explicit. I didn't mean, however, to imply the use of non-standard but still floating point arithmetic. I had in mind systems that were entirely different. A simple example is a system that uses rationals based on unlimited precision integers. Another system might be fixed point arithmetic. The first would not lose precision in the computation while the second would lose more or less precision than I quote depending on the values in question and the characteristics of the fixed point system. You could also imagine an optimizer that noted that you might be adding up large numbers of very small numbers and would re-order the addition to avoid most of the round-off errro by using log N temporary values to perform the addition. -- TedDunning FWIW my favorite variance algorithm is the 'corrected two pass algorithm' of Chan, Golub, Leveque (American Statistician, 1983, page 242): avg=0 for all i avg=avg+data[i] end for avg=avg/n sum=0 sum2=0 for all i sum2=sum2+(data[i]-avg)^2 sum=sum+(data[i]-avg) end for var=(sum2-sum/n)/(n-1) return var AlexC
I removed the following comments from the article as they do not belong there. I have posted them here so that somebody may investigat them further. It would be nice if users use the talk page for comments and not the article. --Richss 16:12, Nov 11, 2004 (UTC)
--- I had a look at the source for AlexCs algorithm. I believe there is a mistake: var=(sum2-sum/n)/(n-1) should read var=(sum2-sum*sum/n)/(n-1) The result of this algorithm agrees with my graphic calculator. I think the corrected algorithm should be added to the page -- aj504@york.ac.uk who still hasn't got a wikipedia account :)
[edit] Incorrect Algorithm?The second algorithm doesn't look right to me. At each step it's calculating the variance of data[i] with respect to the *average so far*, not the true average. Can someone confirm that I'm not just reading it wrong? I have derived and added the update formulas (only the results) for the unbiased/biased variance. The clearly shown that the (old) second algorithm which was in dispute was wrong, so I removed it. I have also removed the example which just shows some numbers (was it a weak numerical proof?) and does not provide any insight on how the formulas work. It was not clear whether the algorithms were for biased or unbiased estimators, so I added comments on it. BurkayDonderici [edit] Algorithm III does not computeHi, In the mathematical equation for m(new), I don't agree with (n+1) in the denominator. I believe that the denominator should be simply (n). I didn't want to edit the entry since I am not a mathematician. CAN SOMEONE WHO IS PLEASE MAKE THE APPROPRIATE COMMENTS .
Methods 1 and 2 produced the same results all the way through the population and matched Method 4's result for the whole population. However, Method 3 always produced a lower result, and the error (which started significatly) reduced as the number of samples grew. Regards, Napoleon BlownApart [edit] Algorithm IIII'm pretty sure this is wrong. From Welford's Paper: S[n]=S[n-1]+(n-1)/n*(x[n]-mean[n-1])^2 --cfp 21:58, 15 August 2006 (UTC)
[edit] Online algorithmI removed the line about Knuth/Welford being on online algorithm. All the algorithms in this article are online algorithms, it's not worth noting. —johndburger 12:24, 18 September 2007 (UTC)
[edit] Algorithm IVDoesn't the final step in West's algorithm have a typo? Instead of:
Shouldn't it actually be:
Looking at West's paper, he has "mathematical description" and "computational description" side by side. The math for the final line looks like: Shauncutts (talk) 06:15, 29 January 2008 (UTC)
n = 0 foreach x in the data: if n=0 then n = 1 mean = x S = 0 sumweight = weight else n = n + 1 temp = weight + sumweight Q = x-mean R = Q*weight/temp S = S + sumweight*R*Q mean = mean + R sumweight = temp end if end for Variance = S * n / ((n-1) * sumweight) // if sample is the population, omit n/(n-1) Gorm (talk) 12:54, 19 February 2008 (UTC)
[edit] Minor spelling and grammar fixesOSFTactical (talk) 22:59, 6 December 2007 (UTC) [edit] Suspecting a formulea errorOn 17/11/2007 Hi, I suspect that the two end formulaes given for the third algorithm : variance_n = sqrt(M2/n) variance = sqrt(M2/(n - 1)) are not the "variance" but the "standard deviation" (Ecart-type in French) Can someone check it ? Pascal P. 90.37.121.130 (talk) 13:52, 17 November 2008 (UTC) [edit] Division by zero problem?The online algorithm should work with n=1 since it needs to progress through that stage to get to n=2, n=3, etc. Therefore, it would be incorrect to calculate the variance as variance = M2 / (n-1) A possible fix is: if n > 1 then variance = M2 / (n-1) else variance = 0 end if Does any one have any objections to me updating this? JBrusey (talk) 14:06, 9 April 2009 (UTC)
if n > 1 then variance = M2 / (n-1) else variance = undefined end if
[edit] Easiest online algorithm yet.Hi all, I was looking at Murray Spiegel's Probability and Statistics (1994), and it lists this formulation for variance: Var(X) = E[X2] − (E[X])2. 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. No divide-by-zeros. Very few math operations. What more can you ask for? :)
[edit] PseudocodeThe numerically stable mean and variance computation works, but attempting something similar for skewness and kurtosis using the incremental moments computation code in the later section seems to fail. Is something missing in it ? Are there any reference implementations ? Shyamal (talk) 16:17, 14 July 2009 (UTC) | ||||||||||||||||||||||||||||||||
| ↑ top of page ↑ | about thumbshots |