Significance test
G-Test Calculator — Likelihood-Ratio Chi-Square
The G-test (likelihood-ratio chi-square) tests whether two categorical variables are independent, like the Pearson chi-square, but is built from the log-likelihood ratio of observed to expected counts; it uses the same degrees of freedom and usually gives a very similar result.
Reviewed by the crosstabs.com methods team · Last updated
Run this on your own data — free, no signup
Upload a CSV or XLSX. Everything runs in your browser; your file never leaves your device.
Open the workspace →What is the G-test?
The G-test is a likelihood-ratio test of independence for a contingency table. Like the Pearson chi-square, it asks whether the row and column variables are associated, but instead of summing (O − E)²/E it sums the log-likelihood ratio of each observed count against its expected count.
Both statistics are compared to the same chi-square distribution with the same degrees of freedom, and in practice they almost always lead to the same conclusion. The G-test is favoured by some analysts for sparse tables and because it is additive for nested log-linear models.
Formula
Definition
G = 2 × Σ O × ln(O / E)
- O
- = each observed cell count
- E
- = its expected count, (row total × column total) / grand total
- ln
- = the natural logarithm
- df
- = (rows − 1) × (columns − 1), the same as the Pearson chi-square; G is compared to the chi-square distribution
Worked example
Worked example
Suppose 110 people are cross-tabulated by whether they saw an ad (rows) and whether they bought (columns):
[[30, 10], [10, 60]] (n = 110)
Summing 2 × O × ln(O / E) over the four cells, using each cell's expected count E = (row total × column total) / grand total, gives:
G = 41.80 with df = (2 − 1) × (2 − 1) = 1, which is highly significant (p < 0.001).
For comparison, the Pearson chi-square on the same table is 40.55 — the two statistics are close, as they usually are.
When to use it
Use it when
- You want an alternative to the Pearson chi-square test of independence.
- You have a sparse contingency table — some analysts prefer the G-test here.
- You are fitting nested or log-linear models, where the G statistic is additive.
Not the right tool when
- You have a very small 2×2 sample — use Fisher's exact test instead, since the G-test relies on the same large-sample chi-square approximation.
- You need an exact p-value rather than a large-sample approximation.
How to interpret it
Rule of thumb
Compare G to the chi-square distribution with (r − 1)(c − 1) degrees of freedom; p < 0.05 indicates the variables are associated. G and the Pearson chi-square almost always agree.
Frequently asked questions
- G-test vs chi-square test?
- Both test whether two categorical variables are independent and use the same degrees of freedom, (r − 1)(c − 1). The chi-square sums (O − E)²/E, while the G-test sums 2 × O × ln(O/E) from the log-likelihood ratio. The two statistics are usually very close and almost always agree.
- When should I use the G-test?
- Use it as an alternative to the chi-square test of independence. Some prefer it for sparse tables, and it is additive for nested or log-linear models. Avoid it for very small 2×2 samples, where Fisher's exact test is better.
- Does the G-test use the same degrees of freedom as chi-square?
- Yes. The G-test uses (rows − 1) × (columns − 1) degrees of freedom, exactly the same as the Pearson chi-square, and G is compared to the same chi-square distribution.
References & further reading
- G-test — Wikipedia
- Sokal, R. R. & Rohlf, F. J. Biometry.
Try it on your own data — free, no signup
Upload a CSV or XLSX. Everything runs in your browser; your file never leaves your device.
Open the workspace →