Unit 7, lesson 46

Conditional Probability Mass Functions

How to turn one row or column of a joint table into a conditional PMF, why the condition needs positive probability, how reversing the condition changes the denominator, and how conditional means and joint masses follow.

  • Video 46
  • Joint, Marginal and Conditional Distributions

A parcel is selected from a constructed shipping model, and you learn that it took the express route. The question of how likely an inspection is now concerns express parcels only, so the overall inspection rate may no longer be the right answer. This lesson shows how to turn the matching row of a joint table into a complete distribution given that information, how to compute a mean from it, and how to keep conditional, marginal and joint probabilities apart.

Key terms

Conditional probability mass function

Definition Let XX and YY be discrete random variables with joint PMF pX,Yp_{X,Y}, and let xx be a value with pX(x)>0p_X(x) > 0. The conditional PMF of YY given X=xX = x is

pY∣X(y∣x)=pX,Y(x,y)pX(x)p_{Y \mid X}(y \mid x) = \frac{p_{X,Y}(x, y)}{p_X(x)}

for every real yy, which is the conditional probability P(Y=y∣X=x)P(Y = y \mid X = x). For fixed xx it is a PMF in yy. Its masses are nonnegative and add to 11, since the numerators add to pX(x)p_X(x). It is positive exactly at the values yy with pX,Y(x,y)>0p_{X,Y}(x, y) > 0, which form the conditional support. If pX(x)=0p_X(x) = 0, the conditional PMF given X=xX = x is not defined. The conditional PMF of XX given Y=yY = y is defined in the same way when pY(y)>0p_Y(y) > 0.

In plain words Learning that X=xX = x keeps only the outcomes in row xx of the joint table. The conditional PMF spreads all of the probability over that row, in the same proportions the row already had.

Example In the parcel model, X=1X = 1 for express and X=0X = 0 for standard routing, and Y=1Y = 1 for an extra inspection and Y=0Y = 0 for none. The joint table with its margins is

Y=0Y = 0Y=1Y = 1pX(x)p_X(x)
X=0X = 00.30.30.20.20.50.5
X=1X = 10.10.10.40.40.50.5
pY(y)p_Y(y)0.40.40.60.611

Given X=1X = 1, the conditional masses are pY∣X(0∣1)=0.1/0.5=0.2p_{Y \mid X}(0 \mid 1) = 0.1 / 0.5 = 0.2 and pY∣X(1∣1)=0.4/0.5=0.8p_{Y \mid X}(1 \mid 1) = 0.4 / 0.5 = 0.8, which add to 11. Among express parcels the inspection probability is 0.80.8, compared with 0.60.6 over all parcels.

Renormalizing a row or column

Definition To find the conditional PMF of YY given X=xX = x from a joint table, take row xx, check that its total pX(x)p_X(x) is positive, and divide every entry of the row by that total. To find the conditional PMF of XX given Y=yY = y, do the same with column yy and its total pY(y)p_Y(y). Dividing by one common positive number keeps every ratio between entries of the row or column, keeps zero entries at zero and makes the new total 11.

In plain words The selected row or column becomes the whole world. Its entries keep their relative sizes and are rescaled so that they add to one.

Example In the parcel table the row X=0X = 0 has entries 0.30.3 and 0.20.2 with total 0.50.5, so given standard routing, YY equals 00 or 11 with probabilities 0.60.6 and 0.40.4. The row X=1X = 1 has entries 0.10.1 and 0.40.4 in the ratio 11 to 44, and they become 0.20.2 and 0.80.8. So the inspection probability is 0.40.4 for standard parcels, 0.80.8 for express parcels and 0.60.6 overall. The overall value lies between the two conditional values because it is a weighted average of them, but it equals neither. A zero entry stays zero. Toss a fair coin twice, and let XX be the number of heads on the first toss and YY the total number of heads. The row X=1X = 1 has entries 00, 14\tfrac14 and 14\tfrac14 for Y=0,1,2Y = 0, 1, 2, so given X=1X = 1 the total is 11 or 22 with probability 12\tfrac12 each, and the conditional support is {1,2}\{1, 2\}.

