For such an online algorithm, a recurrence relation is required between quantities from which the required statistics can be calculated in a numerically stable fashion.
The following formulas can be used to update the mean and (estimated) variance of the sequence, for an additional element x This algorithm is much less prone to loss of precision due to catastrophic cancellation, but might not be as efficient because of the division operation inside the loop.
A relative histogram of a random variable can be constructed in the conventional way: the range of potential values is divided into bins and the number of occurrences within each bin are counted and plotted such that the area of each rectangle equals the portion of the sample values within that bin: is an analytical methodology to combine statistical moments from individual segments of a time-history such that the resulting overall moments are those of the complete time-history.
Communications of ACM, 22(9), 532-535, 1979 [Zhang2007] Q. SSDBM, p.29, 19th International Conference on Scientific and Statistical Database Management (SSDBM 2007), 2007.
Zamar, Robust Multivariate Estimates for High-Dimensional Datasets.
Rebonato and P Jackel, The most general methodology to create a valid correlation matrix for risk management and option pricing purposes, Quantitative Research Centre of the Nat West Group, October, 1999. The Annals of Statistics, 24(3), 1327-1345, 1996 [Rubin1987] D.
The algorithm can be extended to handle unequal sample weights, replacing the simple counter n with the sum of weights seen so far.
West (1979) Assume that all floating point operations use the standard IEEE 754 double-precision arithmetic.