# Confusion with Chi-Square test

I have an extremely simple question regarding chi-square test. So far I have found two different formulas for it: $$\chi^2=\sum\frac{(x_o-x_e)^2}{x_e}$$ and $$\chi^2=\sum\frac{(x_o-x_e)^2}{\sigma^2}$$

$x_o$ is the observed data while $x_e$ is the expected data. Clearly the two formulas do not return the same result because $x_e \neq \sigma^2$. Can someone explain to me why there are two different formulas for the chi-square test and when I should use each one of them? Thank you.

Actually, when $x_o$ is Poisson, the estimate of (or sometimes the population value of) $\text{Var}(x_o)$ is $x_e$. But that second formula can occur in a variety of contexts.

The sum of the squares of $k$ independent standard normal random variables is distributed as $\chi^2_k$.

So if you have $x_o$'s that are approximately normal, and $x_e$ is the expected value of $x_o$ and $\sigma^2$ is its variance, then $z = (x_o - x_e)/\sigma$ is approximately standard normal. The sum of squares of $k$ independent such $z$'s will be approximately $\chi^2_k$. The sum of squares of such terms is your second formula.

If the $x_o$ values are multivariate normal but dependent in such a way as to have a fixed total, this just reduces the degrees of freedom in the $\chi^2$ by 1. If there are other (additional) such linear constraints (such as fixed margins of tables), they each tend to reduce the d.f. by 1 (but you don't count ones that are already implied by existing constraints).

As a result of the "sums of squares of standardized approximate normals will be approximate chi-squared" idea, there are many, many situations under which something that looks like that second formula might be approximately $\chi^2$.

Without a reference, it's a bit hard to guess what situation you're in.

The first formula can be a special case of the second (as I mentioned, with Poisson data).

It actually applies to count data that's Poisson or multinomial (the multinomial has smaller variance than the Poisson, but the resulting dependence structure is such that the formula still works out, simply reducing the d.f. as I mentioned before).