0
$\begingroup$

Does the chi squared test work if the variables have different levels? Here's an example

x <- factor(sample(c('a', 'b', 'c'), 100, replace = T))
y <- factor(ifelse(x == 'a', 'd', 'e'))

The contingency table includes zeros:

table(x, y)

   y
x    d  e
  a 29  0
  b  0 39
  c  0 32

Running chisq.test(x, y) gives a very small p-value, so x and y are not independent. This is the correct result, but I thought one of the assumptions behind chisq.test is that there needs to be no zeros in the contingency table (point 6 in this paper).

What's going on here? To me, it looks like chisq.test shouldn't work, since not all of the assumptions are met, but the result from the test is correct?

$\endgroup$
1
  • 2
    $\begingroup$ The paper doesn't say what you say that it says... $\endgroup$
    – Glen_b
    Commented Mar 2, 2020 at 2:28

1 Answer 1

6
$\begingroup$

First, the assumption is about the cells of the expected table. None of the cells in your expected table would be 0.

Second, "not working" doesn't mean it won't give a correct answer. When assumptions fail then you lack the full guarantee of the things that have been proven to be true. But you could still get a factually accurate result if you use the method while flouting the assumptions.

That said, the assumption of no zeroes in the expected counts is necessary because of how the chi-square statistic is calculated. If you had actually failed this assumption then running the test would have thrown an error.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.