Unbiasedness and the Sample Variance

We saw earlier that we estimate the variance in the sample as $$ s^2 = \frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2 $$ and used this as an estimator for $\sigma^2$. Is the estimator unbiased? First, note that we are talking about the random variable, not the outcome. The random variable for which $s^2$ is an outcome is $$ S^2 = \frac{1}{n-1} \sum_{i=1}^n (X_i - \bar{X})^2. $$ The simplest way to work this out is to start with a single part of the sum. We have that \begin{align*} E(X_i - \bar{X})^2 &= E \left( X_i - \frac{1}{n} \sum_{j=1}^n X_j \right)^2 \\ &=E \left( X_i-\mu - \frac{1}{n} \sum_{j=1}^n (X_j-\mu) \right)^2 \\ &= E \left( \frac{n-1}{n}(X_i-\mu) - \frac{1}{n}\sum_{j\ne i} (X_j-\mu) \right)^2 \\ &= \left( \frac{(n-1)^2}{n^2}\sigma^2 - \frac{n-1}{n^2} \sigma^2 \right) \\ &= \left( \frac{(n-1)}{n}\sigma^2 \right). \end{align*} So now for $ S^2 $ there are $n$ of these in the sum (so $n$ of the same value) and we divide by $n-1$ and so $$ES^2 = \frac{1}{n-1} \sum_{i=1}^n E(X_i - \bar{X})^2 = \frac{1}{n-1}\frac{(n-1)}{n}n\sigma^2 = \sigma^2$$ So by our definition this estimator is unbiased for $\sigma$. This is the reason for dividing by $n-1$ instead of $n$, to obtain an unbiased estimator.