I have quite a simple question but I can't for the life of me figure it out.
For a set of iid samples $\,\,X_1, X_2, \ldots, X_n\,\,$ from distribution with mean $\,\mu$.
If you are given the sample variance as
$ S^2 = \frac{1}{n-1}\sum\limits_{i=1}^n \left(X_i - \bar{X}\right)^2 $
How can you write the following?
$ S^2 = \frac{1}{n-1}\left[\sum\limits_{i=1}^n \left(X_i - \mu\right)^2 - n\left(\mu - \bar{X}\right)^2\right] $
All texts that cover this just skip the details but I can't work it out myself. I get stuck after expanding like so
$ S^2 = \frac{1}{n-1}\sum\limits_{i=1}^n \left(X_i^2 -2X_i\bar{X} + \bar{X}^2\right) $
What am I missing?
Edit: A similarly equivalent expression is often given that I also can't derive but which may be more obvious is
$ S^2 = \frac{1}{n-1}\left[\sum\limits_{i=1}^n X_i^2 - n\bar{X}^2\right] $