.. _bessel_correction:

This page is inpired by `Wikipedia <https://en.wikipedia.org/wiki/Bessel%27s_correction>`__.

Bessel's Correction
-----------------------

Bessel's correction is the use of :math:`n-1` instead of :math:`n` in the formulas for sample
variance and sample standard deviation.
In fact, using :math:`n` as a denominator leads to a biased estimator.
This variance estimator is noted :math:`s^2_n`.
Lets compute the discrepency between population variance and the biased sample variance:

.. math::
   \mathbb{E}[\sigma^2-s_n^2] &= \mathbb{E} \left[ \frac{1}{n} \sum_{i=1}^n(x_i - \mu)^2 - \frac{1}{n}\sum_{i=1}^n (x_i - \overline{x})^2 \right]
   
   &=\mathbb{E}\left[ \frac{1}{n} \sum_{i=1}^n\left((x_i^2 - 2 x_i \mu + \mu^2) - (x_i^2 - 2 x_i \overline{x} + \overline{x}^2)\right) \right]

   &=\mathbb{E}\left[ \frac{1}{n} \sum_{i=1}^n\left(\mu^2 - \overline{x}^2 + 2 x_i (\overline{x}-\mu) \right) \right]
   
   &=\mathbb{E}\left[ \frac{1}{n} \sum_{i=1}^n \left(\mu^2 - \overline{x}^2 \right) + \frac{1}{n} \sum_{i=1}^n 2 x_i (\overline{x} - \mu) \right]

   &=\mathbb{E}\left[  \mu^2 - \overline{x}^2 + \frac{1}{n} \sum_{i=1}^n 2 x_i (\overline{x} - \mu) \right]

   &=\mathbb{E}\left[  \mu^2 - \overline{x}^2 + 2\overline{x}(\overline{x} - \mu) \right]

   &=\mathbb{E}\left[  \mu^2 - 2 \overline{x} \mu + \overline{x}^2 \right]

   &= \mathbb{E}\left[  (\overline{x}   - \mu)^2 \right]

   &= \mathrm{Var}[\overline{x}]

   &= \frac{\sigma^2}{n}


This result shows us that the discrepency between the population and sample variance is :math:`\frac{\sigma^2}{n}`.
It is simply, the :ref:`Standard Error of the Mean <SEM>`.
From this result we can deduce how :math:`S_n^2` must be adjusted:

.. math::
   \mathbb{E} \left[ s^2_n \right] = \sigma^2 - \frac{\sigma^2}{n} = \frac{n-1}{n} \sigma^2

Thus, the adjustment factor is :math:`\frac{n-1}{n}`. As such, an unbiased estimator of :math:`\sigma^2` is:

.. math::
   s^2 = \frac{s^2_n}{\frac{n-1}{n}} = \frac{n}{n-1} s_n^2 &= \frac{n}{n-1} \frac{1}{n} \sum_{i=1}^n (x_i-\overline{x})^2

   &= \frac{1}{n-1} \sum_{i=1}^n (x_i-\overline{x})^2
