I compute well-known "sample Pearson correlation coefficient" of two vectors:

$r(X,Y) = \frac{\sum ^n _{i=1}(X_i - \bar{X})(Y_i - \bar{Y})}{\sqrt{\sum ^n _{i=1}(X_i - \bar{X})^2} \sqrt{\sum ^n _{i=1}(Y_i - \bar{Y})^2}}$ . So far so good.

I need to generalize it as follows.
I need to add "weights", $w_i\in[0..1]$, to the formula.

The idea is that *smaller values* of $w_i$ make affect of $(X_i,Y_i)$ on $r$ *smaller*.

(Proportionally to value of $w_i$.)

Without $w_i$, every $(X_i,Y_i)$ and $(Y_j,Y_j)$ affec $r$ equaly.

$w_i$ makes then affect $r$ differently, with different "weight".

Would it be right to calculate $r(X,Y,w)$ as

$r(X',Y')$ where $X'_i=w_i(X_i-\bar{X})$, and $Y'_i=w_i(Y_i-\bar{Y})$ ? Or else, what would be the

right way to insert $w_i$ into the formula ?