class: title-slide <br> <br> .right-panel[ # Beta Prior ## Dr. Mine Dogucu Examples from [bayesrulesbook.com](https://bayesrulesbook.com) ] --- ## Back to Graduate School Applications Last lecture we were trying to understand `\(\pi\)` the acceptance rate of a graduate program in a specific department. Let's make a fresh start to the same problem. This time we will let `\(\pi \in [0,1]\)`. --- **Continuous probability models** Let `\(\pi\)` be a continuous random variable with pdf `\(f(\pi)\)`. Then `\(f(\pi)\)` has the following properties: - `\(\int_\pi f(\pi)d\pi = 1\)`, ie. the area under `\(f(\pi)\)` is 1 - `\(f(\pi) \ge 0\)` - `\(P(a < \pi < b) = \int_a^b f(\pi) d\pi\)` when `\(a \le b\)` Interpreting `\(f(\pi)\)`: `\(f(\pi)\)` can be used to _compare_ the plausibility of two different values of `\(\pi\)`. --- ## Plotting the continuous prior For each of the student's prior ideas for `\(\pi\)` plot the pdf of the prior. Your plot will not be exact since no exact values are given. Morteza thinks that it is extremely difficult to get into this program. Jared thinks that it is difficult to get into this program. Erin does not have any strong opinions whether it is difficult or easy to get into this program. Xuan thinks that it is easy to get into this program. Beyoncé thinks that it is extremely easy to get into this program. --- ## Morteza's prior <img src="slide-02b-beta-prior_files/figure-html/unnamed-chunk-2-1.png" style="display: block; margin: auto;" /> --- ## Jared's prior <img src="slide-02b-beta-prior_files/figure-html/unnamed-chunk-3-1.png" style="display: block; margin: auto;" /> --- ## Erin's prior <img src="slide-02b-beta-prior_files/figure-html/unnamed-chunk-4-1.png" style="display: block; margin: auto;" /> --- ## Xuan's prior <img src="slide-02b-beta-prior_files/figure-html/unnamed-chunk-5-1.png" style="display: block; margin: auto;" /> --- ## Beyoncé's prior <img src="slide-02b-beta-prior_files/figure-html/unnamed-chunk-6-1.png" style="display: block; margin: auto;" /> --- ## Beta Prior model Let `\(\pi\)` be a random variable which can take any value between 0 and 1, ie. `\(\pi \in [0,1]\)`. Then the variability in `\(\pi\)` might be well modeled by a Beta model with __shape parameters__ `\(\alpha > 0\)` and `\(\beta > 0\)`: `$$\pi \sim \text{Beta}(\alpha, \beta)$$` The Beta model is specified by continuous pdf `\begin{equation} f(\pi) = \frac{\Gamma(\alpha + \beta)}{\Gamma(\alpha)\Gamma(\beta)} \pi^{\alpha-1} (1-\pi)^{\beta-1} \;\; \text{ for } \pi \in [0,1] \end{equation}` where `\(\Gamma(z) = \int_0^\infty y^{z-1}e^{-y}dy\)` and `\(\Gamma(z + 1) = z \Gamma(z)\)`. Fun fact: when `\(z\)` is a positive integer, then `\(\Gamma(z)\)` simplifies to `\(\Gamma(z) = (z-1)!\)`. --- ## Beta Prior model .pull-left[ <img src="slide-02b-beta-prior_files/figure-html/unnamed-chunk-7-1.png" style="display: block; margin: auto;" /> ] .pull-right[ `\(\pi \sim \text{Beta}(3, 8)\)` `\(f(\pi) = \frac{\Gamma(\alpha + \beta)}{\Gamma(\alpha)\Gamma(\beta)} \pi^{\alpha-1} (1-\pi)^{\beta-1}\)` `\(f(\pi) = \frac{\Gamma(3 + 11)}{\Gamma(3)\Gamma(8)} 0.5^{3-1} (1-0.5)^{8-1}\)` `\(f(\pi) = \frac{13!}{2!7!} 0.5^{3-1} (1-0.5)^{8-1}\)` `\(f(\pi) = 0.703125\)` ] --- ## Beta Prior model `\(\pi \sim \text{Beta}(3, 8)\)` .pull-left[ <img src="slide-02b-beta-prior_files/figure-html/unnamed-chunk-8-1.png" style="display: block; margin: auto;" /> ] .pull-right[ ```r dbeta(x = 0.5, shape1 = 3, shape2 = 8) ``` ``` ## [1] 0.703125 ``` ] --- ## Plotting Beta Prior <img src="slide-02b-beta-prior_files/figure-html/unnamed-chunk-10-1.png" style="display: block; margin: auto;" /> --- ## Plotting Beta Prior with `bayesrules` package Use the `plot_beta()` function in the `bayesrules` package to try different shape parameters. Example: ```r plot_beta(alpha = 5, beta = 7) ``` <img src="slide-02b-beta-prior_files/figure-html/unnamed-chunk-12-1.png" style="display: block; margin: auto;" /> --- ## Beta Descriptives `$$E(\pi) = \frac{\alpha}{\alpha + \beta}$$` `$$\text{Mode}(\pi) = \frac{\alpha - 1}{\alpha + \beta - 2}$$` `$$\text{Var}(\pi) = \frac{\alpha \beta}{(\alpha + \beta)^2(\alpha + \beta + 1)}$$` --- ## Beta Descriptives with `bayesrules` package Use the `summarize_beta()` function in the `bayesrules` package to find the mean, mode, and variance of various Beta distributions. Example: ```r summarize_beta(alpha = 5, beta = 7) ``` ``` ## mean mode var ## 1 0.4166667 0.4 0.01869658 ```