1
$\begingroup$

I have a distribution that will continuously have numbers added to it as they are measured. I want to keep only knowledge of the mean, the standard deviation, and the number of values so far in the distribution.
How would I go about adding a new value to the distribution and correctly recalculating the standard deviation? (I can do the mean).
Thanks!

1 Answers 1

1

Let's write the mean when we have $N$ values as $\bar x_N$. Then: $ \bar x_{N+1}=\frac{1}{N+1}\sum_{i=1}^{N+1}x_i=\frac{N}{N+1}\frac{1}{N}\sum_{i=1}^{N}x_i+\frac{1}{N+1}x_{N+1}= $ $ =\frac{N}{N+1}\bar x_N+\frac{1}{N+1}x_{N+1} $ You already had it, but I didn't remember it and it is necessary for the next one. Notating the standard deviation when we have $N$ values as $\sigma_N$: $ \sigma^2_{N+1}=\frac{1}{N+1}\sum_{i=1}^{N+1}(x_i-\bar x_{N+1})^2=\frac{1}{N+1}\sum_{i=1}^{N+1}(x_i^2-\bar x_{N+1}^2) $

$ =\frac{N}{N+1}\frac{1}{N}\sum_{i=1}^{N}(x_i^2-\bar x_{N}^2)+\frac{1}{N+1}\sum_{i=1}^{N}(\bar x_{N}^2-\bar x_{N+1}^2)+\frac{1}{N+1}(x^2_{N+1}-\bar x^2_{N+1}) $ $ =\frac{N}{N+1}\sigma^2_N+\frac{N}{N+1}(\bar x_{N}^2-\bar x_{N+1}^2)+\frac{1}{N+1}(x^2_{N+1}-\bar x^2_{N+1}) $ I think that it should be enought.