Theoretical Context
Inferential statistics is about predicting the behavior of an entire population/distribution from a finite-sized random sample. The larger the size N of the random sample, the better the sample mean \bar{x} and variance s^2_x estimate the true mean \mu and variance \sigma^2. This animation aims to show exactly this.
The animation is build based on the following procedure:
- We compute a random ‘master’ sample of size N_\mathrm{max}=1000.
- We define arrays that will contain the means and standard deviations of subsamples.
- We create subsamples of sizes N=1,2,3\dots,1000 by taking the first N elements form the master sample.
- For those subsamples, we compute the average \bar{x} and standard deviation s_x.
- We plot a histogram of the subsample along with the average and standard deviation. We stack these plots together into an animation.
For the animation, we drew the master sample from a normal distribution:
\begin{equation*} p(x)=\frac{1}{\sqrt{2\pi\sigma^2}}\exp\bigg[-\frac{1}{2}\frac{(x-\mu)^2}{\sigma^2}\bigg], \end{equation*}
where we took \mu=0 and \sigma=1/2.