Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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).

share|cite|improve this question

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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.