ASymCat
Measure association between categorical variables — separately in each direction.
Most association measures are symmetric: they report one 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. ASymCat scores association in both
directions across a dozen probabilistic, information-theoretic, and statistical
measures, behind one consistent interface.
import asymcat
data = asymcat.read_sequences("data.tsv")
coocs = asymcat.collect_cooccs(data)
scorer = asymcat.CatScorer(coocs)
scorer.mle()[("a", "x")] # (0.83, 0.20) — P(x|a) vs P(a|x)
That tuple is the whole point: a symmetric summary would collapse the two numbers into one and hide exactly the structure ASymCat is built to reveal — which variable predicts which, and how strongly, in each direction.
Install
pip install asymcat
ASymCat itself needs only FreqProb, NumPy and SciPy. For the plotting examples
in the documentation, pip install "asymcat[viz]" adds matplotlib, seaborn and
pandas.
The interface
The workflow is always the same: read data into paired sequences (or a
presence–absence matrix), collect the co-occurrences, build a CatScorer, then
call a measure. Every measure returns a mapping from category pairs to a
(x→y, y→x) tuple.
import asymcat
data = asymcat.read_sequences("data.tsv") # or asymcat.read_pa_matrix(...)
coocs = asymcat.collect_cooccs(data) # order=2, pad="#" for n-grams
scorer = asymcat.CatScorer(coocs, smoothing_method="laplace", smoothing_alpha=1.0)
scorer.mle() # P(y|x), P(x|y)
scorer.theil_u() # uncertainty coefficient in each direction
scorer.pmi() # pointwise mutual information
scorer.fisher() # exact odds ratios
# Turn any scored measure into matrices for plotting
xy, yx, x_labels, y_labels = asymcat.scorer.scorer2matrices(scorer.pmi())
Choosing a measure
| Measure | Use it for | Family |
|---|---|---|
mle |
conditional probabilities P(y|x), P(x|y) |
probabilistic |
pmi / pmi_smoothed |
co-occurrence strength vs. independence | information-theoretic |
theil_u |
directional predictability (uncertainty coefficient) | information-theoretic |
cond_entropy / mutual_information |
information remaining / shared | information-theoretic |
chi2 / cramers_v |
strength of statistical association | statistical |
fisher |
exact odds ratios for small samples | statistical |
log_likelihood_ratio |
G² association statistic | statistical |
goodman_kruskal_lambda |
proportional reduction in prediction error | statistical |
jaccard_index |
directional set overlap | set-based |
tresoldi |
smoothed measure tuned for sequence alignment | specialized |
Significance and uncertainty. The statistical tests expose matching p-value
scorers (chi2_pvalue, fisher_pvalue, log_likelihood_ratio_pvalue). For any
measure — including the information-theoretic ones with no closed-form null —
permutation_pvalue(measure, ...) estimates significance by shuffling the x↔y
pairing, and bootstrap_ci(measure, ...) returns percentile confidence intervals
by resampling the co-occurrences.
scorer.chi2_pvalue() # closed-form p-values
scorer.permutation_pvalue("theil_u", n_permutations=1000, seed=0)
scorer.bootstrap_ci("theil_u", n_bootstrap=1000, confidence_level=0.95, seed=0)
Sparse data. Plug-in entropy is biased low on small samples, and that bias
carries into Theil's U, conditional entropy and mutual information. Pass
entropy_estimator="chao_shen" (fast) or "nsb" (Bayesian, slower) to use
FreqProb's bias-corrected estimators; permutation tests and bootstrap intervals
then use the same estimator.
scorer = asymcat.CatScorer(coocs, entropy_estimator="chao_shen")
scorer.theil_u()
Why ASymCat
- Directional by construction — every measure reports
x→yandy→xseparately, surfacing asymmetries symmetric measures average away. - One consistent API across a dozen measures — swap
scorer.mle()forscorer.theil_u()without changing anything else. - Built for sparse data via FreqProb: smoothing for stable probability estimates, and bias-corrected entropy estimators for the information-theoretic measures.
- Typed and tested — full type hints (
py.typed), strict linting and type-checking, and a test suite run across Python 3.10–3.12.
Documentation
- Documentation site — user guide and full API reference.
- User Guide — concepts, measure selection, data preparation, and worked examples.
- The Tresoldi Measure — motivation and
definition of the specialized
tresoldimeasure. - API Reference — every public class and function, generated from the source.
Applications
Directional association between categories recurs across fields: grapheme–phoneme
correspondence and sound-change directionality in linguistics; asymmetric
species co-occurrence in ecology; feature screening in machine learning;
and dependency analysis in categorical analytics. Sample datasets for several
of these live in resources/.
Citation
If you use ASymCat in academic research, please cite:
@software{tresoldi_asymcat,
author = {Tresoldi, Tiago},
title = {ASymCat: Asymmetric measures of association between categorical variables},
url = {https://github.com/tresoldi/asymcat}
}
License
MIT — see LICENSE.
Metadata
Release files for asymcat 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asymcat-0.7.0.tar.gz | 35.9 kB | With provenance | Details for asymcat-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asymcat-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for asymcat-0.7.0-py3-none-any.whl |
Total release size: 68.0 kB
Release files / asymcat-0.7.0.tar.gz
| Download URL | asymcat-0.7.0.tar.gz |
|---|---|
| Size | 35.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34c1c73c27db6c3f74d28fd62e2ea5ce9c71f6c5cf578d15e5580c5a64ede4c6
|
|
BLAKE2b-256 checksum How to use checksums |
baafc9dc415564051533ef707eaf1e941aadcab4302700684fe5db8230745cdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logRelease files / asymcat-0.7.0-py3-none-any.whl
| Download URL | asymcat-0.7.0-py3-none-any.whl |
|---|---|
| Size | 32.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d9c5c4bc58261479c9ac1a1acfb050707bcaf31be3c5897bf1852f7ebd851188
|
|
BLAKE2b-256 checksum How to use checksums |
e7e77659543a52206cfae47c731eb7912b1457ba2f682e988e06d06fa50b2881
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logSecurity for asymcat 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for asymcat-0.7.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.