Last Updated: March 26, 2024 - Updated due date
Updated Due Date: April 11. 11:59 pm.
Please consult the syllabus about proper homework format, due date, and policy. For programming questions, you may use all of Pandas and Numpy, unless a problem states otherwise. Certain problems allow other packages and modules. You may not use packages and modules other than what is explicitly allowed.
Added: January 28, 2024
<aside>
⚠️ For this problem, you may use scipy.stats.beta, matplotlib.pyplot, numpy
</aside>
Let $K$ be the number of heads of flipping a biased coin $n$ times. Let $P$ be the probability that the coin comes up heads.
(2 pts.) In fact, $K$ is called a Binomial random variable with parameters $n$ and $p$, and write $K \sim \text{Binom}(n,P)$, which has a probability mass function:
$$ f_K(k) = \binom{n}{k}P^k(1-P)^{n-k} $$
Computing summary statistics from this PMF is difficult. Instead, using the summation above in part 1, derive the formulas for $\mathbb E[K]$ and $\text{Var}[K]$ for the Binomial distribution.
(3 pts.) Suppose we don’t know $P$, and instead treat it as a random variable. A reasonable distribution for $P$ is the Beta distribution, which has itself two parameters $\alpha, \beta$, that we’ll consider as integers for this problem. (Parameters like $\alpha, \beta$ describing distributions of a parameter $P$ of another distribution are often called hyperparameters.)
We then can write $P \sim \text{Beta}(\alpha, \beta)$. The Beta distribution has the PDF:
$$ f_P(p) = \begin{cases} c\cdot p^{\alpha-1}(1-p)^{\beta-1} & \text{ if } 0 < p < 1\\ 0 & \text{ otherwise} \end{cases} $$
where $c$ is a normalizing factor that depends on $\alpha, \beta$, given by the formula:
$$ c = \frac{(\alpha + \beta-1)!}{(\alpha-1)!(\beta-1)!} $$
Using Bayes’s theorem, argue that the posterior distribution $P\mid K$ for the bias $P$ given the number of heads $K$ after $n$ throws is also Beta distributed: $P\mid K \sim \text{Beta}(\alpha^\prime, \beta^\prime)$.
Hint: You can argue this by showing that the posterior PDF $f_{P\mid K}(p)$ satisfies:
$$ f_{P\mid K}(p) \propto p^{\alpha^\prime-1}(1-p)^{\beta^\prime-1} $$
What are $\alpha^\prime$ and $\beta^\prime$ in terms of $\alpha$ and $\beta$?
Suppose you toss the biased coin ten times, resulting in a total of seven heads. Assume a prior distribution $P \sim \text{Beta}(1, 1)$ for the coin’s bias.
spicy.stats.beta
module.(2 pts.) Let us now consider the impact of our prior assumption. Plot the prior and posterior distributions for the alternative priors $P \sim\text{Beta}(5,5)$, $P \sim \text{Beta}(2, 5)$ and $P\sim \text{Beta}(10, 2)$. Compare and contrast these priors and posteriors with the ones you obtained with the prior $P\sim \text{Beta}(1, 1)$.