# 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.

## closed as unclear what you're asking by AdamO, Michael Chernick, Juho Kokkala, mdewey, kjetil b halvorsenJan 3 '18 at 20:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• 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? – Quartz Jun 26 '13 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. – AdamO Jun 26 '13 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.
• 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. – vinnief Jun 27 '13 at 13:26