Exercise 1
Consider the following model,
- Prior: \(\theta \sim \text{Beta}(\alpha = 5, \beta = 5)\)
- Likelihood: \(X_1, X_1, \ldots, X_n \sim \text{Bern}(\theta)\)
- Posterior: \(\theta \mid X_1, X_1, \ldots, X_n \sim \ ?\)
and observed data with statistics,
- Sample size: \(n = 20\)
- Number of “successes” \(\sum x_i = 15\)
Use the given prior and the observed data to calculate a Bayes’ estimate of \(\theta\). (Use the posterior mean.)
Solution
- Recall that a Beta distribution with parameters \(\alpha\) and \(\beta\) has mean \(\frac{\alpha}{\alpha + \beta}\).
- The posterior distribution for the Beta-Bernoulli model is a Beta distribution with parameters \(a = \alpha + \sum x_i\) and \(b = \beta + \sum y_i\).
- Here we have, \(\sum y_i = n - \sum x_i\).
- Here we are using \(\alpha\) and \(\beta\) as the parameters for the prior, and \(a\) and \(b\) as the parameters of the posterior.
So, in this case, we have
\[
\theta \mid X_1, X_1, \ldots, X_n \sim \text{Beta}(a = 20, b = 10)
\]
Then we have
\[
\hat{\theta}_B = \frac{a}{a + b} = \frac{20}{20 + 10} = \boxed{\frac{2}{3}}
\]
Exercise 2
Consider the following model,
- Prior: \(\theta \sim \text{Beta}(\alpha = 50, \beta = 20)\)
- Likelihood: \(X_1, X_1, \ldots, X_n \sim \text{Bern}(\theta)\)
- Posterior: \(\theta \mid X_1, X_1, \ldots, X_n \sim \ ?\)
and observed data with statistics,
- Sample size: \(n = 40\)
- Number of “successes” \(\sum x_i = 32\)
Use the given prior and the observed data to calculate a Bayes’ estimate of \(\theta\). (Use the posterior mean.)
Solution
In this case, we have
\[
\theta \mid X_1, X_1, \ldots, X_n \sim \text{Beta}(a = 82, b = 28)
\]
Then we have
\[
\hat{\theta}_B = \frac{a}{a + b} = \frac{82}{82 + 28} = \boxed{\frac{41}{55}}
\]
Exercise 3
Consider the following model,
- Prior: \(\theta \sim \text{Beta}(\alpha = 10, \beta = 60)\)
- Likelihood: \(X_1, X_1, \ldots, X_n \sim \text{Bern}(\theta)\)
- Posterior: \(\theta \mid X_1, X_1, \ldots, X_n \sim \ ?\)
and observed data with statistics,
- Sample size: \(n = 5\)
- Number of “successes” \(\sum x_i = 2\)
Use the given prior and the observed data to calculate a Bayes’ estimate of \(\theta\). (Use the posterior mean.)
Solution
In this case, we have
\[
\theta \mid X_1, X_1, \ldots, X_n \sim \text{Beta}(a = 12, b = 63)
\]
Then we have
\[
\hat{\theta}_B = \frac{a}{a + b} = \frac{12}{12 + 63} = \boxed{\frac{4}{25}}
\]
Exercise 4
Consider the following model,
- Prior: \(\theta \sim \text{Beta}(\alpha = 10, \beta = 60)\)
- Likelihood: \(X_1, X_1, \ldots, X_n \sim \text{Bern}(\theta)\)
- Posterior: \(\theta \mid X_1, X_1, \ldots, X_n \sim \ ?\)
and observed data with statistics,
- Sample size: \(n = 5\)
- Number of “successes” \(\sum x_i = 2\)
Use the given prior and the observed data to calculate a 99% credible interval
Solution
qbeta(c(0.005, 0.995), shape1 = 10 + 2, shape2 = 60 + 3)
## [1] 0.06973818 0.28374039
Exercise 5
Consider the following model,
- Prior: \(\theta \sim \text{Beta}(\alpha = 4, \beta = 4)\)
- Likelihood: \(X_1, X_1, \ldots, X_n \sim \text{Bern}(\theta)\)
- Posterior: \(\theta \mid X_1, X_1, \ldots, X_n \sim \ ?\)
and observed data with statistics,
- Sample size: \(n = 5\)
- Number of “successes” \(\sum x_i = 2\)
Use the given prior and the observed data to calculate a 90% credible interval
Solution
qbeta(c(0.05, 0.95), shape1 = 4 + 2, shape2 = 4 + 3)
## [1] 0.2452998 0.6847622
Exercise 6
Consider the following model,
- Prior: \(\theta \sim \text{Beta}(\alpha = 10, \beta = 4)\)
- Likelihood: \(X_1, X_1, \ldots, X_n \sim \text{Bern}(\theta)\)
- Posterior: \(\theta \mid X_1, X_1, \ldots, X_n \sim \ ?\)
and observed data with statistics,
- Sample size: \(n = 50\)
- Number of “successes” \(\sum x_i = 2\)
Use the given prior and the observed data to calculate a 95% credible interval
Solution
qbeta(c(0.025, 0.975), shape1 = 10 + 2, shape2 = 4 + 48)
## [1] 0.1024842 0.2909709
Exercise 7
Consider the following model,
- Prior: \(\theta \sim \text{Beta}(\alpha = 10, \beta = 4)\)
- Likelihood: \(X_1, X_1, \ldots, X_n \sim \text{Bern}(\theta)\)
- Posterior: \(\theta \mid X_1, X_1, \ldots, X_n \sim \ ?\)
and observed data with statistics,
- Sample size: \(n = 50\)
- Number of “successes” \(\sum x_i = 20\)
Use the given prior and the observed data to test \(H_0: \theta > 0.50\) vs \(H_1: \theta \leq 0.50\)
Solution
pbeta(0.50, shape1 = 10 + 20, shape2 = 4 + 30, lower.tail = FALSE)
## [1] 0.3073275
pbeta(0.50, shape1 = 10 + 20, shape2 = 4 + 30)
## [1] 0.6926725
Accept \(H_1\).
Exercise 8
Consider the following model,
- Prior: \(\theta \sim \text{Beta}(\alpha = 10, \beta = 10)\)
- Likelihood: \(X_1, X_1, \ldots, X_n \sim \text{Bern}(\theta)\)
- Posterior: \(\theta \mid X_1, X_1, \ldots, X_n \sim \ ?\)
and observed data with statistics,
- Sample size: \(n = 20\)
- Number of “successes” \(\sum x_i = 5\)
Use the given prior and the observed data to test \(H_0: 0.25 < \theta < 0.50\) vs \(H_1: \theta \leq 0.25, \theta \geq 0.50\)
Solution
diff(pbeta(c(0.25, 0.50), shape1 = 10 + 5, shape2 = 10 + 15))
## [1] 0.9020704
Accept \(H_0\).
Exercise 9
Consider the following model,
- Prior: \(\theta \sim \text{Beta}(\alpha = 3, \beta = 3)\)
- Likelihood: \(X_1, X_1, \ldots, X_n \sim \text{Bern}(\theta)\)
- Posterior: \(\theta \mid X_1, X_1, \ldots, X_n \sim \ ?\)
and observed data with statistics,
- Sample size: \(n = 100\)
- Number of “successes” \(\sum x_i = 70\)
Use the given prior and the observed data to test \(H_0: \theta > 0.80\) vs \(H_1: \theta \leq 0.80\)
Solution
pbeta(0.80, shape1 = 3 + 70, shape2 = 3 + 30, lower.tail = FALSE)
## [1] 0.00374593
pbeta(0.80, shape1 = 3 + 70, shape2 = 3 + 30)
## [1] 0.9962541
Accept \(H_1\).