Think Bayes
This notebook presents code and exercises from Think Bayes, second edition.
Copyright 2018 Allen B. Downey
MIT License: https://opensource.org/licenses/MIT
The height problem
For adult male residents of the US, the mean and standard deviation of height are 178 cm and 7.7 cm. For adult female residents the corresponding stats are 163 cm and 7.3 cm. Suppose you learn that someone is 170 cm tall. What is the probability that they are male?
Run this analysis again for a range of observed heights and plot a curve that shows P(male) versus height. What is the mathematical form of this function?
To represent the likelihood functions, I'll use norm from scipy.stats, which returns a "frozen" random variable (RV) that represents a normal distribution with given parameters.
Write a class that implements Likelihood using the frozen distributions. Here's starter code:
Here's the prior.
And the update:
Compute the probability of being male as a function of height, for a range of values between 150 and 200.
If you are curious, you can derive the mathematical form of this curve from the PDF of the normal distribution.
How tall is A?
Suppose I choose two residents of the U.S. at random. A is taller than B. How tall is A?
What if I tell you that A is taller than B by more than 5 cm. How tall is A?
For adult male residents of the US, the mean and standard deviation of height are 178 cm and 7.7 cm. For adult female residents the corresponding stats are 163 cm and 7.3 cm.
Here are distributions that represent the heights of men and women in the U.S.
Use thinkbayes2.MakeMixture to make a Pmf that represents the height of all residents of the U.S.
Write a class that inherits from Suite and Joint, and provides a Likelihood function that computes the probability of the data under a given hypothesis.
Write a function that initializes your Suite with an appropriate prior.
Update your Suite, then plot the joint distribution and the marginal distribution, and compute the posterior means for A and B.
Second tallest problem
In a room of 10 randomly chosen U.S. residents, A is the second tallest. How tall is A? What is the probability that A is male?