From: "Alan Miller" Subject: Re: Simple standard deviation question Date: Fri, 23 Nov 2001 06:35:35 GMT Newsgroups: sci.math.num-analysis Summary: Adjusting mean/STD of dataset after update, downdate, swap Andrew Munn wrote in message <3c92884a.0111210650.3a2760a5@posting.google.com>... >I have a quick std.dev question. If you can't help me I hope you can direct >me to someone. > >I have a data set with a known number of elements and I know the standard >deviation of that set. I know the value of one of the elements in the set >and I want to replace that element with another element of known value and >I want to know the standard deviation of the new set. Can I determine the >new std.dev with this info? What if I also knew the mean of the original >set? I am trying to find a formula to accomplish this. If you could help >me out I'd greatly appreciate it. > >Thanks, >Andrew Munn Perhaps you should have asked this on one of the sci.stat newsgroups. Here are the algorithms for update, downdate & swap. They all apply to the mean and the sum of squares of deviations from the mean. get the standard deviation estimate by taking sqrt(sumsq/(n-1)), or if you want an unbiased estimate, use sqrt(sumsq/(n-1.5)). Update ---------- x is the new value. n = n + 1 dev = y - mean mean = mean + dev/n sumsq = sumsq + dev*(y - mean) Downdate -------------- x is the value being removed. n = n - 1 dev = x - mean mean = mean - dev/n sumsq = sumsq - dev*(x - mean) Swap ------- y is the new value to replace x. diff = y - x devx = x - mean mean = mean + diff/n sumsq = sumsq + diff*(devx + y - mean) Cheers -- Alan Miller (Honorary Research Fellow, CSIRO Mathematical & Information Sciences) http://www.ozemail.com.au/~milleraj http://users.bigpond.net.au/amiller/