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.0.tar.gz (24.7 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.0-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: causal_falsify-0.3.0.tar.gz
  • Upload date:
  • Size: 24.7 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.0.tar.gz
Algorithm Hash digest
SHA256 73195bcc390c508149c3422530a134990042eecff7a62eaaa76cce2ed24edd08
MD5 1d352457614e8fa495fb9fa2d42da8c9
BLAKE2b-256 5aaf29598375ec01e1168e21ef2de8aeeedb08657cd18cc3d044c096f9d4cf60

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: causal_falsify-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 28.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 246bf58d851d2fd575535804b387ee99e781a8a3e298777a69196a34377c5864
MD5 edf92c6137d66e9e55df796f68db3965
BLAKE2b-256 fc4c1e5ed4160da5f3e0c57e2e473db6ac2c3833e91d64a99e0482e3fe34860b

See more details on using hashes here.

Provenance

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