Explain Statistics: Matching formulas for chi square tests The chi square formula given in my book is:
$\chi^2 = \frac{(n-1)s^2}{\sigma^2} $ 
At first I admitted to feeling some kind of strangeness to this formula, but after a few hours I realized that $\chi^2$ was $\displaystyle \sum_{i=1}^n \left(\frac{X_i - \mu}{\sigma}\right)^2 - \left( \frac{\bar{x} - \mu}{\frac{\sigma}{\sqrt{n}}} \right)^2$ in disguise. However, there's a formula in my book that says that 
$\chi^2 = \displaystyle \frac{\sum_{i=1}^n (O_i - E_i)^2}{E_i}$ where $O_i$ is the observed value and $E_i$ is the expected value. I want to show that this expression is equivalent to the one above: $$\displaystyle \sum_{i=1}^n \left(\frac{X_i - \mu}{\sigma}\right)^2 - \left( \frac{\bar{x} - \mu}{\frac{\sigma}{\sqrt{n}}} \right)^2$$
This equation comes from the fact that $(n-1)s^2 = \displaystyle \sum_{i=1}^n ((X_i - \mu)+(\mu - \bar{x}))^2$
 A: Following Alecos' & whuber's comments, it would seem that these are two different $\chi^2$ statistics, for two different quantities. They may both be distributed under $\chi^2[k]$ without being equal in meaning.
The expression $\chi^2=\sum_{i=1}^n(N-1)\frac{s^2}{\sigma^2}$ seems to be the $\chi^2$ statistic for variance, used with a null hypothesis concerning the population variance. 
The other expression $\chi^2=\sum^n_{i=1}(\frac{O_i-E_i}{E_i})^2$ concerns Pearson's $\chi^2$ statistic for goodness-of-fit.
To this, I would add that there are many random variables whose distributions follow $\chi^2$, as by definition

the chi-squared distribution (also chi-square or χ2-distribution) with k degrees of freedom is the distribution of a sum of the squares of k independent standard normal random variables
  (https://en.wikipedia.org/wiki/Chi-squared_distribution)

One only has to choose quantities which are distributed as $N(0,1)^2$ for the terms in the sum.
I realise that this answer could be expanded upon, and I do hope that someone will correct me where necessary and further this explanation. Certainly, this is a confusing topic.
