How to find variance of k+1 elements if variance of k elements is known?

425 Views Asked by At

I need to find the variance of k+1 elements given the variance of k elements. I can also store other features for k elements like mean ($\mu_n$) etc. So, given the below function's value,

$$ \frac{1}{n}\sum\limits_{i=1}^n(a_i-\mu_{n})^2 $$

I need to find

$$ \frac{1}{n+1}\sum\limits_{i=1}^{n+1}(a_i-\mu_{n+1})^2 $$

where $\mu_{n}$ is the mean of k elements and $\mu_{n+1}$ is the new mean of k+1 elements.

1

There are 1 best solutions below

0
On

Let $(\mu_n,\sigma^2_n)$ be mean and variance of $a_1,a_2,\ldots,a_{n}$. Then:

$$ \color{blue}{\mu_{n+1}} = \frac{1}{n+1}\sum_{k=1}^{n+1}a_k = \color{blue}{\frac{a_{n+1}+n \mu_n}{n+1}}\tag{1} $$ and:

$$\begin{eqnarray*}\color{red}{\sigma^2_{n+1}}&=&\frac{1}{n+1}\sum_{k=1}^{n+1}(a_k-\mu_{n+1})^2\\&=&\frac{1}{n+1}\sum_{k=1}^{n+1}\left[(a_k-\mu_n)^2-2(a_k-\mu_n)(\mu_{n+1}-\mu_n)+(\mu_{n+1}-\mu_n)^2\right]\\&=&\frac{1}{n+1}\sum_{k=1}^{n+1}\left[(a_k-\mu_n)^2+(\mu_{n+1}-\mu_n)^2\right]\\&=&\color{red}{(\mu_{n+1}-\mu_n)^2+\frac{\sigma_n^2+(a_{n+1}-\mu_n)^2}{n+1}}\tag{2}\end{eqnarray*}$$

are the update rules.