Skip to content

Inferential Statistics

Left: Histogram of subsample (blue) and corresponding true distribution (red). Middle: Mean \bar{x} of subsample as function of sample size N. Right: Now for the standard deviation s_x.

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:

  1. We compute a random ‘master’ sample of size N_\mathrm{max}=1000.
  2. We define arrays that will contain the means and standard deviations of subsamples.
  3. We create subsamples of sizes N=1,2,3\dots,1000 by taking the first N elements form the master sample.
  4. For those subsamples, we compute the average \bar{x} and standard deviation s_x.
  5. 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.

Downloads