Theil's U¶
CatScorer.theil_u() · directional · range \([0, 1]\) · information-theoretic
Theil's U, or the uncertainty coefficient (Theil, 1970), is the share of the uncertainty about one variable that knowing the other removes. 0 means that knowing \(x\) says nothing about \(y\); 1 means that it determines \(y\) completely. It is the information-theoretic counterpart of the conditional probability, and corrects for the base rate.
Definition¶
For two variables \(X\) and \(Y\),
with \(U(Y \mid X) = 1\) by convention when \(H(Y) = 0\). In ASymCat, the variables are the first and second elements of the pair subset \(S(x, y)\), the co-occurrences whose first element is \(x\) or whose second element is \(y\):
The entropies follow the scorer's entropy_estimator: the plug-in
(maximum-likelihood) estimate by default, or the bias-corrected "chao_shen"
and "nsb" estimators from FreqProb (see
Work with sparse data).
Example¶
With the example data:
>>> from asymcat import CatScorer
>>> pairs = [("q", "k")] * 2 + [("c", "k")] * 6 + [("k", "k")] * 3 + [("c", "s")] * 4
>>> theil_u = CatScorer(pairs).theil_u()
>>> [round(u, 3) for u in theil_u[("c", "k")]]
[0.226, 0.152]
>>> [round(u, 3) for u in theil_u[("q", "k")]]
[1.0, 0.0]
>>> theil_u[("k", "s")]
(1.0, 1.0)
cand /k/: the subset is the whole dataset. Knowing the letter removes 23% of the uncertainty about the sound, and knowing the sound removes 15% of the uncertainty about the letter.qand /k/: the subset is the column of /k/, where the sound is always /k/. Its entropy is zero, so \(U(Y_S \mid X_S) = 1\) by convention, and knowing the sound says nothing about which ofc,korqspelled it.kand /s/: the subset holdsk–/k/ andc–/s/. Each letter determines the sound and each sound the letter, so both scores are 1, althoughkand /s/ never occur together. Theil's U measures predictability, not attraction: see Pitfalls.
Properties¶
- Directional. \(U(Y \mid X) \neq U(X \mid Y)\) in general; both share the numerator \(I(X; Y)\) and differ in the entropy they normalize by.
- Corrected for the base rate. A frequent \(y\) does not by itself raise the score, unlike \(P(y \mid x)\).
- Unsigned. Avoidance is as predictive as attraction.
- A convention on degenerate subsets. When one variable takes a single value in the subset, its score is 1 (no uncertainty left to remove), as for Goodman–Kruskal λ.
- Bias-corrected estimates leave \([0, 1]\). With
"chao_shen"or"nsb", a slightly negative score on a small subset means no detectable association. The plug-in estimate can also print as-0.0.
API¶
theil_u ¶
Return a Theil's U uncertainty scorer.
For every pair (x, y) this computes Theil's U in both directions
over the subset of co-occurrences where pair[0] == x or
pair[1] == y, matching compute_theil_u(Y, X) and
compute_theil_u(X, Y) on that subset. The underlying entropies are
computed with a vectorized formulation (see
_subset_entropy_components) that evaluates all pairs at once
rather than re-filtering the co-occurrence list for each pair.
Entropies follow the scorer's entropy_estimator. Bias-corrected
estimates are not confined to [0, 1]: a slightly negative value on
a small subset means no detectable association.
The whole-variable version, for two aligned series rather than a pair of
symbols, is asymcat.correlation.theil_u.
References¶
- Theil (1970); Shannon (1948); Cover & Thomas (2006). See References.