Skip to main content

Algorithms to falsify unconfoundedness assumption when having access to multi-source observational data.

Project description

causal-falsify

PyPI Documentation Downloads License

causal-falsify: A Python library with algorithms for falsifying unconfoundedness assumption in a composite dataset from multiple sources.

This library implements algorithms proposed in our two papers based on testing independence of causal mechanisms:

  • Detecting Hidden Confounding in Observational Data Using Multiple Environments – NeurIPS 2023 (pdf)
  • Falsification of Unconfoundedness by Testing Independence of Causal Mechanisms – ICML 2025 (pdf)

📦 Installation & Documentation

Install from PyPI:

pip install causal-falsify

Documentation can be found at causal-falsify.readthedocs.io


Algorithms

We have implemented three falsification algorithms, which can be used complementarily:

  • Hierarchical Graphical Independence Constraint (HGIC) Test:
    This test jointly assesses whether unconfoundedness and independence of causal mechanisms hold across sources. A rejection indicates that at least one of these conditions fails. The HGIC test is derived from specific d-separation using constraint-based causal discovery in a hierarchical causal graphical model.

  • Mechanism Independence Test (MINT):
    Similar to the HGIC test, MINT jointly tests for unconfoundedness and independence of causal mechanisms across sources. However, it makes a parametric linearity assumption, which greatly improves sample efficiency but may lead to false positives if the linear model is severely misspecified.

  • Transportability-Based Test:
    This alternative approach jointly tests for transportability and unconfoundedness across sources. A rejection here likewise indicates that at least one of these conditions does not hold.

Example usage

An example with the MINT algorithm.

from causal_falsify.algorithms.mint import MINT
from causal_falsify.utils.simulate_data import simulate_data

# Create a simulated pandas DataFrame containing where unmeasured confounding is present:
# - Observed pre-treatment covariates: ["X_0", "X_1"]
# - Source label: "S"
# - Treatment: "A"
# - Outcome: "Y"
confounded_data = simulate_data(
    n_samples=250, conf_strength=1.0, n_envs=10, n_observed_confounders=2
)

# Run the MINT algorithm
mint_algorithm = MINT(binary_treatment=False)
p_value = mint_algorithm.test(
    confounded_data,
    covariate_vars=["X_0", "X_1"],
    treatment_var="A",
    outcome_var="Y",
    source_var="S",
)

# We are evaluating the joint null hypothesis of no unmeasured confounding 
# and independent causal mechanisms across sources.
# Reject the null if p-value < significance level (e.g., 0.05).
print("p-value:", p_value)
print("reject null:",  p_value < 0.05)

📄 Please cite our work if you use our package

The HGIC and MINT algorithms are based on two of our papers which you can cite as follows:

@article{karlsson2023detecting,
  title={Detecting hidden confounding in observational data using multiple environments},
  author={Karlsson, Rickard and Krijthe, Jesse H},
  journal={Advances in Neural Information Processing Systems},
  volume={36},
  pages={44280--44309},
  year={2023}
}

@inproceedings{karlsson2025falsification,
  title={Falsification of Unconfoundedness by Testing Independence of Causal Mechanisms},
  author={Karlsson, Rickard and Krijthe, Jesse H},
  booktitle={International Conference on Machine Learning},
  organization={PMLR}
  year={2025},
}

🐛 Issues

If you encounter any bugs, unexpected behavior, or have questions about using the package, please don’t hesitate to open an issue.


📬 Contact

Created by Rickard Karlsson – feel free to reach out!

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

causal_falsify-0.2.0.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

causal_falsify-0.2.0-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file causal_falsify-0.2.0.tar.gz.

File metadata

  • Download URL: causal_falsify-0.2.0.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for causal_falsify-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dabb097cb43bd1f2164cae0a7fa227793490ed89ca0ece570383b5ab1f604eb3
MD5 4ece9b6186caa326dc2cb8fada7a26ac
BLAKE2b-256 3b4982d180810962d7a4ec114cfe230ab5402a972659224fe22996e23f673a03

See more details on using hashes here.

Provenance

The following attestation bundles were made for causal_falsify-0.2.0.tar.gz:

Publisher: publish.yml on RickardKarl/causal-falsify

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

File details

Details for the file causal_falsify-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: causal_falsify-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for causal_falsify-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2263b3fd1a37ec36403ddb98d031856eba6eacbcc5cc5a8129a9cc67f3b7e76
MD5 518387514239b7671a54d86ac8d37256
BLAKE2b-256 e29073fb9acac7dabfbaa4a2b676fca8f5e034728b272fba6361eedd10cfbf0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for causal_falsify-0.2.0-py3-none-any.whl:

Publisher: publish.yml on RickardKarl/causal-falsify

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