Last week:
Today: continue building up Bayesian concepts
install.packages() function.| Region | M | N | S | W | Total |
|---|---|---|---|---|---|
| Probability | 0.21 | 0.17 | 0.38 | 0.24 | 1 |
| Region | M | N | S | W | Total |
|---|---|---|---|---|---|
| Probability | 0.21 | 0.17 | 0.38 | 0.24 | 1 |
During the opening scene, the main character asks someone if they would like a “Pop”.
What is the probability that the main character is from the South?
| Region | M | N | S | W | Total |
|---|---|---|---|---|---|
| Probability | 0.21 | 0.17 | 0.38 | 0.24 | 1 |
During the opening scene, the main character asks someone if they would like a “Coke”.
What is the probability that the main character is from the South?
pop_vs_soda dataset to explore the relationship between region (region) and whether people say “pop” or “soda” when referring to carbonated beverages (pop).pop_vs_soda dataset to explore the relationship between region (region) and whether people say “pop” or “soda” when referring to carbonated beverages (pop).| pop | midwest | northeast | south | west |
|---|---|---|---|---|
| 0 | 0.36 | 0.73 | 0.92 | 0.71 |
| 1 | 0.64 | 0.27 | 0.08 | 0.29 |
| Region | M | N | S | W | Total |
|---|---|---|---|---|---|
| Prior probability | 0.21 | 0.17 | 0.38 | 0.24 | 1 |
| Posterior probability |
| Region | M | N | S | W | Total |
|---|---|---|---|---|---|
| Prior probability | 0.21 | 0.17 | 0.38 | 0.24 | 1 |
| Posterior probability | 0.4791 | 0.1645 | 0.1065 | 0.2499 | 1 |
In 1996, Gary Kasparov played a six-game chess match against the IBM supercomputer Deep Blue.
Kasparov and Deep Blue were to meet again for a six-game match in 1997.
Let \pi denote Kasparov’s chances of winning any particular game in the re-match.
| \pi | 0.2 | 0.5 | 0.8 | Total |
|---|---|---|---|---|
| f(\pi) | 0.10 | 0.25 | 0.65 | 1 |
| \pi | 0.2 | 0.5 | 0.8 | Total |
|---|---|---|---|---|
| f(\pi) | 0.10 | 0.25 | 0.65 | 1 |
In the second step of our analysis, we collect and process data which can inform our understanding of \pi.
Here, Y = the number of the six games in the 1997 re-match that Kasparov wins.
Note that Y inherently depends upon \pi.
Thus, we must model this dependence of Y on \pi using a conditional probability model.
Y|\pi \sim \text{Bin}(6, \pi)
Let’s assume \pi = 0.8.
The probability that he would win all 6 games is approximately 26%.
f(y=6|\pi=0.8) = {6 \choose 6} 0.8^6 (1-0.8)^{6-6},
Let’s assume \pi = 0.8.
The probability that he would win none of the games is approximately 0%.
f(y=0|\pi=0.8) = {6 \choose 0} 0.8^0 (1-0.8)^{6-0},
Note that the Binomial gives us the theoretical model of the data we might observe.
Next, we determine how compatible this particular data is with the various possible values of \pi.
Recall, f(y|\pi) = L(\pi|Y=y). When Y=1,
\begin{align*} L(\pi | y = 1) &= f(y=1|\pi) \\ &= {6 \choose 1} \pi^1 (1-\pi)^{6-1} \\ &= 6\pi(1-\pi)^5 \end{align*}
| \pi | 0.2 | 0.5 | 0.8 |
|---|---|---|---|
| L(\pi|y=1) |
| \pi | 0.2 | 0.5 | 0.8 |
|---|---|---|---|
| L(\pi|y=1) | 0.3932 | 0.0938 | 0.0015 |
\begin{align*} f(y=1) =& \sum_{\pi} L(\pi |y=1)f(\pi) \\ =& L(\pi=0.2|y=1)f(\pi=0.2) + L(\pi=0.5|y=1)f(\pi=0.5) + \\ & L(\pi=0.8|y=1)f(\pi=0.8) \end{align*}
\begin{align*} f(y=1) =& \sum_{\pi} L(\pi |y=1)f(\pi) \\ =& L(\pi=0.2|y=1)f(\pi=0.2) + L(\pi=0.5|y=1)f(\pi=0.5) + \\ & L(\pi=0.8|y=1)f(\pi=0.8) \\ \approx& 0.3932 \cdot 0.10 + 0.0938 \cdot 0.25 + 0.0015 \cdot 0.65 \\ \approx& 0.0637 \end{align*}
\text{posterior} = \frac{\text{prior} \times \text{likelihood}}{\text{normalizing constant}}
f(\pi | y=1) = \frac{f(\pi) L(\pi | y = 1)}{f(y=1)} \ \text{for} \ \pi \in \{ 0.2, 0.5, 0.8\}
Work with your group to find the posterior probabilities.
Note!! We do not have to calculate the normalizing constant!
We can treat f(Y=y) as a constant with respect to \pi.
Then, we say that
\begin{align*} f(\pi | y) &= \frac{f(\pi) L(\pi|y)}{f(y)} \\ & \propto f(\pi) L(\pi|y) \\ \\ \text{posterior} &\propto \text{prior} \cdot \text{likelihood} \end{align*}
Today we learned how to, in general, approach Bayesian analysis.
You now are ready to work on Assignment 1: Thinking Like a Bayesian.
Wednesday: Beta-binomial
Next week:
STA6349 · Applied Bayesian Analysis · Fall 2026