Reversed conditioning

Definition Let pX(x)>0p_X(x) > 0 and pY(y)>0p_Y(y) > 0. The probabilities P(Y=y∣X=x)P(Y = y \mid X = x) and P(X=x∣Y=y)P(X = x \mid Y = y) have the same numerator pX,Y(x,y)p_{X,Y}(x, y), but the first divides it by the row total pX(x)p_X(x) and the second by the column total pY(y)p_Y(y). They are linked by Bayes’ theorem,

P(X=x∣Y=y)=pX,Y(x,y)pY(y)=pY∣X(y∣x) pX(x)pY(y).\begin{aligned} &P(X = x \mid Y = y) \\[0.4em] &\quad = \frac{p_{X,Y}(x, y)}{p_Y(y)} \\[0.4em] &\quad = \frac{p_{Y \mid X}(y \mid x)\, p_X(x)}{p_Y(y)}. \end{aligned}

When pX,Y(x,y)>0p_{X,Y}(x, y) > 0, the two conditional probabilities are equal exactly when pX(x)=pY(y)p_X(x) = p_Y(y).

In plain words Read what comes after the bar first. It names the group you are working inside, and that group decides the denominator. Swapping the two sides of the bar asks a different question.

Example In the parcel table, inspection among express parcels uses the row X=1X = 1, which gives 0.4/0.50.4 / 0.5. Express routing among inspected parcels uses the column Y=1Y = 1, which gives 0.4/0.60.4 / 0.6. So

P(Y=1∣X=1)=0.8,P(X=1∣Y=1)=23.\begin{gathered} P(Y = 1 \mid X = 1) = 0.8, \\[0.4em] P(X = 1 \mid Y = 1) = \tfrac{2}{3}. \end{gathered}

The same cell 0.40.4 is divided by two different totals. Renormalizing the whole column Y=1Y = 1 gives the conditional PMF of XX given Y=1Y = 1, with mass 13\tfrac13 at 00 and 23\tfrac23 at 11. Bayes’ theorem reaches the reversed value from the conditional probability 0.80.8 and the two margins, since 0.8⋅0.5/0.6=230.8 \cdot 0.5 / 0.6 = \tfrac23.

Conditional mean from a conditional PMF

Definition Let pX(x)>0p_X(x) > 0. The conditional mean of YY given X=xX = x is the mean of the conditional PMF,

E[Y∣X=x]=∑yy pY∣X(y∣x),\begin{aligned} &E[Y \mid X = x] \\[0.4em] &\quad = \sum_{y} y \, p_{Y \mid X}(y \mid x), \end{aligned}

where the sum runs over the conditional support. It exists when ∑y∣y∣ pY∣X(y∣x)\sum_{y} \lvert y \rvert \, p_{Y \mid X}(y \mid x) is finite, which always holds when YY has finitely many possible values. It is a number attached to the value xx, and it need not be a possible value of YY.

In plain words Find the right conditional distribution first, then average YY with its weights. Averaging with the raw joint masses of the row skips the division by the row total and in general gives a wrong answer.

Example In a constructed timing model, a task belongs to group A, coded X=0X = 0, or to group B, coded X=1X = 1, and it takes T=2T = 2 or T=6T = 6 minutes.

T=2T = 2T=6T = 6pX(x)p_X(x)
X=0X = 0, group A916\tfrac{9}{16}316\tfrac{3}{16}34\tfrac34
X=1X = 1, group B116\tfrac{1}{16}316\tfrac{3}{16}14\tfrac14

