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, binary_outcome=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.3.1.tar.gz (26.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.3.1-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for causal_falsify-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7296b6010583ecaecadc86a40f33ba8f9410283445e01a7f89739d433a0d2f50
MD5 4f6ae37b53cb2ff01028288a178f17d7
BLAKE2b-256 d6af65a6846964be3fab02742743ac3790af4b427464f4ecebee323ea979ab08

See more details on using hashes here.

Provenance

The following attestation bundles were made for causal_falsify-0.3.1.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.3.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for causal_falsify-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db8ad3273eae194376db8c1e9927460e2c09f304dd2be67f0df19525f2c1cb2d
MD5 ed9fd23970933c2963d5ed00e823a60f
BLAKE2b-256 126270d7eeed026f1f4f104e22522073a32828759436b39c79f6c98c563aea64

See more details on using hashes here.

Provenance

The following attestation bundles were made for causal_falsify-0.3.1-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