W = 1  W=0  Marginal

Totals

C = 1  c_{1}y  c_{1}n  c_{1}
C = 2  c_{2}y  c_{2}n  c_{2}
Marginal w_{1}, the number of objects w_{0}, the number of objects
Totals  with W =1  with W =0  n

Table 1: Contingency Table for C and W

Measuring Goodness-of-Fit with the log likelihood ratio test statistic.

Suppose you are assessing the correlation between two binary variables, C and W.

Each cell of the table corresponds to one combination of the values of C and W. G^{2} is calculated as follows, where the summation is over all combinations of values of C and W, and p(x) is the sample relative frequency of x:

G^{2} = −2n × ∑_{c,w} p(c, w) × log \frac{p(c, w)}{p(c) × p(w)}

The greater the G^{2} value, the poorer the fit of the model of independence between C and W.

The numerator of the log term corresponds to the model of interdependence between the variables, and the denominator corresponds to the model of independence between them (hence, the product of the probabilities). The log terms measure differences between the models: the greater the absolute value, the less similar they are. The overall sum is a weighted average of these difference measures: due to the p(c,w) term, the log terms for the more frequent combinations of variable values contribute more to the overall value of G^{2} than do the terms for the less frequent variable combinations.

In the specific case corresponding to table 1,G^{2} is as follows:

G^{2} = −2n × (\frac{c_{1}y}{n} × log \frac{c_{1}y × n}{c_{1} × w_{1}} + \frac{c_{1}n}{n} × log \frac{c_{1}n × n}{c_{1} × w_{0}} + \frac{c_{2}y}{n} × log \frac{c_{2}y × n}{c_{2} × w_{1}} + \frac{c_{2}n}{n} × log \frac{c_{2}n × n}{c_{2} × w_{0}})