Dividing each row by its total gives the masses 34\tfrac34 and 14\tfrac14 at the times 22 and 66 in group A, and 14\tfrac14 and 34\tfrac34 in group B. Hence E[T∣X=0]=2⋅34+6⋅14=3E[T \mid X = 0] = 2 \cdot \tfrac34 + 6 \cdot \tfrac14 = 3 minutes and E[T∣X=1]=2⋅14+6⋅34=5E[T \mid X = 1] = 2 \cdot \tfrac14 + 6 \cdot \tfrac34 = 5 minutes. Neither mean is a possible duration. Weighting the times by the raw row entries of group A would give 2⋅916+6⋅316=942 \cdot \tfrac{9}{16} + 6 \cdot \tfrac{3}{16} = \tfrac94, which is the conditional mean 33 multiplied by the row total 34\tfrac34 and not the conditional mean itself.

Joint probability from conditional and marginal

Definition For every xx with pX(x)>0p_X(x) > 0 and every real yy,

pX,Y(x,y)=pX(x) pY∣X(y∣x),\begin{aligned} &p_{X,Y}(x, y) \\[0.4em] &\quad = p_X(x)\, p_{Y \mid X}(y \mid x), \end{aligned}

and pX,Y(x,y)=0p_{X,Y}(x, y) = 0 for every yy when pX(x)=0p_X(x) = 0. Adding over xx gives the law of total probability for PMFs,

pY(y)=∑xpX(x) pY∣X(y∣x),\begin{aligned} &p_Y(y) \\[0.4em] &\quad = \sum_{x} p_X(x)\, p_{Y \mid X}(y \mid x), \end{aligned}

where the sum runs over the values xx with pX(x)>0p_X(x) > 0. So pY(y)p_Y(y) is a weighted average of the conditional probabilities pY∣X(y∣x)p_{Y \mid X}(y \mid x) with weights pX(x)p_X(x). A plain average of the conditional probabilities agrees with it when the weights are equal, and in general it does not.

In plain words Conditioning divides a joint mass by a group total. Multiplying a within-group probability by the probability of the group undoes that step and recovers the joint mass, and adding over the groups recovers the overall probability.

Example Change the parcel model so that P(X=0)=0.75P(X = 0) = 0.75 and P(X=1)=0.25P(X = 1) = 0.25, while the inspection probabilities stay 0.40.4 for standard and 0.80.8 for express parcels. The joint masses with inspection are 0.75⋅0.4=0.30.75 \cdot 0.4 = 0.3 and 0.25⋅0.8=0.20.25 \cdot 0.8 = 0.2, and those without inspection are 0.75⋅0.6=0.450.75 \cdot 0.6 = 0.45 and 0.25⋅0.2=0.050.25 \cdot 0.2 = 0.05, so the four cells add to 11. The overall inspection probability is

P(Y=1)=0.3+0.2=0.5,P(Y = 1) = 0.3 + 0.2 = 0.5,

not the plain average 0.60.6 of 0.40.4 and 0.80.8. In the original model the two routes were equally likely, which is why the plain average happened to give the right value there. The timing table above was built the same way, since 34⋅34=916\tfrac34 \cdot \tfrac34 = \tfrac{9}{16} and 14⋅14=116\tfrac14 \cdot \tfrac14 = \tfrac{1}{16}.

Check yourself

  1. A joint table has the row (0.1,0.2)(0.1, 0.2) for X=0X = 0 and the row (0.3,0.4)(0.3, 0.4) for X=1X = 1, with columns for Y=0Y = 0 and Y=1Y = 1. Find P(Y=1∣X=1)P(Y = 1 \mid X = 1) and P(X=1∣Y=1)P(X = 1 \mid Y = 1), and then the full conditional PMF of YY given X=0X = 0.
Show the answer

The row X=1X = 1 has total 0.70.7, so P(Y=1∣X=1)=0.4/0.7=47P(Y = 1 \mid X = 1) = 0.4 / 0.7 = \tfrac47. The reversed question uses the column Y=1Y = 1, whose total is 0.2+0.4=0.60.2 + 0.4 = 0.6, so P(X=1∣Y=1)=0.4/0.6=23P(X = 1 \mid Y = 1) = 0.4 / 0.6 = \tfrac23. The row X=0X = 0 has total 0.30.3, so given X=0X = 0 the variable YY equals 00 with probability 0.1/0.3=130.1 / 0.3 = \tfrac13 and 11 with probability 0.2/0.3=230.2 / 0.3 = \tfrac23. These two masses add to 11.

  1. A joint PMF has the following table, and XX takes no values other than 00 and 11.
