# Covariance between two random variables with different number of values?

Let's say I have a RV $X$ with values $100$, $200$ and their associated probabilities, and some RV $Y$ with values $35$, $47$ and $862$ with associated probabilities.

What does it even mean to find the covariance of those Random Variables? Looking at the formula it looks like we're doing $$(x_1 - \mu_x) (y_1 - \mu_y) P(x_1 \cap y_1) + (x_2 - \mu_x) (y_2 - \mu_y) P(x_2 \cap y_2) + ... + (x_n - \mu_x) (y_n - \mu_y) P(x_n \cap y_n)$$.

How does that make sense if the random variables have different numbers of values?

• Where did you get that formula? Of course you need to know the joint probability of all combinations of values from X and Y in order to compute their covariance. So basically, you will have a double summation, and the number of terms (variable values) in each sum need not be the same. – Mark L. Stone Jul 6 '16 at 2:10
• @MarkL.Stone, sorry for the late reply and thanks for the clarification. The formula was in the prof's slides. That's why I was confused because there was only a single summation symbol and a single index, so it didn't really make any sense if we assume different data set sizes. – jeremy radcliff Jul 7 '16 at 1:12

A more typical way to write out the covariance of two discrete random variables would be: \begin{align} Cov(X, Y) = E[(X - \mu_X)(Y - \mu_Y)] = \sum_x \sum_y (x - \mu_X)(y - \mu_Y)P(X=x, Y=y) \end{align} In your case you would get: \begin{align} (100 - \mu_x)(35 - \mu_y)P(X=100, Y=35) + (100 - \mu_x)(47 - \mu_y)P(X=100, Y=47) + \dots + (200 - \mu_x)(862 - \mu_y)P(X=200, Y=862) \end{align} So in short I think that what you are missing is that you should be summing over all possible pairs of outcomes, giving you $3\times 2 = 6$ things to sum over.