This is a tutorial notebook on how to approach a problem using Bayesian statistics. The notebook aims to answer a question similar to "What is Phil's height?" by applying Bayesian inference to estimate the mean of a sample based on observed data.
Bayesian inference is a statistical method that updates the probability of a hypothesis as more evidence or information becomes available. It combines prior beliefs (prior distribution) with the likelihood of observed data to form a posterior distribution, which represents the updated belief after considering the evidence.
The prior distribution reflects our initial beliefs about the parameter before observing any data. In this notebook, we assume Phil's height follows a normal distribution with a mean (mean_height) of 182 cm and a standard deviation (std_dev) of 12.7 cm. This is represented mathematically as:
The likelihood function represents the probability of the observed data given a specific value of the parameter (in this case, Phil's height). Given measurements with a known uncertainty (standard deviation of 5 cm), the likelihood for each measurement is calculated as:
where
The posterior distribution combines the prior distribution and the likelihood of the observed data to provide an updated belief about the parameter. It is calculated as:
The posterior is then normalized so that the area under the curve equals 1.
- Prior PDF Function: Defines the prior probability density function based on the assumed normal distribution of Phil's height.
- Likelihood Function: Calculates the likelihood of the observed measurements for different values of Phil's height.
- Posterior PDF Function: Combines the prior and likelihood to compute the posterior distribution.
The notebook overlays the following curves:
- Prior Distribution: Our initial belief about Phil's height.
- Likelihood of Each Data Point: Individual likelihood curves for each measurement.
- Joint Likelihood: Combined likelihood of observing all measurements.
- Posterior Distribution: The updated belief about Phil's height after considering the observed data.