# How to calculate weighted covariance? [closed]

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:

http://en.wikipedia.org/wiki/Weighted_arithmetic_mean

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

• 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? Jun 26, 2013 at 9:41
• 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. Jun 26, 2013 at 21:59

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.

• The above formula calculates only the sumproduct of variables with weights but not the weighted covariance.
– Jai
Jun 26, 2013 at 4:51
• You are right, I now corrected it. Jun 26, 2013 at 20:49
• Please note that 'a' and 'b' are cost / price and not frequencies.
– Jai
Jun 27, 2013 at 5:16
• 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.
– Jai
Jun 27, 2013 at 5:28
• 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. Jun 27, 2013 at 13:26