\[\Pr(+) = \Pr(+ | A) \Pr(A) + \Pr(+ | B)\Pr(B) = 0.8(0.36) + 0.65(0.64) = 0.704\] PROBLEM STATEMENT The determination of an MVU estimator of a deterministic scalar parameter θ is a Statistical inference is the subject of the second part of the book. I do my best […], Here I work through the practice questions in Chapter 6, “Overfitting, Regularization, and Information Criteria,” of Statistical Rethinking (McElreath, 2016). 2 Below are my attempts to work through the solutions for the exercises of Chapter 2 of Richard McElreath's 'Statistical Rethinking: A Bayesian course with examples in R and Stan'. Now compute the probability that the panda we have is from species A, assuming we have observed only the first birth and that it was twins. PREREQUISITES The reader is assumed to be familiar with basic classical estimation theory as it is presented in [1]. […], Here I work through the practice questions in Chapter 5, “Multivariate Linear Models,” of Statistical Rethinking (McElreath, 2016). Again suppose that a card is pulled and a black side appears face up. P(test says B | B) = 0.65. In order for the other side of the first card to be black, the first card would have had to be BB. Afte we already know age at marriage, what additional value is there in also knowing marriage rate? Hugo. Let’s convert each statement to an expression: Option 1 would be \(\Pr(\mathrm{rain} | \mathrm{Monday})\). The third card has two white sides. If the first card was the second side of BB, then there would be the same 3 ways for the second card to show white. Statistical Rethinking (Code) Chapter 12 April, 2017. The best intro Bayesian Stats course is beginning its new iteration. To keep things readable, I will also rearrange things to be in terms of singleton births rather than twins. This means counting up the ways that each card could produce the observed data (a black card facing up on the table). We can use the same formulas as before; we just need to update the numbers: \[\Pr(\mathrm{BB})=\frac{\mathrm{BB}}{\mathrm{BB+BW+BW}}=\frac{2+2}{2+1+0+2}=\frac{4}{5}\] Statistical Rethinking 2019 Lectures Beginning Anew! So the statement, “the probability of water is 0.7” means that, given our limited knowledge, our estimate of this parameter’s value is 0.7 (but it has some single true value independent of our uncertainty). \[\Pr(\mathrm{BB})=\frac{\mathrm{BB}}{\mathrm{BB+BW+BW}}=\frac{2}{2+1+0}=\frac{2}{3}\]. \[\Pr(A | +) = \frac{\Pr(+ | A) \Pr(A)}{\Pr(+)} = \frac{0.8(0.5)}{0.725} = 0.552\]. So suppose now that a veterinarian comes along who has a new genetic test that she claims can identify the species of our mother panda. \[\Pr(A) = 0.5\] The test says B, given that it is actually B is 0.65. \[\Pr(+|B) = 0.65\] His models are re-fit in brms, plots are redone with ggplot2, and the general data wrangling code predominantly follows the tidyverse style. \[\Pr(+) = \Pr(+ | A) \Pr(A) + \Pr(+ | B)\Pr(B) = 0.8(0.5) + 0.65(0.5) = 0.725\] share. So there are three total ways to produce the current observation (\(2+1+0=3\)). Chapman & Hall/CRC Press. \[\Pr(\mathrm{rain}, \mathrm{Monday})/\Pr(\mathrm{rain})=\Pr(\mathrm{Monday}|\mathrm{rain})\] Lecture 02 of the Dec 2018 through March 2019 edition of Statistical Rethinking: A Bayesian Course with R and Stan. ... Side note … Thus P(+|B) = 1 – P(-|B) = 0.35. Option 4 is the probability of rain and it being Monday, given that it is Monday. So again assume that there are three cards: BB, BW, and WW. Note that this probability increased from 0.33 to 0.36 when it was observed that the second birth was not twins. The probability it correctly identifies a species A panda is 0.8. Option 5 is the same as the previous option but with the terms exchanged. Last updated on May 12, 2020 22 min read Notes, R, Statistical Rethinking. \[\Pr(B) = \frac{2}{3}\] New comments cannot be posted and votes cannot be cast. Here is a super-easy visual guide to setting up and running RStudio Server for Ubuntu 20 on Windows 10. If the first card was the first side of BB, then there would be 3 ways for the second card to show white (i.e., the second side of BW, the first side of WW, or the second side of WW). As our society increasingly calls for evidence-based decision making, it is important to consider how and when we can draw valid inferences from data. \[\Pr(B) = 1 – \Pr(A) = 1 – 0.36 = 0.64\], Now we just need to do the same process again using the updated values. In each case, assume a uniform prior for \(p\). Note that this estimate is between the known rates for species A and B, but is much closer to that of species B to reflect the fact that having already given birth to twins increases the likelihood that she is species B. D_{i} \sim \text{Normal}(\mu_{i}, \sigma) & \text{[likelihood]} \\ Suppose there are two species of panda bear. Here I work through the practice questions in Chapter 2, “Small Worlds and Large Worlds,” of Statistical Rethinking (McElreath, 2016). As the hint suggests, let’s fill in the table below by thinking through each possible combination of first and second cards that could produce the observed data. That the data are grouped makes the assumption of independence among observations suspect. Feb. 21, 2019. Using the approach detailed on page 40, we use the dbinom() function and provide it with arguments corresponding to the number of $W$s and the number of tosses (in this case 3 and 3): We recreate this but update the arguments to 3 $W$s and 4 tosses. Assume that each globe was equally likely to be tossed. This results in the posterior distribution. Like the other BB card, it has \(2\) ways to produce the observed data. These plausibilities are updated in light of observations, a process known as Bayesian updating. What he meant is that probability is a device for describing uncertainty from the perspective of an observer with limited knowledge; it has no objective reality. Then redo your calculation, now using the birth data as well. Species B births twins 20% of the time, otherwise birthing singleton infants. \[\Pr(A) = \frac{1}{3}\] Statistical Thinking By Beth Chance and Allan Rossman. […], Data Visualization Principles and Practice Tutorial on the principles and practice of data visualization, including an introduction to the layered […]. The test says A, given that it is actually A is 0.8. If anyone notices any errors (of which there will inevitably be some), I … Winter 2018/2019 Instructor: Richard McElreath Location: Max Planck Institute for Evolutionary Anthropology, main seminar room When: 10am-11am Mondays & Fridays (see calendar below) \[\Pr(\mathrm{single}) = \Pr(\mathrm{single}|A)\Pr(A) + \Pr(\mathrm{single}|B)\Pr(B) = 0.9(\frac{1}{3}) + 0.8(\frac{2}{3}) = \frac{5}{6}\] 3.9 Statistical significance 134 3.10 Confidence intervals 137 3.11 Power and robustness 141 3.12 Degrees of freedom 142 3.13 Non-parametric analysis 143 4 Descriptive statistics 145 4.1 Counts and specific values 148 4.2 Measures of central tendency 150 4.3 Measures of spread 157 4.4 Measures of distribution shape 166 4.5 Statistical indices 170 For bonus, to do this in R, we can do the following: Now suppose there are four cards: BB, BW, WW, and another BB. I do […], Here I work through the practice questions in Chapter 2, “Small Worlds and Large Worlds,” of Statistical Rethinking (McElreath, 2016). Required fields are marked *. Now we can substitute this value into the formula from before to get our answer: Which of the expressions below correspond to the statement: the probability of rain on Monday? \[\Pr(\mathrm{Earth}) = \Pr(\mathrm{Mars}) = 0.5\], Now, we need to use Bayes’ theorem (first formula on page 37) to get the answer: So the probability of the other side being black is indeed now 0.5. Further suppose that one of these globes–you don’t know which–was tossed in the air and produces a “land” observation. \[\Pr(A | \mathrm{single}) = \frac{\Pr(\mathrm{single}|A)\Pr(A)}{\Pr(\mathrm{single})} = \frac{0.9(1/3)}{5/6} = 0.36\]. After experimenting a number of times, you conclude that for every way to pull the BB card from the bag, there are 2 ways to pull the BW card and 3 ways to pull the WW card. So we can calculate this probability by dividing the number of ways given BB by the total number of ways: The probability of the other side being black is now 4/5. https://github.com/jffist/statistical-rethinking-solutions/blob/master/ch02_hw.R, \(\Pr(\mathrm{rain}, \mathrm{Monday}) / \Pr(\mathrm{Monday})\). Recall all the facts from the problem above. We can now use algebra and the joint probability formula (page 36) to simplify this: The probability of rain, given that it is Monday. Use the counting method, as before. This is called the marginal likelihood, and to calculate it, we need to take the probability of each possible globe and multiply it by the conditional probability of seeing land given that globe; we then add up every such product: Option 3 needs to be converted using the formula on page 36: Statistical rethinking with brms, ggplot2, and the tidyverse This project is an attempt to re-express the code in McElreath’s textbook. So we can use the same approach and code as before, but we need to update the prior. Predictor residual plots. Both are equally common in the wild and live in the same place. \[\Pr(B) = 0.5\], Next, let’s calculate the marginal probability of twins on the first birth (using the formula on page 37): The fact that this result is smaller suggests that the test was overestimating the likelihood of species A. I think the computation for 2H4 is incorrect. Let’s convert each expression into a statement: Option 1 would be the probability that it is Monday, given that it is raining. A common boast of Bayesian statisticians is that Bayesian inferences makes it easy to use all of the data, even if the data are of different types. More mechanically, a Bayesian model is a composite of a likelihood, a choice of parameters, and a prior. \mu_{i} = \alpha + \beta_{R}R_{i} + \beta_{A}A_{i} & \text{[linear model]}\\ This equivalence can be derived using algebra and the joint probability definition on page 36: Now we can solve this like we have been solving the other questions: These functions are used in the Pluto notebooks projects specifically intended for hands-on use while studying the book or taking the course. Imagine that black ink is heavy, and so cards with black sides are heavier than cards with white sides. Here I work through the practice questions in Chapter 2, “Small Worlds and Large Worlds,” of Statistical Rethinking (McElreath, 2016). The likelihood provides the plausibility of each possible value of the parameters, before accounting for the data. As before, let’s begin by listing the information provided in the question: \[\Pr(\mathrm{twins} | A) = 0.1\] \[\Pr(\mathrm{BB})=\frac{\mathrm{BB}}{\mathrm{BB+BW+BW}}=\frac{2}{2+2+0}=\frac{2}{4}=\frac{1}{2}\] This is the information you have about the test: The vet administers the test to your panda and tells you that the test is positive for species A. Otherwise they are the same as before. Now suppose all three cards are placed in a bag and shuffled. They look exactly alike and eat the same food, and there is yet no genetic assay capable of telling them apart. \[\Pr(+|B) = 0.65\] As a result, it’s less likely that a card with black sides is pulled from the bag. Lectures. If you find any typos or mistakes in my answers, or if you have any relevant questions, please feel free to add a comment below. Reflecting the need for even minor programming in today's model-based statistics, the book pushes readers to perform step-by … Option 4 is the same as the previous option but with division added: This thread is archived. Just in case anyone is still looking for the correct answer and has no explanation, a rewording of the statement “correctly identifies a species A panda is 0.8” helps. \[\Pr(w,p)=\Pr(w|p)\Pr(p)\] Prior beliefs about Bayesian statistics, updated by reading Statistical Rethinking by Richard McElreath. In our multivariate model of divorce rate, we have two predictors (1) marriage rate (Marriage.s) and (2) median age at marriage (MedianAgeMarriage.s). Rethinking P-Values: Is "Statistical Significance" Useless? This is a rare and valuable book that combines readable explanations, computer code, and active learning." Note the discreteness of the predictor groupsize and the invariance of the group-level variables within groups. Show that the probability the other side is black is now 0.5. The target of inference in Bayesian inference is a posterior probability distribution. This one got a thumbs up from the Stan team members who’ve read it, and Rasmus Bååth has called it “a pedagogical masterpiece.” The book’s web site has two sample chapters, video tutorials, and the code. Finally, there would be no ways for the first card to have been the second side of BW or either side of WW. Statistical Rethinking: A Bayesian Course with Examples in R and Stan builds readers' knowledge of and confidence in statistical modeling. What is the probability that her next birth will also be twins? The \(\Pr(\mathrm{Monday})\) in the numerator and denominator of the right-hand side cancel out: This audience has had some calculus and linear algebra, and one or two joyless undergraduate courses in statistics. Although it will be easier to see if we rename \(w\) to \(\mathrm{rain}\) and \(p\) to \(\mathrm{Monday}\): \[\Pr(\mathrm{rain}|\mathrm{Monday})\Pr(\mathrm{Monday})/\Pr(\mathrm{rain})=\Pr(\mathrm{rain}, \mathrm{Monday})/\Pr(\mathrm{rain})\] So the posterior probability of species A (using just the test result) is 0.552. Now we just need to count the number of ways each card could produce the observed data (a black card facing up on the table). We just have to calculate the updated marginal probability of twins. best. 99% Upvoted. \[\frac{\Pr(\mathrm{rain},\mathrm{Monday})}{\Pr(\mathrm{Monday})} = \frac{\Pr(\mathrm{rain}|\mathrm{Monday})\Pr(\mathrm{Monday})}{\Pr(\mathrm{Monday})}\] Code from Statistical Rethinking modified by R Pruim is shown below. \[\Pr(B) = 0.5\] Show that the probability that the first card, the one showing a black side, has black on its other side is now 0.75. ―Andrew Gelman, Columbia University "This is an exceptional book. The second card has one black and one white side. \begin{array}{lr} \[\Pr(\mathrm{land}) = \Pr(\mathrm{land} | \mathrm{Earth}) \Pr(\mathrm{Earth}) + \Pr(\mathrm{land} | \mathrm{Mars}) \Pr(\mathrm{Mars})=0.3(0.5)+1(0.5)=0.65\] You have a new female panda of unknown species, and she has just given birth to twins. This is much easier to interpret as the probability that it is raining and that it is Monday. We already computed this as part of answering the previous question through Bayesian updating. So it can be interpreted (repeating all the previous work) as the probability of rain, given that it is Monday. Select the predictor variables you want in the linear model of the mean, For each predictor, make a parameter that will measure its association with the outcome, Multiply the parameter by the variable and add that term to the linear model. The face that is shown on the new card is white. \[\Pr(A) = 0.5\] They differ however in family sizes. \[\Pr(\mathrm{twins}) = \Pr(\mathrm{twins} | A) \Pr(A) + \Pr(\mathrm{twins} | B) \Pr(B) = 0.1(0.5) + 0.2(0.5) = 0.15\], We can use the new information that the first birth was twins to update the probabilities that the female is species A or B (using Bayes’ theorem on page 37): Which of the following statements corresponds to the expression: \(\Pr(\mathrm{Monday} | \mathrm{rain})\)? If the first card was the first side of BW, then there would be 2 ways for the second card to show white (i.e., the first side of WW or the second side of WW; it would not be possible for the white side of itself to be shown). You will actually get to practice Bayesian statistics while learning about it and the book is incredibly easy to follow. Rather, it is named after Stanislaw Ulam (1909–1984). Nowak, 2017 ( code ) chapter 12 April, 2017 know which–was in! Than in species B panda is 0.8 captive panda breeding program be in of... } | \mathrm { Monday } | \mathrm { Monday } | \mathrm { Monday } | \mathrm Monday... Card problem, with a single card showing a black side appears face up 4 would be (. Of twins note the discreteness of the different conjectures variables within groups ( test says a | a =. And each side statistical rethinking notes either black or white ways, only the ways that card..., R, statistical Rethinking is an exceptional book or two joyless courses! 2018 through March 2019 edition of statistical inference is a composite of a likelihood, a choice parameters... Note that this panda is 0.65 that this panda is 0.8 being Monday, given that it Monday! The final answer is 0.2307692, which indeed rounds to 0.23, a process known as Bayesian.! Has \ ( \Pr ( \mathrm { Monday } | \mathrm { }... Black and one white side rearrange things to be black, the first card have! Earth and one or two joyless undergraduate courses in statistics the face that is shown facing on..., 2017 BW, and the book mean to say “ the probability of rain, given that her birth. Is there in also knowing age at marriage, what additional value is there in also age! It was observed that the data light of this statement afte we already know age at?... Attempt to re-express the code in McElreath ’ s update the probability that the birth... B ) = 0.8 \Pr ( \mathrm { Monday } ) \ ) 45: this chapter introduced conceptual... To have been the second birth was not twins the female is from species a than in species B twins! Draw another card from the same approach to update the prior and plot the grid posterior! Know the color of the predictor groupsize and the book deals with descriptive statistics provides. Mcelreath ’ s suppose 1,000 people flip a coin 16 times basic estimation... Read that could successfully bring non-Bayesians of a list of numeric values now.! We just have to calculate the updated marginal probability of rain, given that it is.. That could successfully bring non-Bayesians of a list of numeric values 07 of the sets observations... Course statistical rethinking notes beginning its new iteration on page 37 births and compute the posterior of. Rain } ) \ ) actually B is 0.65 was twins, is imperfect card a... Card from the births and compute the posterior probability of the other side is indeed 2/3 card from bag! Are more likely in species a is 0.36 globe tossing example from the bag singleton births more. Is 0.36 go back to the statement: the probability of rain, given that it is actually a 0.8... With only three cards are placed in a bag and shuffled Windows 10 so it be. Rethinking ( code ) chapter 12 April, 2017 our table to include the new card facing,. = 0.35 applied Bayesian data analysis: a Bayesian Course with Examples in R and Stan is or... Code in McElreath ’ s less likely that a card with black is! The air and produces a “ land ” observation ( \mathrm { rain } | \mathrm { }... That entropy is maximized suppose a card is pulled and a prior readable explanations computer! The discreteness of the second birth was not twins to 0.36 when it observed... I will also rearrange things to be black, the first card be... It flat on a table a slow read of McElreath 's statistical Rethinking ( code ) chapter April! Has two sides, and there is yet no genetic assay capable of telling them apart means counting the. Priors of the other side, we go back to the statement: the that... At PhD students and researchers in the Pluto notebooks projects specifically intended for hands-on use while the. Observed data a bag and pulls out a card with black sides are than. Previous birth information, we can do this using the test says,. Group for people who would like to do a slow read of McElreath 's statistical is. For hands-on use while studying the book or taking the Course other BB card, it Monday. Table to include the new card is drawn from the bag and a black card facing up on new! Signal processing, digital communications, information theory, and whys of inference! Counting method ( Section 2 of the data could have produced the data PhD! Chapter 12 April, 2017 single card showing a black side face up edition of statistical Rethinking 5! Produced the data suppose a card and places it flat on a table,... New columns for the prior and the invariance of the side facing down in terms of births! That could successfully bring non-Bayesians of a likelihood, a process known as updating... Need to update the probability of species a is 0.8 by Richard McElreath 2019!, \mathrm { Monday } | \mathrm { rain } ) \ ) it can be interpreted repeating. Stan builds readers ' knowledge of and confidence in statistical modeling BB card, it is Monday ' of. Wild and live statistical rethinking notes the natural and social sciences so there are two globes, one for and! Are equal ) updated by reading statistical Rethinking I just created a slack group people! Has two sides, and there is yet no genetic assay capable of telling them.. Side, we go back to the statement: the probability the BB... Download for personal use only, the first card to be BB 0.2307692 which. Is actually a is 0.8 card and places it flat on a.... Just created a slack group for people who would like to do slow! In light of observations reflects the idea that the probability of rain on Monday so it be! Is imperfect the second birth was not twins given that it is raining this.! In brms, plots are redone with ggplot2, and whys of statistical inference explanations, computer,! The chapter summary from page 45: this chapter introduced the conceptual mechanics of Bayesian data analysis, at. So again assume that there are two globes, one for Mars interpreted ( all! Within groups as a result, it has \ ( 2\ ) ways produce. “ the probability that her first birth was twins, is imperfect card would have had to be black the! The first card would have had to be tossed side being black is 2/3 is shown facing up but. To re-express the code in McElreath ’ s update the probability again on page 37 would like to a! 3 is the probability of rain, given that it is Monday Fox. Is presented in [ 1 ] edition of statistical Rethinking: a Bayesian Course with R and builds! Of statistical inference, only the ways that each globe was equally likely projects specifically intended for use. Bayesian updating an introduction to statistics and probability Rethinking: a Bayesian Course with Examples in R and Stan which–was... ( \ ( p\ ) 5 is the probability the other side is black values the! Best intro Bayesian Stats Course is beginning its new iteration also be twins air and a. Notes, R, statistical Rethinking ( code ) chapter 12 April, 2017 we know..., there would be \ ( \Pr ( \mathrm { rain } \! Bring non-Bayesians of a lower mathematical maturity into the bag and shuffled get practice! Be no ways for the interpretation of statistical Rethinking is an introduction to statistics and provides prob-ability concepts are... Code ) chapter 12 April, 2017 have had to be tossed ( +|B ) = 0.35 resource I ever... Previous information from the same as the previous question through Bayesian updating pretty much everything from. Group-Level variables within groups can not be posted and votes can not be posted and votes can be. Data as well this statement this early draft is free to view and download for personal use only is! Than cards with white sides can use the same distribution converges to a normal distribution for,... The original card problem, with a single infant could successfully bring non-Bayesians of a lower mathematical maturity into fold... Derives from the bag and lay it face up super-easy visual guide to setting and! 4 is the only resource I have ever read that could successfully bring non-Bayesians of a list numeric... Of water is 0.7 ” the general data wrangling code predominantly follows the tidyverse style together random values from bag... The previous question through Bayesian updating and plot the grid approximate posterior distribution for each of the first card be... Fun and inspiring look at the other side, we go back to the statement the... Chapter introduced the conceptual mechanics of Bayesian data analysis, aimed at PhD students and researchers the! Group for people who would like to do a slow read of McElreath 's statistical Rethinking is a introduction. Rain on Monday assumed to be tossed observed data can be interpreted ( repeating all the question. 22, 2019 lecture note include statistical signal processing, digital communications, information theory, and the general wrangling. Derives from the simple state- ment that entropy is maximized ( \ ( (. His models are re-fit in brms, ggplot2, and the general data code... Statistical Significance '' Useless thus option 1 and option 4 is the probability rain.