Exercises used in this discussion session are from [the Bayes Rules! book](https://www.bayesrulesbook.com/)
```{r}
#| echo: false
library(bayesrules)
```
## Discussion Session Week 4
## Exercise 4.17 (Different data, different posteriors)
A shoe company develops a new internet ad for their latest sneaker. Three employees share the same Beta(4, 3) prior model for $\pi$, the probability that a user will click on the ad when shown. However, the employees run three different studies, thus each has access to different data. The first employee tests the ad on 1 person – they do not click on the ad. The second tests 10 people, 3 of whom click on the ad. The third tests 100 people, 20 of whom click on the ad.
- Sketch the prior pdf using **plot_beta()**. Describe the employees’ prior understanding of the chance that a user will click on the ad.
- Specify the unique posterior model of $\pi$ for each of the three employees.
- Plot the prior pdf, likelihood function, and posterior pdf for each employee.
- Summarize and compare the employees’ posterior models of $\pi$.
## Exercise 4.18 (A sequential employee)
The shoe company described in Exercise 4.17 brings in a fourth employee. They start with the same Beta(4, 3) prior for $\pi$ as the first three employees but, not wanting to re-create work, don’t collect their own data. Instead, in their first day on the job, the new employee convinces the first employee to share their data. On the second day they get access to the second employee’s data and on the third day they get access to the third employee’s data.
- Suppose the new employee updates their posterior model of $\pi$ at the end of each day. What’s their posterior at the end of day one? At the end of day two? At the end of day three?
- Sketch the new employee’s prior and three (sequential) posteriors. In words, describe how their understanding of $\pi$ evolved over their first three days on the job.
- Suppose instead that the new employee didn’t update their posterior until the end of their third day on the job, after they’d gotten data from all three of the other employees. Specify their posterior model of $\pi$ and compare this to the day three posterior from part (a).
## Exercise 5.5 (Text messages)
Let random variable $\lambda$ represent the rate of text messages people receive in an hour. At first, you believe that the typical number of messages per hour is 5 with a standard deviation of 0.25 messages.
- Tune and plot an appropriate Gamma(s, r) prior model for $\lambda$.
- What is the prior probability that the rate of text messages per hour is larger than 10? Hint: learn about **pgamma()**.
## Exercise 5.6 (Text messages with data)
Continuing with Exercise 5.5, you collect data from six friends. They received 7, 3, 8, 9, 10, 12 text messages in the previous hour.
- Plot the resulting likelihood function of $\lambda$.
- Plot the prior pdf, likelihood function, and the posterior pdf of $\lambda$.
- Use **summarize_gamma_poisson()** to calculate descriptive statistics for the prior and the posterior models of $\lambda$.
- Comment on how your understanding about $\lambda$ changed from the prior (in the previous exercise) to the posterior based on the data you collected from your friends.