# Updating mean and variance estimates an improved method

Next consider the sample (1016), which gives rise to the same estimated variance as the first sample."Two-pass" algorithm computes this variance estimate correctly, but "Naïve" algorithm returns 29.333333333333332 instead of 30.The normalization value could be 0 or even negative. All three of them seem to "survive" the sanity check of setting all $\omega_i=1$. ''Update:'' whuber suggested to also do the sanity check with $\omega_1=\omega_2=.5$ and all remaining $\omega_i=\epsilon$ tiny. I went through the math and ended up with variant C: $$Var(X) = \frac\overline V$$ where $\overline V$ is the non corrected variance estimation.But how about B) ($n$ is the number of observations) - is this the correct approach? I belive "Updating mean and variance estimates: an improved method", D. The formula agrees with the unweighted case when all $\omega_i$ are identical.This is a serious problem with "Naïve" algorithm and is due to catastrophic cancellation in the subtraction of two similar numbers at the final stage of the algorithm.Terriberry, only one division operation is needed and the higher-order statistics can thus be calculated for little incremental cost.

The reason why C is necessarily biased is because if you don't use "repeat"-type weights, you lose the ability to count the total number of observations (sample size), and thus you can't use a correction factor.One benefit is that the statistical moment calculations can be carried out to arbitrary accuracy such that the computations can be tuned to the precision of, e.g., the data storage format or the original measurement hardware.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.The parallel algorithm below illustrates how to merge multiple sets of statistics calculated online.The algorithm can be extended to handle unequal sample weights, replacing the simple counter n with the sum of weights seen so far.For unweighted variance $$\text(X):=\frac\sum_i(x_i - \mu)^2$$ there exists the bias corrected sample variance, when the mean was estimated from the same data: $$\text(X):=\frac\sum_i(x_i - E[X])^2$$ I'm looking into weighted mean and variance, and wondering what the appropriate bias correction for the weighted variance is.Using: $$\text(X):=\frac\sum_i \omega_i x_i$$ The "naive", non-corrected variance I'm using is this: $$\text(X):=\frac\sum_i\omega_i(x_i - \text(X))^2$$ So I'm wondering whether the correct way of correcting bias is A) $$\text(X):=\frac\sum_i\omega_i(x_i - \text(X))^2$$ or B) $$\text(X):=\frac\frac\sum_i\omega_i(x_i - \text(X))^2$$ or C) $$\text(X):=\frac\sum_i\omega_i(x_i - \text(X))^2$$ A) does not make sense to me when the weights are small. The third, C) is my interpretation of the answer to this question: https://mathoverflow.net/questions/22203/unbiased-estimate-of-the-variance-of-an-unnormalised-weighted-mean For C) I have just realized that the denominator looks a lot like $\text(\Omega)$. I think it does not entirely align; and obviously there is the connection that we are trying to compute the variance...While this loss of precision may be tolerable and viewed as a minor flaw of "Naïve" algorithm, it is easy to find data that reveal a major flaw in the naive algorithm: Take the sample to be (1016).Again the estimated population variance of 30 is computed correctly by "Two-pass"" algorithm, but "Naïve" algorithm now computes it as −170.66666666666666.West (1979) Assume that all floating point operations use the standard IEEE 754 double-precision arithmetic.Consider the sample (4, 7, 13, 16) from an infinite population.