# How does the nth sample impact Mean and Variance? [duplicate]

Given the Mean and Variance of $$n$$ samples $$x_i$$:

$$M_n=\frac {1}{n}\sum_{1}^{n} x_i$$

$$V_n=\frac {1}{n}\sum_{1}^{n}(x_i-μ_n)^2$$

How do Mean and Variance change, when we take into account one more sample?

In other words, what are the function $$f(x_n,\space...)$$ and $$g(x_n,\space...)$$ such that:

$$M_n = f(x_n,\space n, \space M_{n-1})$$

$$V_n = g(x_n, \space n, \space M_{n-1}, \space V_{n-1})$$

Thank you!

• Outliers defined as what? Often people define outliers as values that lie some number of standard deviations from the mean. In such case, it gets circular.
– Tim
Jun 9, 2019 at 9:11
• ok I'll remove the word "outlier" to focus my question better. thanks! Jun 9, 2019 at 9:12
• This answer seems to give you what you're looking for: https://math.stackexchange.com/questions/374881/recursive-formula-for-variance
– rzch
Jun 9, 2019 at 10:38