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?