Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Recipe

Compute covariance from a joint distribution

Use when: you have a full joint table (or the raw pieces E(XY), E(X), E(Y)) and need \operatorname{Cov}(X,Y)

Goal: a single signed number measuring how X and Y move together, ready to read by its sign, or to rescale into correlation later

Taught in Covariance · a later section extends this recipe with more cases

  1. 1

    Sum each row of the joint table to get X's marginal distribution, then average it; do the same with the columns for Y's marginal distribution.

    Example

    A joint table has p(0,0)=0.2, p(0,1)=0.1, p(1,0)=0.1, p(1,1)=0.6. Row sums give X's marginal, 0.3 at X=0 and 0.7 at X=1, so E(X)=0(0.3)+1(0.7)=0.7. Column sums give the same numbers for Y here, so E(Y)=0.7 too.

    Why: \operatorname{Cov}(X,Y)=E(XY)-E(X)E(Y) needs both marginal means as a separate piece from the joint behavior Step 2 captures.

  2. 2

    Multiply each cell's x-value by its y-value by its own joint probability, and add these products across the whole table. Any cell where x=0 or y=0 contributes 0 automatically.

    Example

    Only the cell x=1,y=1 contributes: E(XY) = (0)(0)(0.2)+(0)(1)(0.1)+(1)(0)(0.1)+(1)(1)(0.6) = 0.6.

    Why: E(XY) is the only place the two variables' JOINT probabilities enter the computation at all; the marginals alone could never distinguish this pair from an independent one with the same marginals.

  3. 3

    Subtract the product of the two marginal means, found in Step 1, from E(XY), found in Step 2.

    Example

    \operatorname{Cov}(X,Y) = 0.6 - (0.7)(0.7) = 0.6 - 0.49 = 0.11

    ⚡ Shortcut

    If X and Y are already known to be independent (checked with the recipe from the previous section), skip this step entirely: \operatorname{Cov}(X,Y)=0 automatically, since independence forces E(XY)=E(X)E(Y).

    Why: this is the computational form of \operatorname{Cov}(X,Y)=E\big[(X-\mu_X)(Y-\mu_Y)\big], reaching the same number without computing every individual deviation product by hand.

  4. 4

    A positive result means X and Y tend to sit above (or below) their own means together. A negative result means one runs high exactly when the other runs low. A result near zero means little linear association.

    Example

    \operatorname{Cov}(X,Y)=0.11 > 0: the two variables here tend to move together, matching the table's own concentration of probability in the (1,1) cell.

    Why: the sign is exactly what covariance is built to report. Its raw magnitude still depends on the units X and Y happen to be measured in — exactly what the next section's correlation fixes.

Common mistakes

  • Computing E(X)E(Y) correctly but then adding instead of subtracting it from E(XY).
  • Computing E(XY) by multiplying the marginal means, E(X)E(Y), instead of summing xy\cdot p(x,y) over the actual joint table.
  • Forgetting that a cell with x=0 or y=0 still needs to be included in the sum for Step 2, it just happens to contribute 0.
  • Dropping a sign when X or Y takes negative values, since a negative times a negative flips the product's sign.