G-test of independence
The G-test may be used both as a test of goodness-of-fit (comparing frequencies of one nominal variable to theoretical expecations) and as a test of independence (comparing frequencies of one nominal variable for different values of a second nominal variable). The underlying arithmetic of the test is the same. Goodness-of-fit tests and tests of independence are used for quite different experimental designs and test different null hypotheses, so I treat the G-test of goodness-of-fit and the G-test of independence as two distinct statistical tests.
When to use it
The G-test of independence is used when you have two nominal variables, each with two or more possible values. A data set like this is often called an "R×C table," where R is the number of rows and C is the number of columns. For example, if you surveyed the frequencies of three flower phenotypes (red, pink, white) in four geographic locations, you would have a 3×4 table. You could also consider it a 4×3 table; it doesn't matter which variable is the columns and which is the rows.
It is also possible to do a G-test of independence with more than two nominal variables, but that experimental design doesn't occur very often and is rather complicated to analyze and interpret, so I won't cover it.
Null hypothesis
The null hypothesis is that the relative proportions of one variable are independent of the second variable; in other words, the proportions at one variable are the same for different values of the second variable. In the flower example, you would probably say that the null hypothesis was that the proportions of red, pink and white were the same at the four locations.
For some experiments, you can express the null hypothesis in two different ways, and either would make sense. For example, when an individual clasps their hands, there is one comfortable position; either the right thumb is on top, or the left thumb is on top. Downey (1926) collected data on the frequency of right-thumb vs. left-thumb clasping in right-handed and left-handed individuals. You could say that the null hypothesis is that the proportion of right-thumb-clasping is the same for right-handed and left-handed individuals, or you could say that the proportion of right-handedness is the same for right-thumb-clasping and left-thumb-clasping individuals.
How the test works
The math of the G-test of independence is the same as for the G-test of goodness-of-fit, only the method of calculating the expected frequencies is different. For the goodness-of-fit test, a theoretical relationship is used to calculate the expected frequencies. For the test of independence, only the observed frequencies are used to calculate the expected. For the hand-clasping example, Downey (1926) found 190 right-thumb and 149 left-thumb-claspers among right-handed women, and 42 right-thumb and 49 left-thumb-claspers among left-handed women. To calculate the estimated frequency of right-thumb-claspers among right-handed women, you would first calculate the overall proportion of right-thumb-claspers: (190+42)/(190+42+149+49)=0.5395. Then you would multiply this overall proportion times the total number of right-handed women, 0.5395×(190+149)=182.9. This is the expected number of right-handed right-thumb-claspers under the null hypothesis; the observed number is 190. Similar calculations would be done for each of the cells in this 2×2 table of numbers.
(In practice, the calculations for the G-test of independence use shortcuts that don't require calculating the expected frequencies; see Sokal and Rohlf, pp. 731-732.)
The degrees of freedom in a test of independence are equal to (number of rows)−1 × (number of columns)−1. Thus for a 2×2 table, there are (2−1)×(2−1)=1 degree of freedom; for a 4×3 table, there are (4−1)×(3−1)=6 degrees of freedom.
Example
Gardemann et al. (1998) surveyed genotypes at an insertion/deletion polymorphism of the apolipoprotein B signal peptide in 2259 men. Of men without coronary artery disease, 268 had the ins/ins genotype, 199 had the ins/del genotype, and 42 had the del/del genotype. Of men with coronary artery disease, there were 807 ins/ins, 759 ins/del, and 184 del/del.
The biological null hypothesis is that the apolipoprotein polymorphism doesn't affect the likelihood of getting coronary artery disease. The statistical null hypothesis is that the proportions of men with coronary artery disease are the same for each of the three genotypes.
The result is G=7.30, 2 d.f., P=0.026. This indicates that the null hypothesis can be rejected; the three genotypes have significantly different proportions of men with coronary artery disease.
Graphing the results
The data used in a test of independence are usually displayed with a bar graph, with the values of one variable on the X-axis and the proportions of the other variable on the Y-axis. If the variable on the Y-axis only has two values, you only need to plot one of them:
![]() |
| A bar graph for when the nominal variable has only two values. |
If the variable on the Y-axis has more than two values, you should plot all of them. Sometimes pie charts are used for this:
![]() |
| A pie chart for when the nominal variable has more than two values. |
But as much as I like pie, I think pie charts make it difficult to see small differences in the proportions. In this situation, I prefer bar graphs:
![]() |
| A bar graph for when the nominal variable has more than two values. |
Similar tests
The G-test of independence gives approximately the same results as the chi-squared test of independence. Unlike the chi-square test statistics, G-values are additive, which means they can be used for more elaborate statistical designs. The G-test is therefore preferred by many, even for simpler designs where the additivity is not important.
If the expected numbers in some classes are small, the G-test will give inaccurate results. In that case, you should use Fisher's exact test if there are only two variables with two classes in each. See the web page on small sample sizes for further discussion.
Power analysis
For a 2×2 table with equal sample sizes, you can do a power analysis with this power analysis web page. This web page is set up for one-tailed tests, rather than the more common two-tailed tests, so enter alpha = 2.5 instead of alpha = 5 percent. If you enter 50% for sample 1 percentage, 55% for sample two percentage, 2.5% for alpha and 10% for beta, the results will say "Sample size = 2094 for both samples!" This means that each sample size would have to be 2094, or a total of 4188 in the two samples put together.
For a 2×2 table with unequal sample sizes, you can use this power analysis web page. This page is set up for two-tailed tests, so enter alpha = 0.05. Enter power (which is 1 - beta) instead of beta; if you want the probability of a false negative (beta) to be 10 percent, enter 90 in the "power" box.
I don't know how to do a power analysis if one or both variables has more than two values.
How to do the test
Spreadsheet
I have set up an Excel spreadsheet that performs this test for up to 10 columns and 50 rows. It is largely self-explanatory; you just enter you observed numbers, and the spreadsheet calculates the G-test statistic, the degrees of freedom, and the P-value.
Web pages
I am not aware of any web pages that will do a G-test of independence.
SAS
Here is a SAS program that uses PROC FREQ for a G-test. It uses the handclasping data from above.
data handclasp; input thumb $ hand $ count; cards; rightthumb righthand 190 leftthumb righthand 149 rightthumb lefthand 42 leftthumb lefthand 49 ; proc freq data=handclasp; weight count; tables thumb*hand / chisq; run;
The output includes the following:
Statistics for Table of thumb by hand
Statistic DF Value Prob
------------------------------------------------------------
Chi-Square 1 2.8265 0.0927
Likelihood Ratio Chi-Square 1 2.8187 0.0932
Continuity Adj. Chi-Square 1 2.4423 0.1181
Cochran–Mantel–Haenszel Chi-Square 1 2.8199 0.0931
Phi Coefficient 0.0811
Contingency Coefficient 0.0808
Cramer's V 0.0811
The "Likelihood Ratio Chi-Square" is the P-value for the G-test; in this case, G=2.8187, 1 d.f., P=0.0932.
Further reading
Sokal and Rohlf, pp. 729-739.
Zar, pp. 505-506.
References
Downey, J.E. 1926. Further observations on the manner of clasping the hands. American Naturalist 60: 387-391.
Gardemann, A., D. Ohly, M. Fink, N. Katz, H. Tillmanns, F.W. Hehrlein, and W. Haberbosch. 1998. Association of the insertion/deletion gene polymorphism of the apolipoprotein B signal peptide with myocardial infarction. Atheroslerosis 141: 167-175.
⇐ Previous topic | Next topic ⇒
This page was last revised January 2, 2008. Its address is http://udel.edu/~mcdonald/statgtestind.html.
©2007-2008 by John H. McDonald. You can probably do what you want with this content; see the permissions page at http://udel.edu/~mcdonald/statpermissions.html for details.


