Lably
Skip to content

G-test

Statistical test

  • 6 min read
  • 5 chapters

Related on Lably

Through Statistics, Statistical significance and Chi-squared test

Formulation

The general formula for test statistics of the G-test is

G=2∑iOi⋅ln⁡(OiEi),

where Oi≥0 is the observed count in a cell, Ei>0 is the expected count under the null hypothesis, ln denotes the natural logarithm, and the sum is taken over all non-empty cells. The resulting G is asymptotically chi-squared distributed as the total number of observations tends to infinity (convergence in distribution).

Furthermore, the total observed count must be equal to the total expected count:

∑iOi=∑iEi=N,

where N is the total number of observations.

Both, the G-test statistics G and the chi-square test statistics χ2 are special cases of a general family of power divergence statistics by Cressie and Read. For λ∉{0,−1} set

CRλ=2λ(λ+1)∑iOi((OiEi)λ−1).

Then,

G=limλ→0CRλ,χ2=CR1.

Derivation

We can derive the value of the G-test from the log-likelihood ratio test where the underlying model is a multinomial model.

Suppose we had a sample O=(O1,…,Om) where each Oi is the number of times that an object of type i was observed. Furthermore, let N=∑i=1mOi be the total number of observations. If we assume that the underlying model is multinomial, then the test statistic is defined by

ln⁡(L(p~|O)L(p^|O))=ln⁡(∏i=1mp~iOi∏i=1mp^iOi),

where p~=(p~1,…,p~m) is the null hypothesis and p^=(p^1,…,p^m) is the maximum likelihood estimate (MLE) of the parameters given the data. Recall that for the multinomial model, the MLE of p^i given some data is given by

p^i=OiN.

Furthermore, we may represent each null hypothesis parameter p~i as

p~i=EiN,

where Ei is the expected count of objects of type i under the null hypothesis. Thus, by substituting the representations of p~i and p^i in the log-likelihood ratio, the equation simplifies to

ln⁡(L(p~|O)L(p^|O))=ln⁡(∏i=1m(EiOi)Oi)=∑i=1mOiln⁡(EiOi)

Finally, multiply by a factor of −2 (used to make the G-test formula asymptotically equivalent to the Pearson's chi-squared test statistics) to achieve the form

G=−2∑i=1mOiln⁡(EiOi)=2∑i=1mOiln⁡(OiEi)

Heuristically, one can imagine Oi as continuous and approaching zero, in which case Oiln⁡Oi→0, and terms with zero observations can simply be dropped. However the expected count in each cell must be strictly greater than zero for each cell (Ei>0 for all i) to apply the method.

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Statistics