Log-likelihood ratio (G²)¶
CatScorer.log_likelihood_ratio(),
CatScorer.log_likelihood_ratio_pvalue() · symmetric · statistical
The log-likelihood ratio statistic \(G^2\) compares the likelihood of the 2×2 table under independence with its likelihood without that constraint. Dunning (1993) introduced it to computational linguistics as an alternative to chi-square for rare events, and it is widely used for collocation extraction.
Definition¶
With \(O_{ij}\) the observed and \(E_{ij}\) the expected counts of the table, as for chi-square,
where empty cells contribute 0. ASymCat applies no continuity correction.
log_likelihood_ratio_pvalue returns the p-value from the \(\chi^2\)
distribution with one degree of freedom, which \(G^2\) follows asymptotically
under independence. Both are symmetric, so both tuple entries are equal.
Example¶
With the example data:
>>> from asymcat import CatScorer
>>> pairs = [("q", "k")] * 2 + [("c", "k")] * 6 + [("k", "k")] * 3 + [("c", "s")] * 4
>>> scorer = CatScorer(pairs)
>>> round(scorer.log_likelihood_ratio()[("c", "k")][0], 3)
3.937
>>> round(scorer.log_likelihood_ratio_pvalue()[("c", "k")][0], 3)
0.047
On the same table, the Yates-corrected chi-square gives \(p = 0.30\) and Fisher's exact test \(p = 0.23\). With so few observations, the asymptotic tests disagree, and the exact test is the one to trust.
Properties¶
- Additive. \(G^2\) decomposes over nested tables, which makes it convenient for model comparison.
- Asymptotically equivalent to chi-square, and neither is reliable when expected counts are small: without a continuity correction, \(G^2\) tends to be anti-conservative there, as above. Prefer Fisher's exact test for sparse tables.
- Unsigned. Check the sign of PMI or the odds ratio for the direction of the departure.
API¶
log_likelihood_ratio ¶
Return a Log-Likelihood Ratio (G²) scorer.
Computes the G² statistic as an alternative to Chi-square that works better with small expected frequencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
square_ct
|
bool
|
Whether to return the score over the 2x2 contingency table (default:
True). |
True
|
Returns:
| Type | Description |
|---|---|
Dict[Tuple[Any, Any], Tuple[float, float]]
|
Dictionary mapping symbol pairs to (G²(X,Y), G²(Y,X)) tuples. |
log_likelihood_ratio_pvalue ¶
Return the p-values of the Log-Likelihood Ratio (G²) test.
This is the significance counterpart to log_likelihood_ratio:
under the null hypothesis of independence, G² is asymptotically
chi-square distributed, and this returns the corresponding p-value for
each pair. As with the other symmetric statistical tests, both tuple
entries hold the same value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
square_ct
|
bool
|
Whether to compute the p-value over the 2x2 contingency table
(default: True). |
True
|
Returns:
| Type | Description |
|---|---|
Dict[Tuple[Any, Any], Tuple[float, float]]
|
Dictionary mapping symbol pairs to (p-value, p-value) tuples. |
References¶
- Dunning (1993). See References.