Skip to main content

ASymCat

CI Docs PyPI version Python versions License: MIT Code style: ruff

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 PMI tempered by conditional probability, for alignments 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→y and y→x separately, surfacing asymmetries symmetric measures average away.
  • One consistent API across a dozen measures — swap scorer.mle() for scorer.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 — definition, properties and caveats of the specialized tresoldi measure.
  • API Reference — every public class and function, generated from the source.
  • References — the published source of each measure, with a BibTeX file.

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/; see resources/README.md for their sources and licences.

Citation

If you use ASymCat in published work, please cite the version you used:

@software{tresoldi_asymcat,
  author  = {Tresoldi, Tiago},
  title   = {{ASymCat}: Asymmetric measures of association between
             categorical variables},
  year    = {2026},
  version = {0.8.0},
  url     = {https://asymcat.tresoldi.org/}
}

See How to cite for APA and classic BibTeX forms, and References for the papers behind each measure. Citation metadata is also in CITATION.cff.

License

MIT — see LICENSE.

Metadata

Release files for asymcat 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asymcat 0.8.0
File Size Uploaded Provenance Actions
asymcat-0.8.0.tar.gz 36.5 kB With provenance Details for asymcat-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for asymcat 0.8.0
File Interpreter ABI Platform Actions
asymcat-0.8.0-py3-none-any.whl Python 3 none any Details for asymcat-0.8.0-py3-none-any.whl

Total release size: 69.1 kB

Release files / asymcat-0.8.0.tar.gz

Download URL asymcat-0.8.0.tar.gz
Size 36.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b63b21bc9b3d8e02ce1a17072adbabbbc08ed6da2d6c1026d143bac02dd0b6c2
BLAKE2b-256 checksum
How to use checksums
2741774399cfc5185d361cd52c02fdfe3df294ccee2615795fc5b20a59ade550
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 log

Release files / asymcat-0.8.0-py3-none-any.whl

Download URL asymcat-0.8.0-py3-none-any.whl
Size 32.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b297850a97ff862c651d9a4ed57cc30e1c41f7f87cc18f17b8053fdac05b6f5
BLAKE2b-256 checksum
How to use checksums
d55e7895ef5707495b40b80cf3e6701a4bfdf8b0ae758aee6228bbd09f52a01e
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 log

Security for asymcat 0.8.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.

Select from 2 files

Attestation for asymcat-0.8.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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page