A toolkit for robust conditional independence testing in causal discovery.
Project description
citests: A Conditional Independence Test Toolkit
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-learncompatible: All tests are designed as drop-in replacements for the standard tests in thecausal-learnecosystem, 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 forgcm,wgcm,pcm(installsxgboostonly;pycometsitself is GitHub-only and must be installed separately:pip install git+https://github.com/shimenghuang/pycomets.git)tigramite— required forcmiknn,cmiknn_mixed,regcir— required forrcit,rcot,ci_mm,hartemink_chisq(installsrpy2); the corresponding R packages must also be installed:RCITfrom GitHubericstrobl/RCIT(forrcit,rcot)MXMfrom CRAN (forci_mm)bnlearnfrom CRAN (forhartemink_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.pycitests/tests/contingency_table_tests.pycitests/tests/regression_tests.pycitests/tests/nearest_neighbor_tests.pycitests/tests/kernel_tests.pycitests/tests/ml_based_tests.pycitests/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.KCIfrom 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.mdfor the full attribution including authors, paper citation, and vendored revision SHA. - hartemink_chisq uses
bnlearn(R) for Hartemink discretisation viarpy2, paired with causal-learn's Chi-Square test. - RCIT / RCoT wrap the R RCIT
package via
rpy2under the optional[r]extra. - CiMM wraps the
ci.mmtest from the R MXM package (GPL-2+) viarpy2under 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0faa18b94a53d0fff23d42f1afef5881ff2258b31ec90f6e497af222a1ac4f4
|
|
| MD5 |
68203d6152406cb5d3ba5f91fa44492a
|
|
| BLAKE2b-256 |
d5b6046fbcded7f2c7811ebcf13a9fc8199c80de986f895d58d15b0256e1f8f1
|
Provenance
The following attestation bundles were made for citests-0.1.0.tar.gz:
Publisher:
release.yml on averinpa/constraint-based-causal-discovery-suite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
citests-0.1.0.tar.gz -
Subject digest:
e0faa18b94a53d0fff23d42f1afef5881ff2258b31ec90f6e497af222a1ac4f4 - Sigstore transparency entry: 1562377778
- Sigstore integration time:
-
Permalink:
averinpa/constraint-based-causal-discovery-suite@55bf661990ea4b80c91f45c6fe400430e5084090 -
Branch / Tag:
refs/tags/citests-v0.1.0 - Owner: https://github.com/averinpa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@55bf661990ea4b80c91f45c6fe400430e5084090 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8081429e88c5505c604fd74761415559a96cd70674c2e959d9e677d177b766cd
|
|
| MD5 |
0de8bfa4bb4ab7655910d6fd460d6ab9
|
|
| BLAKE2b-256 |
75b49a2ddfa3e73f1796c1f925f3de67958979f6100b8a262d83bd4f8d17ef3c
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
citests-0.1.0-py3-none-any.whl -
Subject digest:
8081429e88c5505c604fd74761415559a96cd70674c2e959d9e677d177b766cd - Sigstore transparency entry: 1562377977
- Sigstore integration time:
-
Permalink:
averinpa/constraint-based-causal-discovery-suite@55bf661990ea4b80c91f45c6fe400430e5084090 -
Branch / Tag:
refs/tags/citests-v0.1.0 - Owner: https://github.com/averinpa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@55bf661990ea4b80c91f45c6fe400430e5084090 -
Trigger Event:
push
-
Statement type: