Preview

A lesson from Essential Probability & Statistics for ML

£29/month

£29/month£29/month or £249/year · 30-day money-back guarantee

Get full access

Our content is best on a larger screen

Conditional PMFs

Slicing and renormalising

Explanation

Suppose the random variable XX is 11 if an email is spam and 00 if not, and YY is the number of times the email contains the word "free". Knowing that an email is spam changes what we expect of YY, and their joint PMF holds that information.

So what is the distribution of YY once we know that X=xX = x? With a two-way table of counts, we found a conditional probability by restricting to the known row and dividing by its total. With the joint PMF we do this to every cell in the row for X=xX = x, which gives a whole distribution of YY: the conditional distribution of YY given X=xX = x.

The diagram finds it for each value of XX in steps.

y=0
y=1
y=2
x=0
x=1
0.3
0.18
0.12
0.1
0.1
0.2

Step 1: The joint PMF

Here X=1 if an email is spam and X=0 if not, and Y is the number of times it contains the word "free": 0, 1 or 2. Suppose we learn that an email is spam, so X=1.

Step 2: Restrict to the slice

Only pairs with x=1 can still happen, so only the cells of row x=1 remain: a slice of the table. Their total is not 1 but the marginal PMF of X at 1:

pX(1)=0.1+0.1+0.2=0.4

Step 3: Renormalise

We divide each cell by 0.4. This renormalises the slice: its cells keep their proportions and now add to 1.

0.10.4=0.250.10.4=0.250.20.4=0.5

These are the probabilities of each value of Y given X=1.

Step 4: The other slice

If instead the email is not spam, we restrict to row x=0, with total pX(0)=0.6, and divide each cell by 0.6:

0.30.6=0.50.180.6=0.30.120.6=0.2

Each value of X gives its own distribution of Y. Given spam, Y=2 is the most likely value; given not spam, Y=0 is.

Conditional PMF

Definition

For discrete random variables XX and YY, the conditional PMF of YY given X=xX = x is

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

for each value xx with pX(x)>0p_X(x) > 0. It gives the conditional distribution of YY given X=xX = x.

Likewise, the conditional PMF of XX given Y=yY = y is

pX∣Y(x∣y)=P(X=x∣Y=y)=p(x,y)pY(y)p_{X \mid Y}(x \mid y) = P(X = x \mid Y = y) = \dfrac{p(x, y)}{p_Y(y)}

for each value yy with pY(y)>0p_Y(y) > 0.

Example

An online shop records a product's star rating XX, from 11 to 33, and sets Y=1Y = 1 if the product is returned and Y=0Y = 0 otherwise. The joint PMF of XX and YY is:

y=0y = 0y=1y = 1
x=1x = 10.080.080.120.12
x=2x = 20.240.240.060.06
x=3x = 30.480.480.020.02

Find the PMF of the star rating XX of a returned product, and the probability that a returned product has at least 22 stars.

Solution

A returned product has Y=1Y = 1, so we want the conditional PMF of XX given Y=1Y = 1. The known value is a value of YY, so the slice is the column for Y=1Y = 1. Its cells are 0.120.12, 0.060.06 and 0.020.02, and its total is

pY(1)=0.12+0.06+0.02=0.2p_Y(1) = 0.12 + 0.06 + 0.02 = 0.2

We renormalise the slice by dividing each cell by 0.20.2:

pX∣Y(1∣1)=0.120.2=0.6pX∣Y(2∣1)=0.060.2=0.3pX∣Y(3∣1)=0.020.2=0.1\begin{align*} p_{X \mid Y}(1 \mid 1) &= \dfrac{0.12}{0.2} = 0.6 \\[6pt] p_{X \mid Y}(2 \mid 1) &= \dfrac{0.06}{0.2} = 0.3 \\[6pt] p_{X \mid Y}(3 \mid 1) &= \dfrac{0.02}{0.2} = 0.1 \end{align*}

As a table, the PMF of XX given Y=1Y = 1 is:

xx112233
pX∣Y(x∣1)p_{X \mid Y}(x \mid 1)0.60.60.30.30.10.1

A returned product with at least 22 stars is the event X≥2X \ge 2 given Y=1Y = 1. It holds for x=2x = 2 and x=3x = 3, so we add those values of the conditional PMF:

P(X≥2∣Y=1)=pX∣Y(2∣1)+pX∣Y(3∣1)=0.3+0.1=0.4\begin{align*} P(X \ge 2 \mid Y = 1) &= p_{X \mid Y}(2 \mid 1) + p_{X \mid Y}(3 \mid 1) \\[6pt] &= 0.3 + 0.1 \\[6pt] &= 0.4 \end{align*}

So a returned product has at least 22 stars with probability 0.40.4.

Practice questions

5 questions

A survey records the number of children XX in a household, from 11 to 33, and the number of cars YY, from 00 to 22. The joint PMF of XX and YY is:

y=0y = 0y=1y = 1y=2y = 2
x=1x = 10.150.150.090.090.160.16
x=2x = 20.060.060.120.120.120.12
x=3x = 30.090.090.090.090.120.12

What is the PMF of the number of cars YY in a household with 22 children?

Select the correct answer:

+ 4 more questions · unlocked with a subscription

Rebuilding the joint from conditionals

Explanation

Many pairs of random variables arise in two stages: first XX takes a value, then YY takes a value from its conditional distribution given that value.

We then know the pair through pXp_X and the conditional PMFs of YY given each value of XX, rather than through its joint PMF. Can we recover the joint PMF from them?

We can. The multiplication rule for probabilities, P(A∩B)=P(A) P(B∣A)P(A \cap B) = P(A)\,P(B \mid A), with A={X=x}A = \{X = x\} and B={Y=y}B = \{Y = y\}, gives every cell of the joint PMF:

P(X=x,Y=y)=P(X=x) P(Y=y∣X=x)P(X = x, Y = y) = P(X = x)\,P(Y = y \mid X = x)

In PMF notation, this is:

The joint PMF from conditional PMFs

Theorem

For discrete random variables XX and YY,

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

for each value xx with pX(x)>0p_X(x) > 0 and every value yy. Likewise,

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

for each value yy with pY(y)>0p_Y(y) > 0 and every value xx.

So pXp_X and the conditional PMFs determine the joint PMF, whereas the two marginal PMFs, in general, do not: the marginal PMF of YY is one distribution, whatever the value of XX, while the conditional PMFs give one for each value of XX.

Example

A parcel goes by van (X=0X = 0) with probability 0.70.7, and otherwise by bike (X=1X = 1). The number of days late YY, from 00 to 22, has these conditional PMFs given each XX:

yy001122
pY∣X(y∣0)p_{Y \mid X}(y \mid 0)0.80.80.10.10.10.1
pY∣X(y∣1)p_{Y \mid X}(y \mid 1)0.60.60.30.30.10.1

Find the joint PMF of XX and YY.

Solution

The parcel goes by bike whenever it does not go by van, so the marginal PMF of XX is

pX(0)=0.7,pX(1)=1−0.7=0.3p_X(0) = 0.7, \qquad p_X(1) = 1 - 0.7 = 0.3

Each cell is p(x,y)=pX(x) pY∣X(y∣x)p(x, y) = p_X(x)\,p_{Y \mid X}(y \mid x), so we multiply each row of conditionals by the marginal of its own value of XX. For the van row, we multiply by pX(0)=0.7p_X(0) = 0.7:

p(0,0)=0.7×0.8=0.56p(0,1)=0.7×0.1=0.07p(0,2)=0.7×0.1=0.07\begin{align*} p(0, 0) &= 0.7 \times 0.8 = 0.56 \\[6pt] p(0, 1) &= 0.7 \times 0.1 = 0.07 \\[6pt] p(0, 2) &= 0.7 \times 0.1 = 0.07 \end{align*}

For the bike row, we multiply by pX(1)=0.3p_X(1) = 0.3:

p(1,0)=0.3×0.6=0.18p(1,1)=0.3×0.3=0.09p(1,2)=0.3×0.1=0.03\begin{align*} p(1, 0) &= 0.3 \times 0.6 = 0.18 \\[6pt] p(1, 1) &= 0.3 \times 0.3 = 0.09 \\[6pt] p(1, 2) &= 0.3 \times 0.1 = 0.03 \end{align*}

Writing the cells in a two-way table gives the joint PMF:

y=0y = 0y=1y = 1y=2y = 2
x=0x = 00.560.560.070.070.070.07
x=1x = 10.180.180.090.090.030.03

Each row adds to its marginal, 0.70.7 and 0.30.3, so the cells add to 11.

Practice questions

4 questions

A cinema sets X=1X = 1 if a booking is made online, which happens with probability 0.40.4, and X=0X = 0 if it is made at the desk. The number of tickets YY in a booking, from 11 to 33, has these conditional PMFs given each XX, with one entry missing:

yy112233
pY∣X(y∣0)p_{Y \mid X}(y \mid 0)0.50.50.250.250.250.25
pY∣X(y∣1)p_{Y \mid X}(y \mid 1)0.40.4?0.150.15

What is p(1,2)p(1, 2)?

Select the correct answer:

+ 3 more questions · unlocked with a subscription

Memory is built by recalling, not by reading.

Every time you pull an answer from memory, the memory gets stronger. Reading doesn't do that. Nodeledge asks you questions on every step of every lesson, then asks again after days, weeks and months.

Get full access

£29/month or £249/year · 30-day money-back guarantee

See the learning path