BACKGROUND: Skip safely - it's here for reference, and to legitimize the question.
The opening of this paper reads:
"Karl Pearson’s famous chi-square contingency test is derived from another statistic, called the z statistic, based on the Normal distribution. The simplest versions of $\chi^2$ can be shown to be mathematically identical to equivalent z tests. The tests produce the same result in all circumstances. For all intents and purposes “chi-squared” could be called “z-squared”. The critical values of $\chi^2$ for one degree of freedom are the square of the corresponding critical values of z."
This has been asserted multiple times in CV (here, here, here and others).
And indeed we can prove that $\chi^2_{1\,df}$ is equivalent to $X^2$ with $X\sim N(0,1)$:
Let's say that $X \sim N(0,1)$ and that $Y=X^2$ and find the density of $Y$ by using the $cdf$ method:
$p(Y \leq y) = p(X^2 \leq y)= p(-\sqrt{y} \leq x \leq \sqrt{y})$. The problem is that we cannot integrate in close form the density of the normal distribution. But we can express it:
$$ F_X(y) = F_X(\sqrt{y})- F_X(-\sqrt[]{y}).$$ Taking the derivative:
$$ f_X(y)= F_X'(\sqrt{y})\,\frac{1}{2\sqrt{y}}+ F_X'(\sqrt{-y})\,\frac{1}{2\sqrt{y}}.$$
Since the values of the normal $pdf$ are symmetrical:
$ f_X(y)= F_X'(\sqrt{y})\,\frac{1}{\sqrt{y}}$. Equating this to the $pdf$ of the normal (now the $x$ in the $pdf$ will be $\sqrt{y}$ to be plugged into the $e^{-\frac{x^2}{2}}$ part of the normal $pdf$); and remembering to in include $\frac{1}{\sqrt{y}}$ at the end:
$$ f_X(y)= F_X'(\sqrt[]{y})\,\frac{1}{\sqrt[]{y}}= \frac{1}{\sqrt{2\pi}}\,e^{-\frac{y}{2}}\, \frac{1}{\sqrt[]{y}}=\frac{1}{\sqrt{2\pi}}\,e^{-\frac{y}{2}}\, y^{\frac{1}{2}- 1}$$
Compare to the pdf of the chi square:
$$ f_X(x)= \frac{1}{2^{\nu/2}\Gamma(\frac{\nu}{2})}e^{\frac{-x}{2}}x^{\frac{\nu}{2}-1}$$
Since $\Gamma(1/2)=\sqrt{\pi}$, for $1$ df, we have derived exactly the $pdf$ of the chi square.
Further, if we call the function prop.test()
in R we are invoking the same $\chi^2$ test as if we decide upon chisq.test()
.
THE QUESTION:
So I get all these points, yet I still don't know how they apply to the actual implementation of these two tests for two reasons:
A z-test is not squared.
The actual test statistics are completely different:
The value of the test-statistic for a $\chi^2$ is:
$\chi^2 = \sum_{i=1}^{n} \frac{(O_i - E_i)^2}{E_i} = N \sum_{i=1}^n p_i \left(\frac{O_i/N - p_i}{p_i}\right)^2$ where
$\chi^2$ = Pearson's cumulative test statistic, which asymptotically approaches a $\chi^2$ distribution. $O_i$ = the number of observations of type $i$; $N$ = total number of observations; $E_i$ = $N p_i$ = the expected (theoretical) frequency of type $i$, asserted by the null hypothesis that the fraction of type $i$ in the population is $p_i$; $n$ = the number of cells in the table.
On the other hand, the test statistic for a $z$-test is:
$ \displaystyle Z = \frac{\frac{x_1}{n_1}-\frac{x_2}{n_2}}{\sqrt{p\,(1-p)(1/n_1+1/n_2)}}$ with $\displaystyle p = \frac{x_1\,+\,x_2}{n_1\,+\,n_2}$, where $x_1$ and $x_2$ are the number of "successes", over the number of subjects in each one of the levels of the categorical variables, i.e. $n_1$ and $n_2$.
This formula seems to rely on the binomial distribution.
These two tests statistics are clearly different, and result in different results for the actual test statistics, as well as for the p-values: 5.8481
for the $\chi^2$ and 2.4183
for the z-test, where $\small 2.4183^2=5.84817$ (thank you, @mark999). The p-value for the $\chi^2$ test is 0.01559
, while for the z-test is 0.0077
. The difference explained by two-tailed versus one-tailed: $\small 0.01559/2=0.007795$ (thank you @amoeba).
So at what level do we say that they are one and the same?
chisq.test()
, have you tried usingcorrect=FALSE
? $\endgroup$