class: center, middle, inverse, title-slide .title[ # Teaching Bayesian Modeling with
Bayes Rules! ] .subtitle[ ##
mdogucu.github.io/bayes-lund-2023
Talk at Bayes @ Lund ] .author[ ### Mine Dogucu, Ph.D.
University College London
University of California Irvine ] .date[ ### 2023-01-23 ] --- 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://minedogucu.com">minedogucu.com</a> .large[
] <a href = "http://github.com/mdogucu">mdogucu</a> .large[
] <a href = "http://twitter.com/MineDogucu">MineDogucu</a> .large[
] <a href = "https://mastodon.social/@MineDogucu">mastodon.social/@MineDogucu</a> --- class: middle We have reviewed curricula of **152 high ranking universities and colleges** in the United States and identified **51 Bayesian courses** at the undergraduate level. We have examined **prerequisites, majors, and course content** through catalog and syllabus analysis. <a href="https://www.tandfonline.com/doi/abs/10.1080/00031305.2022.2089232" style="font-size: 22px">Dogucu, M., & Hu, J. (2022). The Current State of Undergraduate Bayesian Education and Recommendations for the Future. The American Statistician. 76:4, 405-413, DOI: 10.1080/00031305.2022.2089232</a> --- <img src="img/bayes-courses-us.png" alt="A table with list of majors that include Bayesian courses as part of the major. There are two majors that require a Bayesian course." width="68%" style="display: block; margin: auto;" /> <a href="https://www.tandfonline.com/doi/abs/10.1080/00031305.2022.2089232" style="font-size: 22px">Dogucu, M., & Hu, J. (2022). The Current State of Undergraduate Bayesian Education and Recommendations for the Future. The American Statistician. 76:4, 405-413, DOI: 10.1080/00031305.2022.2089232</a> --- class:center <img src="img/bayes-rules-hex.png" alt="a hex shaped logo with shiny green-pink disco ball and purple starry background. There is text that says Bayes Rules!" width="25%" style="display: block; margin: auto;" /> .pull-left[ <script src="https://use.fontawesome.com/releases/v5.15.1/js/all.js" data-auto-replace-svg="nest"></script> <i class="fas fa-book fa-2x" aria-hidden="true" title="Book icon"></i> [Bayes Rules! An Introduction to Applied Bayesian Modeling](https://bayesrulesbook.com) ] .pull-right[ <i class="fab fa-r-project fa-2x" aria-hidden="true" title="R logo"></i> [{bayesrules}](https://www.github.com/bayes-rules/bayesrules) ] --- class: middle .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[Tubi] [
](https://github.com/MilesOtt) [
](https://twitter.com/Miles_Ott) [
](https://mastodon.social/@Miles_Ott@aus.social) ] ] --- class: center middle <img src="img/stats-115-logo.png" alt="Stats 115 course logo with prior, likelihood, and posterior plots!" width="25%" style="display: block; margin: auto;" /> [Introduction to Bayesian Data Analysis](https://www.stats115.com) --- class: middle ## Background of students taking the course - Prerequisite: STATS 120C. Introduction to Probability and Statistics III - Recommended: STATS 110. Statistical Methods for Data Analysis I - Students: Data Science major (required), Statistics minor (elective) --- class: middle <style type="text/css"> .panelset { --panel-tab-foreground: whitesmoke; --panel-tab-active-foreground: whitesmoke; --panel-tabs-border-bottom: #00a1a1; --panel-tab-inactive-opacity: 0.5;} </style> .panelset.sideways[ .panel[.panel-name[Unit 1] ### Bayesian Foundations .pull-right[ - Bayes' Rule - The Beta-Binomial Bayesian Model - Balance and Sequentiality in Bayesian Analysis - Conjugate Families ] .pull-left[ <img src="index_files/figure-html/unnamed-chunk-6-1.png" alt="three curves on a single plot with no axis labeled. It is coloring scheme indicates its similarity to the previous plot with prior, scaled likelihood and posterior" style="display: block; margin: auto;" /> ] ] .panel[.panel-name[Unit 2] ### Posterior Simulation & Analysis .pull-right[ <img src="img/unit2.png" alt="A traceplot with no axis labels. Traceplots have thin vertical lines with varying lengths." width="100%" style="display: block; margin: auto;" /> ] .pull-left[ - Grid Approximation - The Metropolis-Hastings Algorithm - Posterior Estimation - Posterior Hypothesis Testing - Posterior Prediction ] ] .panel[.panel-name[Unit 3] ### Regression and Classification .pull-right[ <img src="img/unit3.png" alt="A scatterplot with multiple regression lines passing through points. These regression lines are not all over the place, they are clustered with similar but varyin intercepts and slopes." width="100%" style="display: block; margin: auto;" /> ] .pull-left[ - Normal Regression - Poisson and Negative Binomial Regression - Logistic Regression - Naive Bayes Classification ] ] .panel[.panel-name[Unit 4] ### Hierarchical Models .pull-right[ <img src="img/unit4.png" alt="a figure showing hierarchy with a rectangle on top. With a set of arrows pointing downwards leading to a set of rectangles below which also have a set of arrows pointing downwards leading to a different set of rectangles." width="100%" style="display: block; margin: auto;" /> ] .pull-left[ - Normal hierarchical models without predictors - Normal hierarchical models with predictors - Non-Normal Hierarchical Regression & Classification ] ] ] --- class: middle .font75[Examples] --- class: middle center ## Big Picture <img src="img/bayes-restaurant.png" width="55%" style="display: block; margin: auto;" /> --- class: middle ## Context In Alison Bechdel’s 1985 comic strip The Rule, a character states that they only see a movie if it satisfies the following three rules ([Bechdel 1986](https://dykestowatchoutfor.com/the-essential-dtwof/)): - 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\)`, a random value between 0 and 1, denote the unknown proportion of movies that pass the Bechdel test (i.e. `\(\pi \in [0,1]\)`). --- .pull-left[ ![](index_files/figure-html/ch4-bechdel-priors-1.png)<!-- --> ] -- .pull-right2[ - **Feminist** thinks that women are not represented in movies often. - **Clueless** is unsure. - **Optimist** thinks that Bechdel is a low bar for representation of women in movies and thinks almost all movies pass the test. - Can you match the plots with the personas?] --- class: middle ## Plotting Beta Prior with `bayesrules` package One can use the `plot_beta()` function in the `bayesrules` package to try different shape parameters. Example: ```r library(bayesrules) plot_beta(alpha = 2, beta = 10) ``` <img src="index_files/figure-html/unnamed-chunk-13-1.png" style="display: block; margin: auto;" /> --- ## Plotting Beta Prior <img src="index_files/figure-html/unnamed-chunk-14-1.png" style="display: block; margin: auto;" /> --- <img src="index_files/figure-html/unnamed-chunk-16-1.png" style="display: block; margin: auto;" /> --- 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-20-1.png)<!-- --> ] .pull-right[ ![](index_files/figure-html/unnamed-chunk-21-1.png)<!-- --> ] --- 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 bike_model <- stan_glm(rides ~ temp_feel, data = bikes, family = gaussian, prior_intercept = normal(5000, 1000), prior = normal(100, 40), prior_aux = exponential(0.0008), chains = 4, iter = 5000*2, seed = 84735) ``` --- ### `library(bayesplot)` .pull-left[ ```r mcmc_trace(bike_model, size = 0.1) ``` <img src="index_files/figure-html/unnamed-chunk-25-1.png" width="80%" style="display: block; margin: auto;" /> ] .pull-right[ ```r mcmc_dens_overlay(bike_model) ``` <img src="index_files/figure-html/unnamed-chunk-26-1.png" width="80%" style="display: block; margin: auto;" /> ] --- class: middle .font75[Pedagogical Approach] --- class: middle ### Learning Bayesian Modeling is Fun > How can we live if we don’t change? —Beyoncé. Lyric from “Satellites.” .center[vs.] > What is probability? --- class: middle ### Checking Intuition <img src="img/fake-news-diagram.png" alt="There are two ellipses at the top of the image. The first ellipse reads 'Prior: Only 40% of articles are fake'. The second ellipse reads 'Data: Exclamation points are more common among fake news'. There are two arrows each from the upper two ellipses leading to a third ellipse in the lower part of the image. The third ellipse reads 'Posterior: Is the article fake or not?'" width="80%" style="display: block; margin: auto;" /> --- class: middle ## Active Learning .pull-left[ Quizzes [Quiz Yourself: Bayesian vs. Frequentist](https://www.bayesrulesbook.com/chapter-1.html#quiz-yourself-1) <img src="img/quiz.png" alt="An icon with a question mark and for choices labeled as A, B, C, and D." width="40%" style="display: block; margin: auto;" /> ] .pull-right[ Hands-on Programming [Metropolis-Hastings Algorithm](https://www.bayesrulesbook.com/chapter-7.html#the-metropolis-hastings-algorithm) <img src="img/programming.png" alt="An icon of a student sitting on a chair and in front a desk with a computer typing." width="40%" style="display: block; margin: auto;" /> ] --- class: middle ### Compute for a single case, then use built-in functions ```r predictions <- rstanarm::posterior_predict(bike_model, newdata = bikes) ``` ```r bayesplot::ppc_intervals(bikes$rides, yrep = predictions, x = bikes$temp_feel, prob = 0.5, prob_outer = 0.95) ``` <img src="index_files/figure-html/ppc_intervals-1.png" width="30%" style="display: block; margin: auto;" /> --- ### Accessible and Inclusive <img src="img/timeline.png" alt="Four framed photos are aligned next two each other. From left to right are pictures of a portrait of Thomas Bayes, a photo of Arianna W. Rosenbluth, a photo of David Blackwell, and an empty frame that reads Insert Your Photo Here. The portrait of Thomas Bayes is black and white with him wearing a regalia-like clothing. He has short dark hair. The photo of Arianna W. Rosenbluth is taken outside at the age of 86. She is wearing glasses, smiling, and has gray hair pulled back. David Blackwell is smiling into the camera wearing brown-frame glasses and a white-collar shirt. He has gray short hair on the sides of his head." width="100%" /> [Dogucu, M., Johnson, A. A., & Ott, M. (In Press). Framework for Accessible and Inclusive Teaching Materials for Statistics and Data Science Courses. Journal of Statistics and Data Science Education](https://www.tandfonline.com/doi/full/10.1080/26939169.2023.2165988) --- class: center middle ### Accessibility and Inclusion <table> <thead> <tr> <th style="text-align:left;"> Accessibility and Inclusion Criteria </th> <th style="text-align:left;"> Questions </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Accessibility </td> <td style="text-align:left;"> Is the cost affordable for learners from diverse socioeconomic backgrounds? </td> </tr> <tr> <td style="text-align:left;"> </td> <td style="text-align:left;"> Are plots distinguishable to color blind learners? </td> </tr> <tr> <td style="text-align:left;"> </td> <td style="text-align:left;"> Is alt text provided for images? </td> </tr> </tbody> </table> --- class: center middle <table> <thead> <tr> <th style="text-align:left;"> Accessibility and Inclusion Criteria </th> <th style="text-align:left;"> Questions </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Inclusivity of scholars </td> <td style="text-align:left;"> Do the cited scholars represent diversity across identities, experiences, and expertise? </td> </tr> <tr> <td style="text-align:left;"> </td> <td style="text-align:left;"> Are scholars cited using the correct names and pronouns? </td> </tr> </tbody> </table> --- class: center middle <table> <thead> <tr> <th style="text-align:left;"> Accessibility and Inclusion Criteria </th> <th style="text-align:left;"> Questions </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Inclusivity of students </td> <td style="text-align:left;"> Do examples avoid the necessity of specialized knowledge? </td> </tr> <tr> <td style="text-align:left;"> </td> <td style="text-align:left;"> Do names and pronouns reflect diverse cultural and personal identities? </td> </tr> <tr> <td style="text-align:left;"> </td> <td style="text-align:left;"> Are there examples that could potentially speak to younger as well as older students? </td> </tr> <tr> <td style="text-align:left;"> </td> <td style="text-align:left;"> Does the delivery embrace mistakes and critical thinking? </td> </tr> <tr> <td style="text-align:left;"> </td> <td style="text-align:left;"> Are efforts made to accommodate different academic experiences and create a shared foundation? </td> </tr> </tbody> </table> --- class: middle .font75[Current and Future Projects] --- class: middle ## Southern California Data Science Program HDR DSC awards: \#2123366 \#2123380 \#2123384 <img src="img/nsf-logo.png" alt="NSF logo" width="10%" style="display: block; margin: auto;" /> Through this collaborative grant between University of California Irvine, California State University Fullerton, and Cypress College, a Bayesian course will be adopted at California State University Fullerton. --- class: middle ## Bayes BATS <img src="img/bats-logo.png" alt="NSF logo" width="20%" style="display: block; margin: auto;" /> w/ [Monika Hu](https://pages.vassar.edu/jihu/) and [Amy Herring](https://sta198f2021.github.io/website/authors/amy/) .large[
] <a href = "https://www.stat.uci.edu/bayes-bats/">stat.uci.edu/bayes-bats</a> NSF DUE awards: #2215879, #2215920, and #2215709. --- class: middle Dogucu, M., Kazak, S. & Rosenberg J. (forthcoming) **The Design and Implementation of a Bayesian Data Analysis Lesson for Pre-Service Mathematics and Science Teachers** --- class: middle ## Resources - [Bayes Rules! resources](https://bayes-rules.github.io/) -- - [Undergraduate Bayesian Education Resources](https://undergrad-bayes.netlify.app/) -- - [Undergraduate Bayesian Education Network](https://undergrad-bayes.netlify.app/network.html) --- class: middle center # THANK YOU .large[ [mdogucu.github.io/bayes-lund-2023](https://mdogucu.github.io/bayes-lund-2023) ] .large[
] <a href = "http://minedogucu.com">minedogucu.com</a> .large[
] <a href = "http://github.com/mdogucu">mdogucu</a> .large[
] <a href = "http://twitter.com/MineDogucu">MineDogucu</a> .large[
] <a href = "https://mastodon.social/@MineDogucu">mastodon.social/@MineDogucu</a>