Interactive: Joint Distribution Simulation
The table on the left defines the True Probability model. Use the buttons to sample "events" (phone calls) to populate the Empirical Frequency table on the right. Notice how the empirical values converge to the true probabilities as $N$ increases (Law of Large Numbers).
True Probability P(X, Y)
Y\X
x=1
x=2
x=3
P(Y)
y=4
0.15
0.10
0.05
0.30
y=3
0.02
0.10
0.05
0.17
y=2
0.02
0.03
0.20
0.25
y=1
0.01
0.02
0.25
0.28
P(X)
0.20
0.25
0.55
Sum=1
Controls
Total N: 0
Empirical Frequency
Y\X
x=1
x=2
x=3
P(Y)
y=4
0.00
0.00
0.00
0.00
y=3
0.00
0.00
0.00
0.00
y=2
0.00
0.00
0.00
0.00
y=1
0.00
0.00
0.00
0.00
P(X)
0.00
0.00
0.00
N=1
Sum & Product Rules
Example: Is the robot hearing the command?
Suppose a robot is in 'Attentive Listening Mode' ($L=1$) with probability $P(L=1) = 0.7$. If it is listening attentively, there is a 90% chance it hears a command ($H=1$), so $P(H=1|L=1) = 0.9$. If it is not listening attentively ($L=0$), there is still a 10% chance it hears the command, $P(H=1|L=0) = 0.1$.
Theorem:
Bayes' Theorem
$$P(Y|X) = \frac{P(X|Y)\ P(Y)}{P(X)}$$
Example: Medical Diagnosis
Let $Y=1$ denote having a rare disease and $Y=0$ denote not having it. The prevalence of the disease is $P(Y=1) = 0.001$ (Prior).
We have a test where $X=1$ is a positive result and $X=0$ is negative. The test is accurate but not perfect:
- Sensitivity: $P(X=1 | Y=1) = 0.99$ (True Positive Rate)
- Specificity: $P(X=0 | Y=0) = 0.95$ (True Negative Rate)
We have a test where $X=1$ is a positive result and $X=0$ is negative. The test is accurate but not perfect:
- Sensitivity: $P(X=1 | Y=1) = 0.99$ (True Positive Rate)
- Specificity: $P(X=0 | Y=0) = 0.95$ (True Negative Rate)
Interactive Bayes' Theorem Simulation
1. Set Priors $P(Y)$
(Computed)
$P(Y=0) = 1 - P(Y=1)$
2. Set Likelihoods $P(X|Y)$
| Latent Y | X=0 (Comp) | X=1 | X=2 |
|---|---|---|---|
| Y=0 | |||
| Y=1 |
$P(X=0|Y) = 1 - P(X=1|Y) - P(X=2|Y)$
Can you come up with a scenario where the posterior for a value of $Y$ is 10 times higher than the prior?
What does Bayes' rule say if the two variables it is applied to are independent?