Skip to main content

ASymCat

PyPI version Python versions CI Docs DOI License: MIT

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.

If you use ASymCat in research, please cite it: doi:10.5281/zenodo.23917211 (version 0.9.0; see Citation).

Install

pip install asymcat

ASymCat needs only FreqProb, NumPy and SciPy. For the plotting examples in the documentation, pip install "asymcat[viz]" adds matplotlib, seaborn and pandas.

Quick start

How English spellings map to sounds: the letter q is always pronounced /k/, but /k/ is spelled in several ways.

>>> from asymcat import CatScorer
>>> pairs = [("q", "k")] * 2 + [("c", "k")] * 6 + [("k", "k")] * 3 + [("c", "s")] * 4
>>> scorer = CatScorer(pairs)
>>> p_k_given_q, p_q_given_k = scorer.mle()[("q", "k")]
>>> round(p_k_given_q, 2), round(p_q_given_k, 2)
(1.0, 0.18)

Every measure returns, for each pair (x, y), a tuple (x→y, y→x). Here q predicts /k/ perfectly, while /k/ points back to q only 18% of the time. A symmetric measure would collapse the two numbers into one and hide exactly that difference.

From sequences to scores

ASymCat collects co-occurrences from paired sequences, such as aligned spellings and pronunciations, and from presence–absence matrices (read_sequences and read_pa_matrix load them from files). Any measure can then be scored, tested and plotted the same way:

>>> import asymcat
>>> words = [("cat", "kat"), ("cot", "kot"), ("city", "siti"), ("kit", "kit"), ("cent", "sent")]
>>> cooccs = asymcat.collect_cooccs(words, order=1)  # align position by position
>>> scorer = asymcat.CatScorer(cooccs, smoothing_method="laplace")
>>> [round(v, 2) for v in scorer.theil_u()[("c", "k")]]  # uncertainty coefficient
[0.18, 0.24]
>>> pvalues = scorer.permutation_pvalue("mle", n_permutations=999, seed=0)
>>> [round(float(p), 3) for p in pvalues[("c", "k")]]
[0.137, 0.137]
>>> xy, yx, x_labels, y_labels = asymcat.scorer.scorer2matrices(scorer.pmi())
>>> xy.shape  # one row per spelling symbol, one column per sound, ready to plot
(9, 8)

For sparse data, CatScorer(..., entropy_estimator="chao_shen") or "nsb" replaces the plug-in entropy behind the information-theoretic measures with a bias-corrected estimate.

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 set overlap set-based
tresoldi PMI tempered by conditional probability, for alignments specialized

The statistical tests also expose p-values (chi2_pvalue, fisher_pvalue, log_likelihood_ratio_pvalue). For any measure, permutation_pvalue and bootstrap_ci give resampling-based p-values and confidence intervals. Choosing a measure helps pick one, and each has a page of its own with its definition and a worked example.

Highlights

  • Directional by construction: every measure reports x→y and y→x separately.
  • One interface for every measure: swap scorer.mle() for scorer.theil_u() without changing anything else.
  • Built for sparse data: smoothing and bias-corrected entropy estimation from FreqProb.
  • Domain-neutral: linguistics, ecology, machine learning and categorical analytics; the repository ships sample datasets with their sources and licences.
  • Typed and tested: full type hints (py.typed), with tests on Python 3.10–3.12 across Linux, macOS and Windows.

Documentation

  • Tutorial: from pairs of observations to directional scores, tests and matrices.
  • Concepts: directional association, notation, choosing a measure and common pitfalls.
  • Measures: one page per measure, with its definition, a worked example, its properties and references.
  • How-to guides: preparing data, sparse data, significance testing, ranking scores and plotting.
  • API Reference: every public class and function, generated from the source.
  • References: the published source of each measure, with a BibTeX file.
  • Changelog and Migration guide.
  • FreqProb provides ASymCat's smoothed probabilities and bias-corrected entropy estimators.
  • SciPy's scipy.stats.contingency.association computes symmetric association for a whole contingency table (Cramér's V, Tschuprow's T, Pearson's contingency coefficient). ASymCat adds directional measures and scores every pair of categories.

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.9.0},
  doi     = {10.5281/zenodo.23917211},
  url     = {https://asymcat.tresoldi.org/}
}

The DOI 10.5281/zenodo.23917211 always resolves to the latest version, and the Zenodo record lists the DOI of each version. 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.9.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.9.0
File Size Uploaded Provenance Actions
asymcat-0.9.0.tar.gz 37.6 kB With provenance Details for asymcat-0.9.0.tar.gz

Built distribution (wheel)

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

Total release size: 70.9 kB

Release files / asymcat-0.9.0.tar.gz

Download URL asymcat-0.9.0.tar.gz
Size 37.6 kB
Tags Source
SHA-256 checksum
How to use checksums
674478df0c514b7851b4844f8ad75dfac50b813add17b8779b89235647f263eb
BLAKE2b-256 checksum
How to use checksums
a7f6ceed2b114956d07d8f063118303e34387d9e64868e8cde15f91d1354bb34
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 4, 2026.

Transparency log

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

Download URL asymcat-0.9.0-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3685b06159d2fd6e34517a148e316d6cf7e711a83b1a6924736fc1d5e8f54d6
BLAKE2b-256 checksum
How to use checksums
636e8f525cb8ae9a7e66d56286a86be66258b9c438c26c35a4eef37cee7d6217
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 4, 2026.

Transparency log

Security for asymcat 0.9.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.9.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 4, 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