# G-test vs Pearson's $\chi^2$ test

I'm testing independence in an $$N \times M$$ contingency table. I don't know whether the G-test or Pearson's $$\chi^2$$ test is better. The sample size is in the hundreds but there are some low cell counts. As stated on the Wikipedia page, the approximation to the $$\chi^2$$ distribution is better for the G-test than for Pearson's $$\chi^2$$ test. But I'm using Monte Carlo simulation to compute the p-value, so is there any difference between these two tests?

• Commented Aug 28, 2015 at 11:23

## 3 Answers

They are asymptotically the same. They are just different ways of getting at the same idea. More specifically, Pearson's $$\chi^2$$ test is a score test, whereas the $$G$$-test is a likelihood ratio test. To get a better sense of those ideas, it may help you to read my answer here: Why do my p-values differ between logistic regression output, $$\chi^2$$ test, and the confidence interval for the OR? To answer your direct question, if you are computing the p-value by Monte Carlo simulation, it shouldn't matter; you could just use whichever is more convenient for you. Note that there is no problem with low cell counts, only (potentially) low expected cell counts; it is possible to have low cell counts and have expected counts that are just fine. Furthermore, neither low actual counts nor low expected counts matters when the p-value is determined by simulation.

(For what it's worth, I would probably use Pearson's $$\chi^2$$, because R has a convenient function for that which includes the option of simulating the p-value.)

• what is the function in R? Commented Feb 20, 2018 at 1:50
• @llewmills, chisq.test. Commented Feb 20, 2018 at 2:37

Chi-square test and G-test usually produce similar results. But the most important thing here is you have to pick one of two tests and stick with it, not only for your mentioned test but for future tests during the course of your research. It is advisable because if you try to use both tests interchangeably, it is very likely that you will increase the chance of getting false positive.

• What is the reasoning by which the claim that the chance of a false positive is increased? (Unless you meant to suggest the test is chosen by reference to the actual counts - but then it's the referring to the counts to choose between them that's the problem, rather than the idea of potentially swapping tests per se) Commented Aug 9, 2016 at 8:16
• @Glen_b Chance of getting False Positive likely increases if we choose a p-value of the test that is more favorable to our assumptions (in case we try both tests) Commented Aug 10, 2016 at 12:13

Have a look at Rfast.

The relevant commands are

g2Test_univariate(data, dc)
g2Test_univariate_perm(data, dc, nperm)


The calculations are extremely fast. And in general prefer the $$G^2$$ test as the $$\chi^2$$ is an approximation to it.