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?

  • 3
    $\begingroup$ 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. $\endgroup$ Jul 6, 2016 at 2:10
  • $\begingroup$ @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. $\endgroup$ Jul 7, 2016 at 1:12

1 Answer 1


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.

  • $\begingroup$ Thank you for explaining. In our slides there was only a single summation symbol and a single index, so I couldn't make sense of it in the context of data sets of different sizes. It makes sense now. $\endgroup$ Jul 7, 2016 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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