I'm looking for a formula, to iteratively calculate the mean and standard deviation of a huge list of data points.
I found some examples here (formula 15 f.) and here, but both seem to be falling for my very simple testcase [10,100].
Source 1 states:
$M_1 = x_1$
$S_1 = 0$
$M_k = M_{k-1}+(x_k-M_{k-1})/k$
as well as
$S_k = S_{k-1}+(x_k-M_{k-1})*(x_k-M_k)$
with
$\sigma = \sqrt{S_n/(n-1)}$
This leads me to $M_1 = 10, S_1 = 0$ and $M_2 = 10+(100-10)/2 = 55$ but $S_2 = 0+(100-10)*(100-55) = 4050$ and therefore with $n=2$ to $\sigma \approx 63.6396$. The correct value is $45$, which I get, when I plug in $n = 3$ in the formula for $\sigma$.
Do I understand the formula wrong?
Source 2:
$M_{n+1}=M_n+x_{n+1}$
$S_{n+1}=S_n+\frac{(n*x_{n+1}−M_n)^2}{n(n+1)}$
with the mean given by
$\bar{x}_n= \frac{M_n}{n}$
and the unbiased estimate of the variance is given by
$\sigma_n^2=\frac{S_n}{n+1}$
which leads me to
$M_1 = 10, M_2 = 110, S_1 = 0$
$S_2 = 0+\frac{(2*100-10)^{2}}{2(2+1)} = 6016.6667$
however, if I plug in $n=1$ again this is correct. I feel, that my understanding of indexes is wrong, but why?