# Generalize Pearson

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 ?

• First of all - what do you need the generalization for? What kind of quantity you would like to measure, what properties you would like to have, etc... Commented Mar 11, 2011 at 18:14
• I need it to bevhave just like Person. Except that "older" values affect r less than newer values. I give older values smaller weight = smaller "importance". Does it make sense. For example if all $w_i$ are equal then it would become regular Pearson. Commented Mar 11, 2011 at 18:57

I think that the correct thing to do is treat the values as if they were repeated $w_i$ times. That is, assume first that the weights $w_i$ are non-negative integers, the data actually comes in the form such that the pair $(x_i, y_i)$ appears $w_i$ times, and compute the standard Pearson correlation for such (repeated) data. Doing so gives: $\bar{X}' = \frac{\sum_{i=1}^n w_i x_i}{\sum_{i=1}^n w_i}$ (and similarly for $Y$). And in terms of the original $n$ data points, the formula is: $$r(X,Y,w) = \frac{\sum_{i=1}^n w_i (X_i-\bar{X}')(Y_i-\bar{Y}')}{\sqrt{\sum_{i=1}^n w_i (X_i - \bar{X}')^2} \sqrt{\sum_{i=1}^n w_i (Y_i - \bar{Y}')^2}}$$
and then you can use it of course for general real weights $w_i$. I don't think this is equivalent to your suggestion.