class: center, middle, inverse, title-slide # Bayes Theorem ## Applied To Data Analysis ### Andy Grogan-Kaylor ### University of Michigan ### 2022-03-10 --- <style type="text/css"> @import url('https://fonts.googleapis.com/css2?family=Montserrat&display=swap'); .title-slide { color: #ffcb05; background-color: #00274C; } .title-slide h1 { color: #ffcb05; } pre { white-space: pre-wrap; } h1, h2, h3 { font-family: 'Montserrat', sans-serif; } body { font-family: 'Montserrat', sans-serif; } .author, .date { font-family: 'Montserrat', sans-serif; } blockquote { border-left: 5px solid #ffcb05; margin: 1.5em 10px; padding: 0.5em 10px; } </style> # How To Navigate This Presentation * Use the <span style="font-size:100px">⇦</span> and <span style="font-size:100px">⇨</span> keys to move through the presentation. * Press *o* for *panel overview*. --- class: animated, fadeIn # Derivation -- | | D=1 | D=0 | |:--------------|:---------------------|:--------------------------------| | H=1 | `\(P(D, H)\)` | `\(P(\text{not} D, H)\)` | | H=0 | `\(P(D, \text{not} H)\)` | `\(P(\text{not} D, \text{not} H)\)` | -- From the definition of conditional probability: -- `\(P(D|H) = P(D,H) / P(H)\)` -- `\(P(H|D) = P(D,H) / P(D)\)` --- class: animated, fadeIn # Then: -- `\(P(D|H)P(H) = P(D,H)\)` -- `\(P(H|D)P(D) = P(D,H)\)` -- # Then: `\(P(D|H)P(H) = P(H|D)P(D)\)` --- class: animated, fadeIn # Bayes Theorem: `\(P(H|D) = \frac{P(D|H) P(H)}{P(D)}\)` -- # In Words: `\(\text{posterior} \propto \text{likelihood} \times \text{prior}\)` --- class: animated, fadeIn # Example Consider an example using 1,000 hypothetical studies. We imagine that only 10% of interventions are likely to have results. We adopt standard assumptions of adopting an `\(\alpha\)`, or chance of detecting an effect when one is not there of 5%. We similarly assume 80% power `\(\beta\)`, or a 20% chance of failing to detect an effect when it is not present. -- | Data (D) | D=1 (effect) | D=0 (no effect) | |:-------------------------|:--------------------|:-------------------| | Hypothesis (H) | 100 effects | 900 non-effects | | H=1 (conclude effect) | 80 true positives | 45 false positives | | H=0 (conclude no effect) | 20 false negatives | 855 true negatives | -- > With thanks to the [Wikipedia article](https://en.wikipedia.org/wiki/Bayes%27_theorem#Cancer_rate) on this topic for inspiration for this example. --- class: animated, fadeIn, center, top # Visualization <img src="Bayes-theorem-applied-to-data-analysis_files/figure-html/unnamed-chunk-3-1.png" width="80%" /> --- class: animated, fadeIn # Calculations -- `$$P(\text{H=1} | \text{D=1}) = \frac{P(\text{D=1} | \text{H=1}) P(\text{H=1})}{P(\text{D})}$$` -- `$$=\frac{P(\text{D=1} | \text{H=1}) P(\text{H=1})}{P(\text{D=1} | \text{H=1}) P(\text{H=1}) + P(\text{D=0} | \text{H=1}) P(\text{H=1})}$$` -- `$$P(\text{H=1} | \text{D=1}) = \frac{.8 \times .1}{.08 + .045} = .64$$` -- > See also [Thinking Through Bayesian Ideas](https://agrogan.shinyapps.io/Thinking-Through-Bayes/) --- class: animated, fadeIn # Discussion -- * Calculations suggest that a true effect is likely in 64% of the cases where one concludes the presence of an effect. -- * Consequently, calculations suggest that 36% of the time, when one concludes there is an effect, there is actually no effect. -- * Put another way, despite setting `\(\alpha = .05\)`, 36% of cases result in a false positive. -- * Notice how the Bayesian approach lets us estimate the probability of different hypotheses given the data. In some cases, this may afford us the opportunity to accept our null hypothesis `\(H_0\)`.