I have two variables X and Y with weights a and b respectively.

Pl. see the link for sample data.


I know how to calculate weighted mean and weighted variance for the variables X and Y.

How to calculate weighted covariance values? What is the formula?

I have gone through the following website:


but my problem is I Have different weights for each observations under each variable.

  • 2
    $\begingroup$ Could you please explain better why $w_i=a_i b_i$ in the linked formula would not fit your needs? Have you got an additional weighting $\omega_i$ for the $(X_i,Y_i)$ pairs? $\endgroup$
    – Quartz
    Jun 26, 2013 at 9:41
  • 1
    $\begingroup$ Are these frequency weights? What does one row of this aggregate data even correspond to? For every 3 Xs obseved at 134, 9 Ys are observed at 193??? I think this should only have 1 weight variable. $\endgroup$
    – AdamO
    Jun 26, 2013 at 21:59

1 Answer 1


Technically, you could use both weights: $\frac{\sum_{i=1}^k \sum_{j=1}^l (x_i-\bar{x}) (y_j-\bar{y}) a_i b_j} {\sum_{i=1}^k\sum_{j=1}^l a_i b_j}$, where $\bar{x}$ and $\bar{y}$ are the weighted means of $x$ and $y$, respectively. but whether it makes sense depends on the meanings of the weights. If the weights are frequencies, the above formula would not make sense, as you would need the joint frequencies, $c_{ij}$, such that $a_i= \sum_{j=1}^l c_{ij} \sum_{i=1}^k a_i $ and $b_j= \sum_{i=1}^k c_{ij} \sum_{j=1}^lb_j$ for all $i$ and all $j$.

Under independence, $c_{ij} = \frac{a_i b_j}{\sum_{i=1}^k\sum_{j=1}^l a_i b_j}$ would hold.

  • $\begingroup$ The above formula calculates only the sumproduct of variables with weights but not the weighted covariance. $\endgroup$
    – Jai
    Jun 26, 2013 at 4:51
  • $\begingroup$ You are right, I now corrected it. $\endgroup$
    – vinnief
    Jun 26, 2013 at 20:49
  • $\begingroup$ Please note that 'a' and 'b' are cost / price and not frequencies. $\endgroup$
    – Jai
    Jun 27, 2013 at 5:16
  • $\begingroup$ Please note that 'a' and 'b' are cost / price and not frequencies. When I used the above variance covariance formula for calculating the variance, it is different from the weighted variance obtained from the formula given in en.wikipedia.org/wiki/Weighted_arithmetic_mean. I have worked out this in a MS-Excel sheet. Pl. help me how to attach this file. $\endgroup$
    – Jai
    Jun 27, 2013 at 5:28
  • $\begingroup$ Am new myself, and don't know how to upload files. Could you upload them on docs.google.com, and share the link here? What are $x$ and $y$? Usually its the other way around: the variables are prices and the weights volumes, or frequencies. $\endgroup$
    – vinnief
    Jun 27, 2013 at 13:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.