Skip to main content

ba

Bayesian Association — a unified probabilistic framework for exploring associations in categorical data, with dedicated support for QCA and Association Rule Mining.

To install: pip install ba

Claude Code skills

ba ships with two Claude Code skills in .claude/skills/:

  • ba-user — For anyone using ba as a library: choosing priors, interpreting Bayes factors, writing QCA workflows, mining rules, handling small-sample warnings. Useful prompts that would trigger this skill automatically (if it's in scope):
    • "Analyze my DataFrame for pairwise associations with Bayesian credible intervals"
    • "What prior should I use for a dataset with only 15 cases?"
    • "Walk me through a QCA analysis with calibration and Boolean minimization"
  • ba-contributor — For developers modifying ba's source: adding measures to the registry, extending the Bayesian or QCA layers, writing tests, understanding the ContingencyTable hierarchy and Pot bridge.

You can invoke a skill explicitly via the slash command:

/ba-user Help me set up a prior sensitivity analysis for this 2×2 table

To make the skill available in another project, symlink it into that project's .claude/skills/ directory:

# Make ba-user available in a specific project
mkdir -p /path/to/my-project/.claude/skills
ln -s /path/to/ba/.claude/skills/ba-user /path/to/my-project/.claude/skills/ba-user

# Or make it globally available (triggers across all projects)
ln -s /path/to/ba/.claude/skills/ba-user ~/.claude/skills/ba-user

See the skills documentation for more on skill scoping, and the Claude Code configuration guide for managing project vs. user-level settings.

Quick start

import ba

# Analyze all pairwise associations in a DataFrame
result = ba.analyze(df, outcome="Y")
result.summary()  # metrics + Bayesian CIs for every pair
result.top_pairs(5)  # strongest, most certain associations

Single-pair analysis

ct = ba.contingency_table(a=10, b=5, c=3, d=12)
ct.odds_ratio  # 8.0
ct.phi  # 0.471
ct.metrics(["lift", "phi", "cramers_v"])

# Bayesian posterior
post = ba.bayesian.posterior(ct, prior="jeffreys")
post.credible_interval["risk_difference"]  # (0.12, 0.71)
post.prob_gt(0.0, "risk_difference")  # 0.996

Per-tradition APIs

# Bayesian
ba.bayesian.posterior(ct, prior="uniform")
ba.bayesian.bayes_factor(ct)
ba.bayesian.sensitivity(ct, priors=["jeffreys", "uniform", "beta(2,2)"])

# QCA
binary_df = ba.qca.calibrate(df, {"age": 30, "illness": "any_present"})
tt = ba.qca.truth_table(binary_df, outcome="Y", conditions=["A", "B", "C"])
solution = ba.qca.minimize(tt)
ba.qca.necessity(binary_df, "Y", ["A", "B"])

# Association Rule Mining
rules = ba.rules.mine(df, min_support=0.1, outcome="Y")

Key features

  • Categorical core, binary specialization. The core handles r×c contingency tables. Binary (2×2) is a specialization with extra metrics (OR, RR, phi, Yule's Q, QCA consistency/coverage).
  • Uncertainty first. Every metric comes with Bayesian credible intervals. Bayes factors replace p-values as the default evidence measure.
  • 22 built-in measures in an extensible registry — from support/lift to Cramér's V, mutual information, and Goodman-Kruskal gamma.
  • QCA pipeline: calibrate → truth table → Quine-McCluskey minimization → necessity/sufficiency analysis, all with Bayesian CIs.
  • Association rules with Bayesian augmentation, appearance constraints, and built-in brute-force mining (no mlxtend dependency required).
  • Progressive disclosure. ba.analyze() for one-liners; ba.bayesian/ba.rules/ba.qca for per-tradition control; ContingencyTable/MeasureRegistry for full access.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ba-0.3.1.tar.gz (128.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ba-0.3.1-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file ba-0.3.1.tar.gz.

File metadata

  • Download URL: ba-0.3.1.tar.gz
  • Upload date:
  • Size: 128.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ba-0.3.1.tar.gz
Algorithm Hash digest
SHA256 c0eaad0519a0264712e10ce915bd972ef352e7656cd38a10651d9854161c85a4
MD5 290696af0aaa3bd94020ac328b262c78
BLAKE2b-256 e93424855288ea0c7fb90a6789d8841f35c297211a1b1327df9cbec8423a0dc6

See more details on using hashes here.

File details

Details for the file ba-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: ba-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ba-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a54bdeb6a1e782b742430399d69144d2d45b7aa3e00bb155aa528b11a880215d
MD5 d101444a12a01524b846c7aada3b253c
BLAKE2b-256 3f4078bd077b70b3b64c00499b81d045c5ab72dd409b79451815316176322483

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 files

0.2.0

2 files

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1.0

1 file

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page