If I currently have a sum of N elements (I don't have the elements them self), their mean and the corresponding standard deviation. Later on I receive M (known) other elements. I want to update the mean and standard deviation that I already have according to this new elements. Is it possible to do so ?
standard deviation computation
0
$\begingroup$
statistics
standard-deviation
-
1Yes you can. Add to the sum of N elements the sum of the new M elements. Then dividing it by N+M you get the new mean. Now try with the variance; remember that the variance is the mean of the squares minus the square of the mean. – 2012-03-26
-
0So I need to save the sum of the N elements (to be able to compute the mean later) as well as the sum of squared N elements (to be able to compute the variance later) ? Then the variance when I have M new elements will be: the last sum of squared N elements plus the sum of squared M elements, minus the square of the new mean (which can be computed easily by deviding the sum of all elements by N+M) ? – 2012-03-26
-
1Yes. So suppose you have the old mean and variance (call them m and v) and the number N. Then you recive M new elements. So (N*m+sum of new) / (N+M) is the new mean. This is because N*m produce the sum of the old, then you add the sum of the new, and finally you divide by the total number of elements. For the variance: s = (v+m^2)*N is the sum of the old values (suqred). Then you add to s the sum of the new values (suqred, this I mean you have to do the square and then sum) and then divide it by (N+M). So you have the (new) mean of the squared (called second moment). Subtract the new mean... – 2012-03-26
-
0...squared to get the new variance. – 2012-03-26
1 Answers
0
We need to save the sum of the $N$ elements (to be able to compute the mean later) as well as the sum of squared $N$ elements (to be able to compute the variance later). Then the variance when we have $M$ new elements will be: the last sum of squared N elements plus the sum of squared $M$ elements, minus the square of the new mean (which can be computed easily by dividing the sum of all elements by $N+M$).