Bernie Cosell, All you need to do is compute on the fly the sum of squares S = x[1]^2 + ... + x[n]^2 of the empirical values, as well as the sum of values T = x[1] + ... + x[n]. The mean M = T/n, and the variance V = ((x[1] - M)^2 + (x[n] - M)^2)/(n-1). The SD is the square root of V. If you expand the terms in the equation for V, you get V = (S -2*M*T + n*M^2)/(n-1) = (S - n*M^2)/(n-1), which you can compute in one pass. On Thursday, Jul 10, 2003, at 09:20 America/Denver, Bernie Cosell wrote:
I thought *SURE* I knew an algorithm once, long ago, for calculating the SD "on the fly", but I can't remember any details of any such trickery and a quick Google search only came up with algorithms that I already know and that start with the obvious "calculate the mean..." Basically, I have a largish data set that it will only be convenient to read once and I'd like to be able to calculate [or at least estimate] the SD as the data comes by and avoid having to scroll it into a temp file and then do a second pass over the data from the temp file... Is there such an algorithm or am I just misremembering?
Thanks!
/Bernie\
-- Bernie Cosell Fantasy Farm Fibers mailto:bernie@fantasyfarm.com Pearisburg, VA --> Too many people, too few sheep <--
_______________________________________________ math-fun mailing list math-fun@mailman.xmission.com http://mailman.xmission.com/cgi-bin/mailman/listinfo/math-fun