Need explanation for a form of the Chi-Squared test that differs from the standard definition I'm doing association analysis and I'm using a Chi-Squared test on a 2x2 contingency table.
The usual definition of the Chi-Squared test is given e.g. here and here, the term in the denominator is usually the same as the term on the right side in the bracket in the numerator.
So when it's used for analysing the strength of an observed association $p_{12}$ between two events $p_1$ and $p_2$ it could be written like this:
$$
\chi^2 = \frac{N(p_{12}-p_1 p_2)^2}{p_1 p_2}
$$
However I found a definition that differs from that one in a script about data mining on page 3.
The author also puts the probabilities of the events not occurring in the denominator:
$$
\chi^2 = \frac{N(p_{12}-p_1 p_2)^2}{p_1 p_2 (1-p_1)(1-p_2)}
$$
Given that in my case $p_1$ and $p_2$ are generally very small the term barely changes the results I'm getting, but what is the statistical reasoning behind this? Is it some kind of correction that improves the statistic?
 A: This is just the standard chi-square formula $(O-E)^2/E$ applied to a contingency table.  However, the chi-square statistic will apply this intuitive formula for all cells in the underlying contingency table, and add them up.  So the chi-square statistic for row-column association is of the following form:
$$\chi^2=N\sum_r\sum_c\frac {(f_{rc}-f_{r\bullet}f_{\bullet c})^2}{f_{r\bullet}f_{\bullet c}} $$
Suitably rearranged and simplified.  As you have only $4$ cells ($2$ rows and $2$ columns), the joint probabilities can be re-expressed in terms of you $p$ variables in the contingency table as:
 $$\begin{array}{c|c}\
 f_{11}=p_{12} & f_{12}=p_1-p_{12} & f_{1\bullet}=p_1 \\ \hline
 f_{21}=p_2-p_{12} & f_{22}=1+p_{12} -p_1-p_2 & f_{2\bullet}=1-p_1\\ \hline
 f_{\bullet 1}=p_2 & f_{\bullet 2}=1-p_2 & f_{\bullet\bullet}=1 
\end{array}$$
Your formula applies to the contribution of top-left cell in the contingency table to the chi-square statistic.  There is a bit of tedious work in simplifying the squared terms, but you have:
$$\begin{array}{c|c}\
 (p_{12}-p_1p_2)^2 & (p_1-p_{12}-p_1(1-p_2))^2 \\ \hline
 (p_2-p_{12}-(1-p_1)p_2)^2 & (1+p_{12} -p_1-p_2-(1-p_1)(1-p_2))^2\\
\end{array}
=\begin{array}{c|c}\
 (p_{12}-p_1p_2)^2 & (p_1p_2-p_{12})^2 \\ \hline
 (p_1p_2-p_{12})^2 & (p_{12} -p_1p_2)^2\\
\end{array}$$
So this shows the numerator contribution to the chi-square statistic from each cell in the contingency table is the same, and equal to $N(p_{12}-p_1p_2)^2$.  Now all that is left is to show that the sum of the denominators is equal to the combined denominator.  We have:
$$\frac{1}{p_1p_2}+\frac{1}{p_1(1-p_2)}+\frac{1}{(1-p_1)p_2}+\frac{1}{(1-p_1)(1-p_2)}
=\frac{(1-p_1)(1-p_2)+(1-p_1)p_2+p_1(1-p_2)+p_1p_2}{p_1p_2(1-p_1)(1-p_2)}
=\frac{[1-p_1-p_2+p_1p_2]+[p_2-p_1p_2]+[p_1-p_1p_2]+p_1p_2}{p_1p_2(1-p_1)(1-p_2)}=\frac{1}{p_1p_2(1-p_1)(1-p_2)}$$
Putting this all together and you have the final answer:
$$\chi^2=\frac{N(p_{12}-p_1p_2)^2}{p_1p_2(1-p_1)(1-p_2)}$$
