Conditional distributions and simulation from conditional distributions via rejection sampling
A random variable represents a numerical outcome that is not yet known. We use a capital letter, such as \(X\), for the random variable and a lowercase letter, such as \(x\), for a possible value.
A random vector collects several random variables, such as \((X,Y)\).
For example, \(X\) might indicate whether a person has a disease, and \(Y\) might indicate whether their test is positive.
The pair \((X,Y)\) records both outcomes for the same person.
A probability law, or distribution, specifies the probabilities of events involving a random variable or random vector.
For a single random variable, these might be probabilities such as
\[ P(X=1) \qquad \text{or} \qquad P(a<X\le b). \]
For a random vector, we call its distribution a joint distribution. It specifies probabilities of simultaneous statements about its components, such as
\[ P(X=1,\ Y=1). \]
The distribution of one component of a random vector considered by itself is its marginal distribution.
The joint distribution of \((X,Y)\) tells us how likely different combinations of \(X\) and \(Y\) are.
The marginal distribution of \(X\) tells us how likely different values of \(X\) are, regardless of the value of \(Y\).
To simulate from this marginal distribution, generate \((X,Y)\) jointly and keep only \(X\) from every run.
Suppose we have partial information about the outcome of a random variable.
How can we use that to update our understanding of what values the random variable can take?
“Partial information” is interpreted as “we know the random variable/random vector’s value falls in a certain set.”
Suppose \(X\) is a discrete random variable (or or discrete random vector), \(E\) is some subset of the values \(X\) can take, and \(\Pr(X \in E) > 0\).
Then the conditional distribution of \(X\) given \(X \in E\) is a new probability distribution, denoted \(X \mid X \in E\) (the distribution of \(X\) given \(X \in E\)).
The probabilities it assigns to possible outcomes are
\[\begin{align*} \Pr(X=x\mid X \in E) &=\frac{\Pr(X=x\text{ and }X \in E)}{\Pr(X \in E)} \\ &= \begin{cases} \frac{\Pr(X = x)}{ \Pr(X \in E)} & x \in E \\ 0 & x \not \in E \end{cases}. \end{align*}\]
Suppose we are modeling the cessation of the nausea and vomiting of pregnancy.
We will formalize this by saying that the random variable \(R\) describes the week of cessation of symptoms, with allowable values and probabilities given in the table below
| Gestational age when symptoms ceased | value of \(R\) | Probability |
|---|---|---|
| By 8 weeks | R = 7 | 0.082 |
| After 8, by 9 weeks | R = 8 | 0.092 |
| After 9, by 10 weeks | R = 9 | 0.099 |
| After 10, by 11 weeks | R = 10 | 0.151 |
| After 11, by 12 weeks | R = 11 | 0.175 |
| After 12, by 13 weeks | R = 12 | 0.086 |
| After 13, by 14 weeks | R = 13 | 0.110 |
| After 14, by 15 weeks | R = 14 | 0.072 |
| After 15, by 16 weeks | R = 15 | 0.041 |
| After 16 weeks | R = 16 | 0.092 |
Numbers from: Gadsby, Barnie-Adshead & Jagger (1993), Table 1.
Suppose that the woman is experiencing symptoms at the beginning of week 14.
What is the chance her symptoms will end before the beginning of week 15?
This is a question about the conditional distribution of \(R \mid R \in E\), where \(E\) is the set \(\{14, 15,16\}\).
If we work this out, \(P(R \in E) = .072 + .041 + .092 = .205\).
The possible values for the conditional distribution are \(14, 15, 16\), and their conditional probabilities are
Suppose we have a test for a disease. In this hypothetical example:
We select a person at random from this population and they test positive.
What is the probability that they have the disease?
Let \(D\) indicate whether the randomly selected person has the disease:
Let \(T\) be the result of the test:
The previous page allows us to write down the joint distribution of the random vector \((D,T)\). The probabilities of all four combinations are:
| Positive test (\(T = 1\)) | Negative test (\(T = 0\)) | Total | |
|---|---|---|---|
| Disease (\(D=1\)) | \(0.01\times0.90=0.009\) | \(0.01\times0.10=0.001\) | \(0.010\) |
| No disease (\(D=0\)) | \(0.99\times0.05=0.0495\) | \(0.99\times0.95=0.9405\) | \(0.990\) |
| Total | \(0.0585\) | \(0.9415\) | \(1\) |
A positive test tells us that \((D, T) \in E\), where \(E\) is the set \(\{(0,1), (1,1)\}\).
The conditional distribution of \((D, T) \mid (D, T) \in E\) can take only the values \((1,1)\) and \((0,1)\).
The corresponding probabilities are
Two teams play a best-of-five series. The first to win three games wins the series.
The first three games have been played:
What is the probability that Team A wins the series, given these results?
Let \(X_i\) indicate the outcome of game \(i\):
Let \(W\) indicate the series winner:
We describe the complete outcome using the random vector
\[ \mathbf{X}=(X_1,X_2,X_3,X_4,X_5,W). \]
For convenience, we include outcomes for all five games, even if the series ends earlier. Outcomes after one team has won three games do not affect the series winner.
Our model assigns probability \(1/32\) to each of the 32 possible five-game sequences.
Each sequence determines the winner: \(W=1\) if at least three game outcomes are \(1\), and \(W=0\) otherwise.
Thus, the augmented vector \(\mathbf{X}\) has 32 possible values, each with probability \(1/32\). For example:
| Value of \(\mathbf{X}\) | Probability |
|---|---|
| \((1,0,1,1,0,1)\) | \(1/32\) |
| \((1,0,1,0,0,0)\) | \(1/32\) |
| \((1,0,1,1,0,0)\) | \(0\) |
The last row is impossible: the game outcomes say A wins, but the recorded series winner says B wins.
Let \(E\) be the set of possible complete outcomes consistent with the three games we observed:
\[ E=\{ (1,0,1,0,0,0),\ (1,0,1,0,1,1),\ (1,0,1,1,0,1),\ (1,0,1,1,1,1) \}. \]
Knowing the results of the first three games tells us that \(\mathbf{X}\in E\).
We want the conditional distribution of the winner,
\[ W\mid\mathbf{X}\in E. \]
Each of the four vectors in \(E\) has probability \(1/32\) under the joint distribution.
| Game outcomes \((X_1,X_2,X_3,X_4,X_5)\) | Winner \(W\) | Joint probability |
|---|---|---|
| \((1,0,1,0,0)\) | 0 (B) | \(1/32\) |
| \((1,0,1,0,1)\) | 1 (A) | \(1/32\) |
| \((1,0,1,1,0)\) | 1 (A) | \(1/32\) |
| \((1,0,1,1,1)\) | 1 (A) | \(1/32\) |
Adding these probabilities gives
\[ P(\mathbf{X}\in E)=\frac{4}{32}. \]
There are three rows with \(W=1\) and one row with \(W=0\).
To obtain the conditional distribution, we restrict to outcomes in \(E\) and divide by their total probability:
\[ P(W=1\mid\mathbf{X}\in E) =\frac{3/32}{4/32} =\frac34, \]
\[ P(W=0\mid\mathbf{X}\in E) =\frac{1/32}{4/32} =\frac14. \]
Given the observed results A, B, A, Team A has a 75% chance of winning the series under this model.
Suppose we can simulate complete outcomes of \(X\), where \(X\) may be a random vector.
To draw from the conditional distribution of \(X\) given \(X \in E\), where \(\Pr(X \in E) > 0\):
This is rejection sampling. The accepted value will come from the desired conditional distribution.
To obtain a conditional distribution, we restrict to outcomes in \(E\) and rescale their probabilities to sum to one.
Rejection sampling implements this by simulating from the full distribution and keeping only simulated outcomes in \(E\).
| Conditional distribution | Simulation |
|---|---|
| Outcomes outside \(E\) have conditional probability zero | Discard draws outside \(E\) |
| Outcomes inside \(E\) retain their relative probabilities | Enforced by sampling from the marginal distribution |
| Example | Outcome \(X\) of one run | Keep runs where \(X \in E\) | Examine… |
|---|---|---|---|
| Pregnancy symptoms | \(R\) | \(R \in \{14, 15, 16\}\): symptoms end in week 14 or later | \(R\) |
| Disease test | \((D, T)\) | \((D,T) \in \{(0,1), (1,1)\}\): the test is positive | \(D\) |
| Best-of-five series | \(\mathbf{X}=(X_1,\dots,X_5,W)\) | The first three games are A, B, A | \(W\) |
We always examine the value of interest from the same run whose outcome was in \(E\).
Let’s implement this for the disease-testing example.
We could use the joint distribution described above directly, or we could write the joint as the following model:
\[\begin{align*} D&\sim\operatorname{Bernoulli}(0.01) \\ T&\sim \begin{cases} \operatorname{Bernoulli}(0.90), & \text{if } D=1,\\ \operatorname{Bernoulli}(0.05), & \text{if } D=0. \end{cases} \end{align*}\]
R
For the duration example, one run produces the cessation week \(R\) alone. Its distribution is the table from Example 1:
| \(r\) | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
|---|---|---|---|---|---|---|---|---|---|---|
| \(\Pr(R=r)\) | 0.082 | 0.092 | 0.099 | 0.151 | 0.175 | 0.086 | 0.110 | 0.072 | 0.041 | 0.092 |
We keep runs with \(R \in E\), where \(E = \{14, 15, 16\}\).
R
For the series example, one run plays all five games and records the winner, giving \(\mathbf{X}=(X_1,\dots,X_5,W)\):
\[\begin{align*} X_1, \dots, X_5 &\stackrel{\text{iid}}{\sim} \operatorname{Bernoulli}(1/2) \\ W &= \begin{cases} 1, & \text{if } X_1 + \dots + X_5 \geq 3,\\ 0, & \text{otherwise.} \end{cases} \end{align*}\]
We keep runs with \(\mathbf{X} \in E\): the first three games are A, B, A, that is, \((X_1, X_2, X_3) = (1, 0, 1)\).
R
Next we will use the same idea for Bayesian inference: generate a parameter and data together, then condition on the outcome falling in the set \(E\) of outcomes whose data match what we observed.
For students who have taken probability separately. We have not developed all the background needed to justify these steps in this class. You are not expected to reproduce this proof.
Run independent copies of the simulator. Write \(X_i\) for the outcome of run \(i\), let \(p=\Pr(X\in E)>0\), and let \(\tau\) be the first index with \(X_\tau\in E\). Since \(\Pr(\tau>n)=(1-p)^n\to0\), acceptance occurs almost surely.
For any set \(B\) of possible values of \(X\),
\[ \begin{aligned} \Pr(X_\tau\in B) &=\sum_{n=1}^{\infty}\Pr(\tau=n,\;X_n\in B)\\ &=\sum_{n=1}^{\infty}(1-p)^{n-1}\Pr(X\in B,\;X\in E)\\ &=\frac{\Pr(X\in B,\;X\in E)}{p} =\Pr(X\in B\mid X\in E). \end{aligned} \]
The first accepted draw therefore has exactly the desired conditional law.