class: center, middle, inverse, title-slide # Bayesian Statistics for Undergraduate Learners ##
bit.ly/dogucu-talks
### Mine Dogucu ### 2021-04-20 --- class: middle center <img src="img/headshot.jpeg" alt="A headshot of a woman with curly, short, ear-length hair with green eyes and red lipstick." style="width:165px; margin-top:20px; border: 3px solid whitesmoke; padding: 10px;"> .large[
] <a href = "http://twitter.com/MineDogucu">MineDogucu</a> .large[
] <a href = "http://github.com/mdogucu">mdogucu</a> .large[
] <a href = "http://minedogucu.com">minedogucu.com</a> --- .center[ .pull-left[ <img src="img/ids-logo.png" alt="Introduction to Data Science Course Logo" style="width:215px; align:center; padding: 0px;"> [
](https://github.com/ics80-wi21)[
](https://introdata.science) <img src="img/stats68-logo.png" alt="Stats 68 Course Logo" style="width:215px; align:center; padding: 0px;"> [
](https://github.com/stats68-sp21)[
](https://stats68-sp21.netlify.app/) ] ] .center[ .pull-right[ <img src="img/stats295-logo.png" alt="Stats 295 (R) Course Logo" style="width:215px; align:center; padding: 0px;"> [
](https://github.com/stats295r-fa20)[
](https://www.scicompr.com/) <img src="img/stats-67-logo.svg" alt="67 Course Logo" style="width:215px; align:center; padding: 0px;"> [
](https://github.com/mdogucu/stats67-su20-website)[
](https://www.stats4cs.com/) ] ] --- class: center middle <img src="img/stats-115-logo.png" alt="Stats 115 Course Logo" style="width:215px; align:center; padding: 0px;"> [
](https://github.com/mdogucu/stats115-wi21-website)[
](https://www.stats115.com/) --- class: center middle .font-75[Background] --- ### Bayes Rules! An Introduction to Bayesian Modeling with R .center[ [
bayesrulesbook.com](https://www.bayesrulesbook.com/) ] .pull-left[ .center[ <img src="img/alicia.jpg" alt="A headshot of a woman with long blonde hair wearing a brownish yellow tshirt and a red and pink floral silk scarf wrapped around her neck." style="width:165px; margin-top:20px; border: 3px solid whitesmoke; padding: 10px;"> Alicia Johnson .font-20[Macalester College] [
](https://ajohns24.github.io/portfolio) [
](https://github.com/ajohns24) ] ] .pull-right[ .center[ <img src="img/miles.png" alt="A headshot of a man with short dark hair, and a dark moustache. He is wearing a blue button up shirt and dark gray jacket" style="width:165px; margin-top:20px; border: 3px solid whitesmoke; padding: 10px;"> Miles Ott .font-20[Smith College] [
](https://milesott.com/) [
](https://github.com/MilesOtt) [
](https://twitter.com/Miles_Ott) ] ] -- .pull-left[.footnote[All the examples in this talk are from Johnson, Ott & Dogucu (forthcoming) unless otherwise noted.]] --- class: middle <img src="img/bayes_diagram.png" width="50%" style="display: block; margin: auto;" /> --- class: middle ## Historical changes - Advances in computing -- - Departure from tradition -- - Reevaluation of subjectivity --- class: middle ### State of Bayesian Education at the Undergraduate Level -- - 7 courses / 50 liberal arts colleges - 47 courses / 102 universities -- Major examples: Statistics, Mathematics, Data Science, Computer Science, Actuarial Science, Cognitive Science, Economics, Geological and Planetary Sciences, Philosophy, Physics, Psychology, Political Science. -- Required courses: Duke (Statistical Science), UC Irvine (Data Science), Ohio State (Data Analytics), Virginia Tech (Statistics) .reference[(Dogucu & Hu, forthcoming)] --- class: center middle .font-75[STATS 115] --- class: middle ### Students' Background Prerequisite: STATS 120C. Introduction to Probability and Statistics III Recommended: STATS 110. Statistical Methods for Data Analysis I -- In practice: most of the enrolled students are Data Science majors thus take more statistics and computing courses. --- class: middle Fall 2017 (before UCI, graduate) Winter 2020 (in person) Summer 2020 II (virtual) Winter 2021 (virtual) --- class: middle ### Overview Weeks 1 - 4, Bayesian Foundations (Unit 1) -- <hr> Weeks 5 - 7, Posterior Simulation and Analysis (Unit 2) -- <hr> Week 8 - 10, Bayesian Regression and Classification (Unit 3) -- <hr> Not covered in STATS 115, Hierarchical Bayesian Models (Unit 4) --- class: center middle .font-75[Bayesian Foundations] --- class: middle (1) Zuofu claims that he can predict the outcome of a coin flip. To test his claim, you flip a fair coin 10 times and he correctly predicts all 10! (2) Kavya claims that she can distinguish natural and artificial sweeteners. To test her claim, you give her 10 sweetener samples and she correctly identifies each! In light of these experiments, what do you conclude? a. You’re more confident in Kavya’s claim than Zuofu’s claim. b. The evidence supporting Zuofu’s claim is just as strong as the evidence supporting Kavya’s claim. --- class: middle Suppose that during a recent doctor’s visit, you tested positive for a very rare disease. If you only get to ask the doctor one question, which would it be? a. What’s the chance that I actually have the disease? b. If in fact I don’t have the disease, what’s the chance that I would’ve gotten this positive test result? --- class: middle ## Bayesian Foundations - Bayes' Rule - The Beta-Binomial Model - Balance and Sequentially in Bayesian Analysis - Conjugate families --- class: middle ## Example Bechdel test for movies - the movie has to have at least two women in it; - these two women talk to each other; and - they talk about something besides a man. -- Let `\(\pi\)` represent the number of movies that pass the Bechdel test. -- <img src="index_files/figure-html/unnamed-chunk-3-1.png" style="display: block; margin: auto;" /> --- <img src="index_files/figure-html/unnamed-chunk-5-1.png" style="display: block; margin: auto;" /> --- class: center middle .font-75[Posterior Simulation and Analysis] --- class: middle ## Posterior Simulation and Analysis - Approximating the Posterior - Hypothesis Testing - Credible Intervals - Posterior Prediction --- class: middle ```r one_mh_iteration <- function(w, current){ # STEP 1: Propose the next chain location proposal <- runif(1, min = current - w, max = current + w) # STEP 2: Decide whether or not to go there proposal_plaus <- dnorm(proposal, 0, 1) * dnorm(6.25, proposal, 0.75) current_plaus <- dnorm(current, 0, 1) * dnorm(6.25, current, 0.75) alpha <- min(1, proposal_plaus / current_plaus) next_stop <- sample(c(proposal, current), size = 1, prob = c(alpha, 1-alpha)) # Return the results return(data.frame(proposal, alpha, next_stop)) } ``` --- ```r mh_tour <- function(N, w){ # 1. Start the chain at location 3 current <- 3 # 2. Initialize the simulation mu <- rep(0, N) # 3. Simulate N Markov chain stops for(i in 1:N){ # Simulate one iteration sim <- one_mh_iteration(w = w, current = current) # Record next location mu[i] <- sim$next_stop # Reset the current location current <- sim$next_stop } # 4. Return the chain locations return(data.frame(iteration = c(1:N), mu)) } ``` --- ```r set.seed(84735) mh_simulation_1 <- mh_tour(N = 5000, w = 1) ``` .pull-left[ ![](index_files/figure-html/unnamed-chunk-9-1.png)<!-- --> ] .pull-right[ ![](index_files/figure-html/unnamed-chunk-10-1.png)<!-- --> ] --- class: center middle .font-75[Bayesian Regression and Classification] --- class: middle - Normal regression - Logistic regression - Poisson and negative binomial regression - Naive Bayes classification - Model evaluation, and posterior prediction --- class: center middle .font-75[R packages] --- class: middle center .large[
] <a href = "http://github.com/dogucu/bayesrules">library(bayesrules)</a> ```r devtools::install_github("mdogucu/bayesrules") ``` --- .pull-left[ ```r plot_beta(alpha = 3, beta = 8) ``` <img src="index_files/figure-html/unnamed-chunk-12-1.png" style="display: block; margin: auto;" /> ] .pull-right[ ```r plot_beta(alpha = 10, beta = 2) ``` <img src="index_files/figure-html/unnamed-chunk-13-1.png" style="display: block; margin: auto;" /> ] --- ```r plot_beta_binomial(alpha = 3, beta = 8, y = 19, n = 20) ``` <img src="index_files/figure-html/unnamed-chunk-14-1.png" style="display: block; margin: auto;" /> --- class: middle ```r prediction_summary(y = bikes$rides, yrep = predictions) ``` ``` ## mae mae_scaled within_50 within_95 ## 1 989.8291 1.144095 0.44 0.968 ``` --- class: middle ## `library(rstan)` .pull-left[ ```r # STEP 1: DEFINE the model stan_bike_model <- " data { int<lower=0> n; vector[n] Y; vector[n] X; } parameters { real beta0; real beta1; real<lower=0> sigma; } model { Y ~ normal(beta0 + beta1 * X, sigma); } " ``` ] .pull-right[ ```r # STEP 2: SIMULATE the posterior stan_bike_sim <- stan(model_code = stan_bike_model, data = list(n = nrow(bikes), Y = bikes$rides, X = bikes$temp_feel), chains = 4, iter = 5000*2, seed = 84735) ``` ] --- class: middle ## `library(rstanarm)` ```r normal_model_sim <- stan_glm(rides ~ temp_feel, data = bikes, family = gaussian, chains = 4, iter = 5000*2, seed = 84735) ``` --- ### `library(bayesplot)` .pull-left[ ```r mcmc_trace(normal_model_sim, size = 0.1) ``` <img src="index_files/figure-html/unnamed-chunk-22-1.png" width="80%" style="display: block; margin: auto;" /> ] .pull-right[ ```r mcmc_dens_overlay(normal_model_sim) ``` <img src="index_files/figure-html/unnamed-chunk-23-1.png" width="80%" style="display: block; margin: auto;" /> ] --- ### `library(bayesplot)` ```r ppc_intervals(bikes$rides, yrep = predictions, x = bikes$temp_feel, prob = 0.5, prob_outer = 0.95) ``` <img src="index_files/figure-html/unnamed-chunk-24-1.png" width="30%" style="display: block; margin: auto;" /> --- class: middle ## Assessment - Quizzes - Homework - Project - Exams (midterm and final) --- class: middle ## Pedagogical Approach - Checking intuition -- - Active learning (quizzes and applications) -- - Computing & math together -- - Compute for a single case, then use built-in functions --- class: middle ## Accessibility and Inclusion - Open-Access -- - Visual access (color-palette and alternate text) -- - Citations -- - Datasets More on the topic is available on [DataPedagogy blog](https://www.datapedagogy.com/#category:Bayes_Rules!_book). --- class: middle - [Undergraduate Bayesian Education Resources](https://undergrad-bayes.netlify.app/) -- - [Undergraduate Bayesian Education Network](https://undergrad-bayes.netlify.app/network.html) -- - [USCOTS workshop](https://www.causeweb.org/cause/uscots/uscots21/workshop/4) --- class: middle center Questions? [bit.ly/dogucu-talks](https://bit.ly/dogucu-talks)