1.3.13 · D4Probability & Statistics

Exercises — Joint, marginal, and conditional distributions

2,067 words9 min readBack to topic

We will reuse one running table so the numbers stay concrete. Here it is — a joint pmf over (a disease flag, = healthy, = sick) and (a test result, = negative, = positive):

Row sum
(healthy)
(sick)
Col sum

Every entry is and they sum to , so this is a legal joint distribution. Every cell is a "little box" counting how often that combination happens.

Figure — Joint, marginal, and conditional distributions

Level 1 — Recognition

Goal: name the object and read it straight off the table. No re-normalizing yet.

Exercise 1.1

From the table, write down the value of the joint probability and say in one sentence what it means.

Recall Solution 1.1

WHAT: read the cell in row , column . Meaning: the probability that a random person is both sick and tests positive is . This is a raw count-fraction over everyone, not restricted to any subgroup.

Exercise 1.2

Which numbers in the table are marginals of , and which are marginals of ? Write and .

Recall Solution 1.2

WHY margins: the row totals live in the right margin, the column totals in the bottom margin — that is literally where the name comes from.

  • Marginals of = the two row sums: .
  • Marginals of = the two column sums: .

So and .

Exercise 1.3

Is the expression a joint, a marginal, or a conditional probability? Name it exactly.

Recall Solution 1.3

It is a conditional: joint cell divided by the marginal . By the definition this is — "of the people who tested positive, what fraction are sick?" We slice to the positive column, then divide by its total.


Level 2 — Application

Goal: run the marginal / conditional / product formulas end-to-end.

Exercise 2.1

Compute the full conditional distribution — i.e. the test-result distribution among sick people — and verify it sums to .

Recall Solution 2.1

WHAT / WHY: fix (the sick row: and ). That row sums to , not , so we divide by to re-normalize into a valid distribution. Check: . ✓ Among the sick, test positive (the test's sensitivity).

Exercise 2.2

Compute .

Recall Solution 2.2

Slice the positive column ( and ), whose total is , then take the sick fraction: So a positive test raises sick-probability from the base rate up to about .

Exercise 2.3

Use the product rule to reconstruct the joint cell from and , confirming it matches the table.

Recall Solution 2.3

Product rule: . This is the inverse move of Exercise 2.1: we sliced-then-divided to get ; multiplying by the marginal puts the cell back.


Level 3 — Analysis

Goal: reason about structure — dependence, direction of the bar, degenerate cases.

Exercise 3.1

Are and independent in this table? Justify with the factorization test.

Recall Solution 3.1

Independence requires for every cell. Test the cell: , so the factorization fails on this cell ⇒ dependent. (One failing cell is enough to break independence.) This matches Independence and conditional independence: knowing the test is positive really does change the sick-probability from to .

Exercise 3.2 (the prosecutor's fallacy)

You found . Now compute and explain why they differ.

Recall Solution 3.2

They differ ( vs ) because the denominators differ: one normalizes over the positive column (), the other over the sick row (). Swapping the bar swaps which marginal you divide by. To convert one into the other you need Bayes' theorem:

Exercise 3.3 (degenerate case)

Suppose instead a new column had (nobody ever tests negative). Explain what happens to and why the definition guards against it.

Recall Solution 3.3

The conditional would be undefined. That is exactly why the definition carries the condition . What it looks like: you are trying to slice a strip that has zero total probability — there is no population to re-normalize, so the question "of the negatives, how many are sick?" is meaningless when there are no negatives. The formula is simply not applicable there.


Level 4 — Synthesis

Goal: combine marginalizing, Bayes, and continuous integration in one problem.

Exercise 4.1 (law of total probability)

A factory has two machines. Machine makes of parts with a defect rate; machine makes with a defect rate. Find the overall defect probability , then .

Recall Solution 4.1

Let be the machine, = defective. Given: , . Marginalize away (this is Marginalization and the law of total probability): Then Bayes to reverse the bar: So even though makes most parts, only of defects come from it — because is the cleaner machine.

Exercise 4.2 (continuous joint)

Let on the unit square . (a) Confirm it is a valid pdf. (b) Find the marginal . (c) Find the conditional . (d) Are independent?

Recall Solution 4.2

(a) Valid? A pdf must be (it is, on the square) and integrate to : (b) Marginal of — integrate away: (c) Conditional of given — slice then divide: (d) Independent? The conditional still depends on , so knowing changes the shape of 's distribution ⇒ dependent. Equivalently . Contrast with the parent's example, which did factor.


Level 5 — Mastery

Goal: prove a general statement and connect to a real ML model.

Exercise 5.1 (Naive Bayes with two features)

A spam filter treats two word-features as conditionally independent given the label (spam/ham). Given , , , , compute .

Recall Solution 5.1

Conditional independence given (see Naive Bayes classifier) means the joint feature likelihood factors: Unnormalized scores (numerator of Bayes = likelihood × prior): Normalize (the denominator is their sum — marginalizing the label away): The two "free-ish" words together push spam-probability from a prior up to about .

Exercise 5.2 (general proof)

Prove that if for some non-negative functions (a separable joint), then and are independent — even if are not themselves normalized.

Recall Solution 5.2

Let and . Since the joint sums to : Marginals: Product of marginals: So the joint factors into the marginals ⇒ independent. The lesson: independence only needs the joint to split into a product of a pure- piece and a pure- piece — the normalizing constants sort themselves out. (This is why was independent but was not: can't be written .)


Answer key (quick check)

Reveal-style facts to self-test:

Ex 1.1 value of
Ex 2.1 (sensitivity)
Ex 2.2
Ex 3.2
Ex 4.1 overall defect rate
Ex 4.1
Ex 4.2b marginal
Ex 5.1

Connections

  • Bayes' theorem — used in Ex 3.2, 4.1, 5.1 to reverse the conditioning bar.
  • Marginalization and the law of total probability — the denominator in Ex 4.1 and 5.1.
  • Independence and conditional independence — Ex 3.1, 4.2d, 5.2.
  • Naive Bayes classifier — Ex 5.1's conditional-independence assumption.
  • Covariance and correlation — the L3 "uncorrelated ≠ independent" trap.
  • Probabilistic graphical models — which conditionals may be assumed to factor.
  • Expectation and variance — the counterexample uses moments.