AW

learning from data with humnans

Bootstrapping essentials in python

  • https://en.wikipedia.org/wiki/Sampling_distribution Bootstrapping helps estimating confidence intervals for any static of interest directly from the data sample. In this post we will show how to do your first bootstrap and -more importantly- how to get a feeling of the whole process.

Well-known things first: confidence intervals for the mean

Let’s say you are presented with some data about people heights and want to know the mean height for male and females at 95% confidence level.

The central limit theorem tells us that the mean $^{x}$ of a random variable “height” is normally distributed even if the random variable itself is not normally distributed and allows us to express the confidence interval (CI) as:

$$[^{x}-1.96 \frac{s}{\sqrt(n)}, ^{x}+1.96 \frac{s}{\sqrt(n)}]$$.

Where $s$ is the population standard deviation and $n$ the size of your sample1. Where does the ‘1.96’ come from? That number is a function of the desired confidence level (95% in this case), which should be chosen before the analysis.

Basically we are recalling here that -if you were to sample multiple times from the population-, you would estimate a mean that falls within that CI 95% of the time. The width of such interval is determined by the desired confidence level, by the number $n$ of samples drawn and by the standard deviation of your data $s$.

This also helps you in estimating the size of $n$ necessary to achieve a given level of confidence: collecting 100 times more samples gives you a CI 10 times narrower.

Confidence interval for child heights

Naively bootstrapping CIs (percentile method)

Bootstrapping: a better way (empirical method)

..

When the CLT does not help

..

Notes

  • It the difference in the child’s means statistically significant?
  1. https://speakerdeck.com/jakevdp/statistics-for-hackers?slide=138
  2. https://yanirseroussi.com/2019/01/08/hackers-beware-bootstrap-sampling-may-be-harmful/
  3. https://yanirseroussi.com/2020/08/24/many-is-not-enough-counting-simulations-to-bootstrap-the-right-way/
  4. https://erikbern.com/2018/10/08/the-hackers-guide-to-uncertainty-estimates.html

  1. let’s say $n>30$, more here to know more. ↩︎