sr2-solutions
sr2-solutions copied to clipboard
Chapter 3 - 3H4
The question is "Now compare 10,000 counts of boys from 100 simulated first borns only to the number of boys in the first births, birth1 . How does the model look in this light?"
I think we should compute new posterior and samples based on observations from birth1 data, them simulate again and compare to the birth1.
p_grid <- seq(from=0, to=1, length.out = 1000)
prior <- rep(1, 1000)
likelihood <- dbinom(sum(birth1 == 1), size=100, prob=p_grid)
posterior <- likelihood * prior
posterior <- posterior / sum(posterior)
plot(posterior ~ p_grid, type='l')
samples <- sample(p_grid, prob=posterior, size=1e4, replace=TRUE)
b <- rbinom(1e4, size=100, prob=samples)
print(HPDI(b, prob = c(0.5, 0.89, 0.97)))
median(b)
dens(b)
Now the new model will fit quite good, just like the exercise 3H3.