Y=0Y = 0Y=1Y = 1Y=2Y = 2
X=0X = 018\tfrac1818\tfrac1800
X=1X = 118\tfrac1814\tfrac1438\tfrac38

Find E[Y∣X=0]E[Y \mid X = 0] and E[Y∣X=1]E[Y \mid X = 1], and the conditional PMF of XX given Y=2Y = 2. Can E[Y∣X=2]E[Y \mid X = 2] be computed?

Show the answer

The row X=0X = 0 has total 14\tfrac14, so given X=0X = 0 the masses at Y=0,1,2Y = 0, 1, 2 are 12\tfrac12, 12\tfrac12 and 00. Only the value 11 contributes to the mean, so

E[Y∣X=0]=1⋅12=12.E[Y \mid X = 0] = 1 \cdot \tfrac12 = \tfrac12.

The row X=1X = 1 has total 34\tfrac34, so the conditional masses are 16\tfrac16, 13\tfrac13 and 12\tfrac12, and

E[Y∣X=1]=1⋅13+2⋅12=43.\begin{aligned} E[Y \mid X = 1] &= 1 \cdot \tfrac13 + 2 \cdot \tfrac12 \\[0.4em] &= \tfrac43. \end{aligned}

The column Y=2Y = 2 has total 38>0\tfrac38 > 0 and entries 00 and 38\tfrac38, so given Y=2Y = 2 the variable XX equals 11 with probability 11. The conditional support is {1}\{1\}. The value X=2X = 2 has probability pX(2)=0p_X(2) = 0, so there is no row to renormalize. The conditional PMF of YY given X=2X = 2 is not defined, and neither is E[Y∣X=2]E[Y \mid X = 2], because the formula would divide by zero.

  1. In a constructed model, 20 percent of parts come from line 1, coded X=1X = 1, and the rest from line 0, coded X=0X = 0. A check flags a part, coded Y=1Y = 1, for 90 percent of the parts from line 1 and 10 percent of the parts from line 0. Build the joint table, and find P(Y=1)P(Y = 1) and P(X=1∣Y=1)P(X = 1 \mid Y = 1). A classmate answers 0.90.9 for the last probability. What went wrong?
Show the answer

Multiplying each line’s probability by the conditional probabilities gives pX,Y(1,1)=0.2⋅0.9=0.18p_{X,Y}(1, 1) = 0.2 \cdot 0.9 = 0.18, pX,Y(1,0)=0.2⋅0.1=0.02p_{X,Y}(1, 0) = 0.2 \cdot 0.1 = 0.02, pX,Y(0,1)=0.8⋅0.1=0.08p_{X,Y}(0, 1) = 0.8 \cdot 0.1 = 0.08 and pX,Y(0,0)=0.8⋅0.9=0.72p_{X,Y}(0, 0) = 0.8 \cdot 0.9 = 0.72, which add to 11. The column Y=1Y = 1 gives P(Y=1)=0.18+0.08=0.26P(Y = 1) = 0.18 + 0.08 = 0.26, and

P(X=1∣Y=1)=0.180.26=913≈0.692.\begin{aligned} &P(X = 1 \mid Y = 1) \\[0.4em] &\quad = \frac{0.18}{0.26} = \frac{9}{13} \\[0.4em] &\quad \approx 0.692. \end{aligned}

The value 0.90.9 is P(Y=1∣X=1)P(Y = 1 \mid X = 1), the flag rate within line 1, which divides the cell 0.180.18 by the row total 0.20.2 instead of the column total 0.260.26. Here reversing the condition changes the denominator and with it the answer. A plain average of the two flag rates, 0.50.5, would also be wrong for P(Y=1)P(Y = 1), because the lines have weights 0.20.2 and 0.80.8.

How this lesson connects