# If $\chi^2=0$ for a dataset, are the frequencies of the values in the contingency table all the same?

Could I say that if the $\chi^2$ value of a dataset is $0$, then the frequencies of the values of the cells in the contingency table are all the same? I have noticed that if I change the frequency of any of these values to be more than the other, that $\chi^2$ stops being $0$.

$$\begin{array}{lcc}\quad&1&2\\1&8&8\\2&8&8\end{array}$$

$\chi^2=0$

Any help appreciated

-

It depends on which chi-square test you're talking about. There are many. One frequently used chi-square test with contingency tables is a test of independence of rows and columns. Consider this table: $$\begin{array}{rr|r} \hline 2 & 12 & 14 \\ 3 & 18 & 21 \\ \hline 5 & 30 & 35 \end{array}$$ The numbers in the rightmost column to the right of the vertical line are the sums of the numbers in the rows to the left of the line; the numbers in the bottom row below the horizontal line are the sums of the numbers in the columns above the line; the 35 in the lower right is the sum of the two numbers above it, or equivalently, of the two numbers to its left, or, again equivalently, of the four numbers in the $2\times 2$ table above and to the left of the margins.

Take the number in each cell in the $2\times 2$ table to be the number of individuals in the sample that fall in that cell. The null hypothesis says the probability that an individual is in a particular row is independent of which column that individual is in and vice-versa. The observed numbers are totals in the sample rather than in the population, so you generally won't see perfect independence in the sample even if the null hypothesis is true. Since they're based on the sample rather than on the whole population, if we say the probability of being in the first row is $14/35 = 2/5$ (taking the numbers 14 and 21 from the right margin), that is an estimate. Similarly we can estimate the probability of being in the first column as $5/35 = 1/7$. The probability of being in the cell that is the upper left corner of the table, assuming that the null hypothesis of independence is true, is therefore estimated as $(14/35) \times (5/35) = 2/35$. Since the sample size is 35, the expected count in the first cell is therefore $(14/35) \times (5/35) \times 35$ (and the obvious cancelation of 35 with 35 would happen even if all of the numbers had been different). Call this estimated expected value the expected count in the first cell.

In various chi-square tests (not all chi-square tests, but most chi-square tests that involve categorical data), the test statistic can be written as $$\sum \frac{(\text{observed} - \text{expected})^2}{\text{expected}}.$$

If you work out the chi-square test statistic for the table with the particular numbers I've put there, you'll find it's exactly 0, simply because I chose the numbers to make that happen.

But the four numbers are not equal.

On the other hand, if you're doing the simple chi-square test of the null hypothesis that says an ordinary six-sided die is "fair", then the "expected" counts will each be $1/6$ of the sample size---thus all equal to each other---and the chi-square test statistic then won't be 0 unless all six counts in the sample are equal.

A shorter answer than Michael Hardy's (which is good, by the way): the test statistics you're dealing with are probably of the form $$\sum_i {(O_i - E_i)^2 \over E_i}.$$ where $O_i$ are observed counts and $E_i$ are expected counts. This will be zero, not if all the $O_i$ are the same, but if all the $O_i$ are equal to the corresponding $E_i$. That is, chi-squared is zero in these cases if the observed counts are equal to the corresponding expected counts.