asymcat

Asymmetric measures of association between categorical variables — a well-tested Python library for data exploration.

MIT·Python 3.10–3.12·GitHub·PyPI·Documentation

Most measures of association are symmetric: they report a single number for a pair of variables, as if the relationship between X and Y were the same as between Y and X. Many real relationships are not. Knowing a country often tells you its capital, yet a capital tells you its country far more decisively; one symptom may predict a disease while the disease barely predicts that symptom. ASymCat quantifies association separately in each direction, across a dozen probabilistic, information-theoretic, and statistical measures, behind one consistent interface.

Installation

pip install asymcat

Example

import asymcat

data   = asymcat.read_sequences("data.tsv")
coocs  = asymcat.collect_cooccs(data)
scorer = asymcat.scorer.CatScorer(coocs)

scores = scorer.mle()
scores[("a", "x")]   # (0.83, 0.20)  — P(x|a) vs P(a|x): the association is directional

Every measure returns a mapping from category pairs to a (x→y, y→x) tuple. A symmetric summary would collapse those two numbers into one and hide exactly the structure ASymCat is built to reveal: which variable predicts which, and how strongly, in each direction.

The asymmetry

x→y (predicting y from x) y→x (predicting x from y)
Figure 1. For each category pair, association is scored in both directions. When the two bars differ, the relationship is asymmetric — one category predicts the other better than the reverse. A single symmetric score would report only the average and lose this.

Measures

MeasureFamilyReports
mleprobabilisticP(y|x), P(x|y)
pmi, pmi_smoothedinformation-theoreticpointwise mutual information
theil_uinformation-theoreticuncertainty coefficient
cond_entropyinformation-theoreticconditional entropy
mutual_informationinformation-theoretic(normalized) MI
chi2, cramers_vstatisticalχ² association
fisherstatisticalexact odds ratio
log_likelihood_ratiostatisticalG² statistic
goodman_kruskal_lambdastatisticalproportional error reduction
jaccard_indexset-baseddirectional overlap
tresoldispecializedsmoothed measure for sequences

Statistical tests expose matching p-value scorers (chi2_pvalue, fisher_pvalue, log_likelihood_ratio_pvalue); a generic permutation_pvalue and bootstrap_ci provide significance and confidence intervals for any measure.

Across domains

Directional association between categories recurs wherever one kind of label helps predict another:

  • Linguistics. grapheme–phoneme correspondence and sound-change directionality.
  • Ecology. asymmetric species co-occurrence from presence–absence data.
  • Machine learning. feature screening by directional predictive strength.
  • Categorical analytics. dependency and information flow between discrete variables.

Documentation

Citation

@software{tresoldi_asymcat,
  author  = {Tresoldi, Tiago},
  title   = {ASymCat: Asymmetric measures of association between
             categorical variables},
  url     = {https://github.com/tresoldi/asymcat}
}