Skip to main content

Invariant Causal Prediction for python

Project description

ICPy

CI Coverage badge PyPI version

This packages provides a simple python implementation of Invariant Causal Prediction (ICP) [1].
The source code for the actual algorithm resides in ./src/icp/ICP.py.
See also the original implementation in the R package InvariantCausalPrediction.

Installation

pip install ICPy

Usage

import icpy as icpy
import numpy as np

np.random.seed(seed=1)
n = 100
noise = 0.1
E = np.repeat([0, 1, 2], np.ceil(n / 3.0))[0:n]                       # "Environment"
A = np.random.normal(scale=noise, size=[n]) + np.equal(E, 1)          # Node A
B = A + np.random.normal(scale=noise, size=[n]) / 3 + np.equal(E, 2)  # Node B
C = B + np.random.normal(scale=noise, size=[n])                       # Node C

#  /--->---\
# E -> A -> B -> C

icpy.invariant_causal_prediction(X=np.column_stack((A, B)), y=C, z=E) # test if A or B are parents of C

Output

ICP(S_hat=array([1], dtype=int64),                         # Column 1 = Node B was (correctly) identified as parent of C
    p_values=array([  1.51508232e-01,   4.59577055e-37]),  # error levels at which A and B would/are indentied as parent of C
    p_value=0.16416488336322549)                           # p-value for testing against violation of the model assumptions (e.g. a direct effect of E on C)

News

v0.0.003 (2020-05-15)

  • fix failing import (thanks to @lgmoneda, #1)
  • fix issues when environments are not subsequent whole numbers starting at 0 (thanks to @lgmoneda, #1)

References

[1] J. Peters, P. Bühlmann, N. Meinshausen, Causal inference by using invariant prediction: identification and confidence intervals, J. R. Stat. Soc. Ser. B Stat. Methodol. 78 (2016) 947-1012. doi:10.1111/rssb.12167.

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

ICPy-0.0.6.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

ICPy-0.0.6-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file ICPy-0.0.6.tar.gz.

File metadata

  • Download URL: ICPy-0.0.6.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for ICPy-0.0.6.tar.gz
Algorithm Hash digest
SHA256 2f65df7f9d9be6f6bd52a77ffc8f0858aaa2c6dd4fc7958a278fb3f15cc2b538
MD5 09cff7133f00d06cfb39eb27bba88b12
BLAKE2b-256 c225bf3d0b8f852f71d2808c180dbb126c16e2abd00bd5bf8a9cb0fc505e046a

See more details on using hashes here.

File details

Details for the file ICPy-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: ICPy-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for ICPy-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e92a09337721b06543af3c3d95ce119c3276aa004c156e19c1cf037bc7c5f83c
MD5 79fe46ab0db066bda89782ba9d6ebed2
BLAKE2b-256 f95de7ca0300393659771690a65437e8ad2321cc6c2da42fa5c87130d164529d

See more details on using hashes here.

Supported by

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