Skip to main content

A toolkit for robust conditional independence testing in causal discovery.

Project description

citests: A Conditional Independence Test Toolkit

Documentation License: MIT

Full documentation is hosted on GitHub Pages.

citests is a Python library that provides a comprehensive toolkit for conditional independence (CI) testing. It is designed to be seamlessly integrated with the causal-learn package and offers a collection of partial correlation, contingency table, regression, nearest neighbor, kernel, and machine-learning-based CI tests, plus adapter strategies.

The library is structured to be a powerful benchmark for causal discovery and a practical toolkit for researchers and practitioners.

Features

  • causal-learn compatible: All tests are designed as drop-in replacements for the standard tests in the causal-learn ecosystem, allowing you to easily use them with algorithms like PC.

Installation

Install directly from GitHub with pip:

pip install git+https://github.com/averinpa/citests.git

For local development with extras:

uv sync --all-extras

Optional dependency groups in pyproject.toml:

  • pycomets — required for gcm, wgcm, pcm (installs xgboost only; pycomets itself is GitHub-only and must be installed separately: pip install git+https://github.com/shimenghuang/pycomets.git)
  • tigramite — required for cmiknn, cmiknn_mixed, regci
  • r — required for rcit, rcot, ci_mm, hartemink_chisq (installs rpy2); the corresponding R packages must also be installed:
    • RCIT from GitHub ericstrobl/RCIT (for rcit, rcot)
    • MXM from CRAN (for ci_mm)
    • bnlearn from CRAN (for hartemink_chisq)

The mcmiknn test uses a vendored copy of the upstream hpi-epic/mCMIkNN source under citests/_vendor/indeptests/; no additional installation is required.

Quickstart Example

Here is a simple example of how to use a citests test within the causal-learn PC algorithm.

import numpy as np
from causallearn.search.ConstraintBased.PC import pc
import citests.tests 

# 1. Generate some data
np.random.seed(42)
data = np.random.randn(200, 3)
data[:, 2] = 0.5 * data[:, 0] + 0.5 * data[:, 1] + 0.1 * np.random.randn(200)

# 2. Run the PC algorithm using a citests test
# Example test ids: "fisherz_citests", "spearman", "gsq", "chisq", "kci", "gcm"
cg = pc(data, alpha=0.05, indep_test='spearman')

# 3. View the learned graph
print("Learned Graph Edges:")
print(cg.G.get_edges())

Available Tests

Test Name Family Wrapped From
fisherz_citests Partial Correlation causal-learn (CIT(..., method_name="fisherz"))
spearman Partial Correlation causal-learn Fisher-Z on ranked data
chisq Contingency Table causal-learn (Chisq_or_Gsq(..., method_name="chisq"))
gsq Contingency Table causal-learn (Chisq_or_Gsq(..., method_name="gsq"))
regci Regression tigramite.independence_tests.regressionCI.RegressionCI (optional)
ci_mm Regression R MXM::ci.mm via rpy2 (optional)
cmiknn Nearest Neighbor tigramite.independence_tests.cmiknn.CMIknn (optional)
cmiknn_mixed Nearest Neighbor tigramite CMIknnMixed wrapper (optional)
mcmiknn Nearest Neighbor Vendored indeptests.mCMIkNN from hpi-epic/mCMIkNN (no install required)
kci Kernel causal-learn Python KCI
rcit Kernel R RCIT::RCIT via rpy2 (optional)
rcot Kernel R RCIT::RCoT via rpy2 (optional)
gcm Machine-Learning-Based pycomets GCM with random forest regression (optional)
wgcm Machine-Learning-Based pycomets WGCM with random forest regression (optional)
pcm Machine-Learning-Based pycomets PCM with random forest regression (optional)
disc_chisq Adapter Strategies Native citests equal-frequency discretization + causal-learn Chi-Square
disc_gsq Adapter Strategies Native citests equal-frequency discretization + causal-learn G-Square
dummy_fisherz Adapter Strategies Native citests one-hot encoding + causal-learn Fisher-Z aggregation
hartemink_chisq Adapter Strategies R bnlearn Hartemink discretization + causal-learn Chi-Square (optional)

Module Layout (Survey Taxonomy)

  • citests/tests/partial_correlation_tests.py
  • citests/tests/contingency_table_tests.py
  • citests/tests/regression_tests.py
  • citests/tests/nearest_neighbor_tests.py
  • citests/tests/kernel_tests.py
  • citests/tests/ml_based_tests.py
  • citests/tests/adapter_tests.py

For detailed documentation on each test and its parameters, please see our full documentation page HERE.

Acknowledgements

citests is a toolkit-style assembly. Several tests are adapters over upstream implementations:

  • KCI wraps causallearn.utils.cit.KCI from causal-learn (MIT) under the optional [causallearn] extra.
  • disc_chisq / disc_gsq / dummy_fisherz route discretised / one-hot data through causal-learn's Chi-Square, G-Square, and Fisher-Z back-ends respectively.
  • mCMIkNN is vendored verbatim from hpi-epic/mCMIkNN (MIT). See citests/_vendor/NOTICE.md for the full attribution including authors, paper citation, and vendored revision SHA.
  • hartemink_chisq uses bnlearn (R) for Hartemink discretisation via rpy2, paired with causal-learn's Chi-Square test.
  • RCIT / RCoT wrap the R RCIT package via rpy2 under the optional [r] extra.
  • CiMM wraps the ci.mm test from the R MXM package (GPL-2+) via rpy2 under the optional [r] extra; MXM is invoked rather than vendored, so the GPL boundary remains in the user's R installation.
  • CMIknn / RegressionCI wrap tigramite (GPL-3) under the optional [tigramite] extra; tigramite is invoked at the user's installation rather than vendored, so the GPL-3 boundary remains in the user's environment.

Native citests tests (FisherZ, Spearman, χ²/G², regression-based) are independent implementations. Cross-package interop with cbcd is via the structural cbcd.CITest Protocol — neither package imports the other.

License

MIT License.

Project details


Download files

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

Source Distribution

citests-0.1.0.tar.gz (73.8 kB view details)

Uploaded Source

Built Distribution

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

citests-0.1.0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file citests-0.1.0.tar.gz.

File metadata

  • Download URL: citests-0.1.0.tar.gz
  • Upload date:
  • Size: 73.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for citests-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0faa18b94a53d0fff23d42f1afef5881ff2258b31ec90f6e497af222a1ac4f4
MD5 68203d6152406cb5d3ba5f91fa44492a
BLAKE2b-256 d5b6046fbcded7f2c7811ebcf13a9fc8199c80de986f895d58d15b0256e1f8f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for citests-0.1.0.tar.gz:

Publisher: release.yml on averinpa/constraint-based-causal-discovery-suite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file citests-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: citests-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for citests-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8081429e88c5505c604fd74761415559a96cd70674c2e959d9e677d177b766cd
MD5 0de8bfa4bb4ab7655910d6fd460d6ab9
BLAKE2b-256 75b49a2ddfa3e73f1796c1f925f3de67958979f6100b8a262d83bd4f8d17ef3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for citests-0.1.0-py3-none-any.whl:

Publisher: release.yml on averinpa/constraint-based-causal-discovery-suite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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