class: center, middle, inverse, title-slide # The Gamma-Poisson Model ### Dr. Dogucu --- layout: true <div class="my-header"></div> <div class="my-footer"> From Bayes Rules! book Copyright © Drs. Alicia Johnson, Miles Ott & Mine Dogucu. <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a></div> --- class: middle ## Choosing a Prior Prior distribution depends on our current information. When choosing a prior we may consider - computational ease - interpretability --- ## Conjugate Priors Let `\(f(\theta)\)` be a prior distribution for parameter `\(\theta\)` from a particular distribution, and `\(L(\theta|x)\)` be the likelihood function. If the resulting posterior distribution `\(f(\theta|x)\)` is of the same family of distributions as the prior distribution, then the prior distribution is a conjugate prior for this likelihood. -- __Examples__ The Beta-Binomial Model - Beta is a conjugate prior for the Binomial Likelihood. -- The Gamma-Poisson Model -- The Normal-Normal Model --- ## Non-Conjugate Prior for Binomial Likelihood $$f(\pi)=e-e^\pi\; \text{ for } \pi \in [0,1] $$ - Is this a valid pdf? - After observing 10 successes in 50 trials, calculate the posterior. --- ## The Question We are interested in modeling `\(\lambda\)` the rate of fraud risk calls received per day. We plan on collecting data on the number of fraud risk phone calls received each day. -- `\(\lambda\)` is a rate. `\(\lambda \geq 0\)` --- ## Gamma Prior We guess that we receive on average 3 calls per day and `\(\lambda\)` is somewhere between 2 and 4. -- Let `\(\lambda\)` be a random variable which can take any value between 0 and `\(\infty\)`, ie. `\(\lambda \in [0,\infty)\)`. Then the variability in `\(\lambda\)` might be well modeled by a Gamma model with __shape parameter__ `\(\alpha > 0\)` and __rate parameter__ `\(\beta > 0\)`: `$$\lambda \sim \text{Gamma}(\alpha, \beta)$$` -- The Gamma distribution is specified by continuous pdf `$$f(\lambda) = \frac{\beta^\alpha}{\Gamma(\alpha)} \lambda^{\alpha-1} e^{-\beta\lambda} \;\; \text{ for } \lambda \in [0,\infty)$$` --- ## Gamma Distribution What is `\(f(\lambda)\)` if `\(\lambda =1\)` and `\(\lambda \sim \text{Gamma}(2, 5)\)` ? ```r plot_gamma(shape = 2, rate = 5) ``` -- .pull-left[ <img src="slide-2-gamma-poisson_files/figure-html/unnamed-chunk-2-1.png" style="display: block; margin: auto;" /> ] .pull-right[ ```r dgamma(x = 1, shape = 2, rate = 5) ``` ``` ## [1] 0.1684487 ``` ] --- class: middle ## Descriptives of Gamma `\(E(\lambda) = \frac{\alpha}{\beta}\)` `\(\text{Mode}(\lambda) = \frac{\alpha - 1}{\beta} \text{ where } \alpha\ge1\)` `\(\text{Var}(\lambda) = \frac{\alpha}{\beta^2}\)` --- ## Gamma Tuning <img src="slide-2-gamma-poisson_files/figure-html/gamma-tuning-1.png" style="display: block; margin: auto;" /> --- ## Tuning Gamma example For our example on spam phone calls, set a prior for `\(\lambda\)` such that `\(E(\lambda) = 3\)` and `\(\lambda\)` most likely is between 2 and 4. You can use `plot_gamma()` function to try out different gamma distributions. -- ```r plot_gamma(12,4) ``` <img src="slide-2-gamma-poisson_files/figure-html/unnamed-chunk-4-1.png" style="display: block; margin: auto;" /> --- ## Poisson Likelihood We collect four days of data and receive 6, 2, 2, 1 spam calls each day. Write out the likelihood model. -- `$$L(\lambda | (x_1, \ldots, x_n))=\frac{e^{-n\lambda}\lambda^{\sum x_i}}{\prod x_i!}$$` --- ## Gamma- Poisson Conjugacy Based on the observed data how does our idea about `\(\lambda\)` change? Find the posterior. -- If `\(f(\lambda) \sim \text{Gamma}(\alpha, \beta)\)` and if `\(x_i \sim iid \text{ Poissson}(\lambda) \text{for } i \in 1,\ldots ,n\)` then `\(f(\lambda|\vec{x}) \sim \text{Gamma}(\alpha+ \sum x_i, \beta+n)\)`.