jffist / statistical-rethinking-solutions

Solutions of practice problems from the Richard McElreath's "Statistical Rethinking" book.
61 stars 18 forks source link

2H4 #1

Open alecloudenback opened 5 years ago

alecloudenback commented 5 years ago

Hello,

Thank you for posting a set of solutions!

For 2H4, I believe that the intent of the question is that you use the posterior from the birthing solution as your prior for the analysis with the genetic test. See here:

https://konradsenf.com/statistical-rethinking-chapter-2/

gifuni commented 5 years ago

Hi, Wonderful set of solutions indeed. 2H4 is not entirely clear if we should accont for the first birth or both. However, nothing is more simple than adding an extra Bayesian update :


#p1
likelihood_test <- c(0.8, 1-0.65)
prior <- c(1, 1)
posterior_vet <- prior * likelihood_test
posterior_vet <- posterior_vet/sum(posterior_vet)

posterior_vet[1] #0.6956522
#p2
p_twins_A <- 0.1
p_twins_B <- 0.2
likelihood_twins <- c(p_twins_A, p_twins_B)
prior <- posterior_vet
posterior <- prior * likelihood_twins
posterior <- posterior/sum(posterior)

posterior[1] #0.5333333

#p3
p_singles_A <- 1 - 0.1
p_singles_B <- 1 - 0.2
likelihood_singles <- c(p_singles_A, p_singles_B)
prior <- posterior
posterior <- prior * likelihood_singles
posterior <- posterior/sum(posterior)

posterior[1] #0.5625```