Say I have a mean and standard deviation for a dataset of 5 elements.
I now add a sixth element. Is there a way to calculate the new mean and standard deviation using the information we had prior (i.e. not just recalculating the whole thing from scratch)?
For the mean, I see that I can just multiply the old one by $5$, add the new element, and divide by $6$.
I'm not sure if there's something I can do with the standard deviation, however.
$$\sigma_{old} = \sqrt{\sum_i (X_i - \mu_{old})^2}$$
$$\sigma_{new} = \sqrt{\sum_i (X_i - \mu_{new})^2 + (X_{new} - \mu_{new})^2}$$
$$\mu_{new} = \frac{\mu_{old}*N + X_{new}}{N+1}$$
$$\sigma^2_{new} = \sigma^2_{old} + \sum_i \left( (X_i - \mu_{new})^2 - (X_i - \mu_{old})^2 \right) + (X_{new} - \mu_{new})^2$$
After putting it in terms of the old stats, this becomes (I think)
$$\sigma^2_{new} = \sigma^2_{old} + \sum_i \left(2 X_i + \frac{(2N+1) \mu_{old} + X_{new}}{N+1} \right) \left(\frac{X_{new} - \mu_{old}}{N+1}\right) + (X_{new} - \frac{\mu_{old}*N + X_{new}}{N+1})^2$$
Is there anything better than this monstrosity?