User:Azmisov/sandbox

First, we use the recurrence relation for weighted mean:

$$v_n = \textstyle \sum_{i=1}^n \displaystyle w_i$$

$$\begin{array}{lcl} \bar x_n & = & \frac 1 {v_n} \textstyle \sum_{i=1}^n \displaystyle w_ix_i\\ & = & \frac 1 {v_n}((\bar x_{n-1}-1)(v_n-w_i)+w_ix_n) \\ & = & \bar x_{n-1}+\frac {w_i} {v_n}(x_n-\bar x_{n-1}) \end{array}$$

Next we derive the recurrence relation for the difference term:

$$x_i-\bar x_n = (x_i-\bar x_{n-1})-\frac {w_i} {v_n}(x_n-\bar x_{n-1})$$

And note the following formula when $i = n$ :

$$x_n-\bar x_n = \frac {v_{n-1}} {v_n}(x_n-\bar x_{n-1})$$

A similar formula can be obtained for $y$ by substituting the variable for $x$. From here, we can derive the recurrence relation for weighted covariance:

$$\begin{array}{lcl} C_n & = & \textstyle \sum_{i=1}^n \displaystyle w_i(x_i-\bar x_n)(y_i-\bar y_n)\\ & = & w_n(x_n-\bar x_n)(y_n-\bar y_n) + \textstyle \sum_{i=1}^{n-1} \displaystyle w_i(x_i-\bar x_n)(y_i-\bar y_n)\\ & = & w_n(x_n-\bar x_n)(y_n-\bar y_n) + \textstyle \sum_{i=1}^{n-1} \displaystyle w_i((x_i-\bar x_{n-1})-\frac {w_i} {v_n}(x_n-\bar x_{n-1}))((y_i-\bar y_{n-1})-\frac {w_i} {v_n}(y_n-\bar y_{n-1})) \end {array}$$

Here, it is useful to note these relations:

$$\begin{array}{lcl} \textstyle \sum_{i=1}^{n-1} \displaystyle \frac {w_i^2} {v_n}(x_i-\bar x_{n-1})(y_n-\bar y_{n-1}) & = & \frac {y_n-\bar y_{n-1}} {v_n} \textstyle \sum_{i=1}^{n-1} \displaystyle w_i^2(x_i-\bar x_{n-1}) \\ & = & \frac {y_n-\bar y_{n-1}} {v_n}(\bar x_{n-1}(n-1) - \bar x_{n-1}(n-1))\\ & = & 0 \end {array}$$

A similar result can be obtained by switching the $x$ and $y$  variables. So when we expand the summation in our formula for $C_n$ we will get this simplified expression:

$$\begin{array}{lcl} C_n & = & C_{n-1} + w_n(x_n-\bar x_n)(y_n-\bar y_n) + \frac {q_n} {v_n2}(x_n-\bar x_{n-1})(y_n-\bar y_{n-1}) \\ & = & C_{n-1} + \frac {w_nv_{n-1}^2} {v_n^2}(x_n-\bar x_{n-1})(y_n-\bar y_{n-1}) + \frac {q_n} {v_n2}(x_n-\bar x_{n-1})(y_n-\bar y_{n-1}) \\ & = & C_{n-1} + \frac {w_nv_{n-1}^2 - q_n} {v_n^2}(x_n-\bar x_{n-1})(y_n-\bar y_{n-1}) \end {array}$$