CITIDEL >
Planet Math Computer Science >
Planet Math Computer Science Collection >
Please use this identifier to cite or link to this item:
http://hdl.handle.net/10117/1294

Title:  onepass algorithm to compute sample variance 
Issue Date:  11Apr2007 
Publisher:  PlanetMath 
Citation:  http://planetmath.org/encyclopedia/OnePassAlgorithmToComputeSampleVariance.html 
Abstract:  ive formula for calculating the sample variance in one pass, ... suffers from computational roundoff error. If the mean xb is large in absolute value, and ... is close to ... , then the subtraction at the end will tend to lose significant digits on the result. Also, in rare cases, the sum of squares ... can overflow on a computer. A better alternative, though requiring more work per iteration, is to calculate the running sample mean and variance instead, and update these as each datum is processed. Here we give the derivation of the onepass algorithm  which involves nothing more than simple algebraic manipulations. Define the running arithmetic mean and the sum of squared residuals: ... We want to express ... and ... in terms of the old values ... and ... . For convenience, let ... and ... . Then we have ... For the variance calculation, we have ... Now observe: ... hence we obtain: ... Note that the number to be added to ... is never negative, so no cancellation error will occur from this procedure. (However, there can still be computational roundoff error if ... happens to be very small compared to ... .) ... The recurrence relation for the sample covariance of two lists of numbers ... and ... can be derived similarly. If ... and ... denote the arithmetic means of first 
URI:  http://www.citidel.org/handle/10117/1294 
Appears in Collections:  Planet Math Computer Science Collection

Files in This Item:
File 
Size  Format 
OnePassAlgorithmToComputeSampleVariance.html  32Kb  HTML  View/Open 

All items in DSpace are protected by copyright, with all rights reserved.
