ICPy


NameICPy JSON
Version 0.0.6 PyPI version JSON
download
home_pageNone
SummaryInvariant Causal Prediction for python
upload_time2024-03-22 15:21:20
maintainerNone
docs_urlNone
authorNone
requires_python!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7
licenseNone
keywords statistics casual-inference
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## ICPy
[![CI](https://github.com/jan-glx/ICPy/actions/workflows/ci.yml/badge.svg)](https://github.com/jan-glx/ICPy/actions/workflows/ci.yml) [![Coverage badge](https://raw.githubusercontent.com/jan-glx/ICPy/python-coverage-comment-action-data/badge.svg)](https://htmlpreview.github.io/?https://github.com/jan-glx/ICPy/blob/python-coverage-comment-action-data/htmlcov/index.html)
[![PyPI version](https://img.shields.io/pypi/v/ICPy.svg)](https://pypi.org/project/ICPy/)

This packages provides a simple python implementation of Invariant Causal Prediction (ICP) [1].<br>
The source code for the actual algorithm resides in [./src/icp/ICP.py](./src/icpy/ICP.py). <br>
See also the original implementation in the R package [InvariantCausalPrediction](https://cran.r-project.org/web/packages/InvariantCausalPrediction/index.html).
### Installation
``` bash
pip install ICPy
```
### Usage
``` python
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

``` python
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](https://github.com/lgmoneda), [#1](https://github.com/jan-glx/ICPy/pull/1))
* fix issues when environments are not subsequent whole numbers starting at 0 (thanks to [@lgmoneda](https://github.com/lgmoneda), [#1](https://github.com/jan-glx/ICPy/pull/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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ICPy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
    "maintainer_email": "Jan Gleixner <jan.gleixner+icpy@gmail.com>",
    "keywords": "statistics, casual-inference",
    "author": null,
    "author_email": "Jan Gleixner <jan.gleixner+icpy@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c2/25/bf3d0b8f852f71d2808c180dbb126c16e2abd00bd5bf8a9cb0fc505e046a/ICPy-0.0.6.tar.gz",
    "platform": null,
    "description": "## ICPy\n[![CI](https://github.com/jan-glx/ICPy/actions/workflows/ci.yml/badge.svg)](https://github.com/jan-glx/ICPy/actions/workflows/ci.yml) [![Coverage badge](https://raw.githubusercontent.com/jan-glx/ICPy/python-coverage-comment-action-data/badge.svg)](https://htmlpreview.github.io/?https://github.com/jan-glx/ICPy/blob/python-coverage-comment-action-data/htmlcov/index.html)\n[![PyPI version](https://img.shields.io/pypi/v/ICPy.svg)](https://pypi.org/project/ICPy/)\n\nThis packages provides a simple python implementation of Invariant Causal Prediction (ICP) [1].<br>\nThe source code for the actual algorithm resides in [./src/icp/ICP.py](./src/icpy/ICP.py). <br>\nSee also the original implementation in the R package [InvariantCausalPrediction](https://cran.r-project.org/web/packages/InvariantCausalPrediction/index.html).\n### Installation\n``` bash\npip install ICPy\n```\n### Usage\n``` python\nimport icpy as icpy\nimport numpy as np\n\nnp.random.seed(seed=1)\nn = 100\nnoise = 0.1\nE = np.repeat([0, 1, 2], np.ceil(n / 3.0))[0:n]                       # \"Environment\"\nA = np.random.normal(scale=noise, size=[n]) + np.equal(E, 1)          # Node A\nB = A + np.random.normal(scale=noise, size=[n]) / 3 + np.equal(E, 2)  # Node B\nC = B + np.random.normal(scale=noise, size=[n])                       # Node C\n\n#  /--->---\\\n# E -> A -> B -> C\n\nicpy.invariant_causal_prediction(X=np.column_stack((A, B)), y=C, z=E) # test if A or B are parents of C\n```\nOutput\n\n``` python\nICP(S_hat=array([1], dtype=int64),                         # Column 1 = Node B was (correctly) identified as parent of C\n    p_values=array([  1.51508232e-01,   4.59577055e-37]),  # error levels at which A and B would/are indentied as parent of C\n    p_value=0.16416488336322549)                           # p-value for testing against violation of the model assumptions (e.g. a direct effect of E on C)\n```\n\n### News\nv0.0.003 (2020-05-15)\n* fix failing import (thanks to [@lgmoneda](https://github.com/lgmoneda), [#1](https://github.com/jan-glx/ICPy/pull/1))\n* fix issues when environments are not subsequent whole numbers starting at 0 (thanks to [@lgmoneda](https://github.com/lgmoneda), [#1](https://github.com/jan-glx/ICPy/pull/1))\n\n### References\n[1] J. Peters, P. B\u00fchlmann, 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.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Invariant Causal Prediction for python",
    "version": "0.0.6",
    "project_urls": {
        "source": "https://github.com/jan-glx/ICPy"
    },
    "split_keywords": [
        "statistics",
        " casual-inference"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f95de7ca0300393659771690a65437e8ad2321cc6c2da42fa5c87130d164529d",
                "md5": "79fe46ab0db066bda89782ba9d6ebed2",
                "sha256": "e92a09337721b06543af3c3d95ce119c3276aa004c156e19c1cf037bc7c5f83c"
            },
            "downloads": -1,
            "filename": "ICPy-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "79fe46ab0db066bda89782ba9d6ebed2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
            "size": 4621,
            "upload_time": "2024-03-22T15:21:18",
            "upload_time_iso_8601": "2024-03-22T15:21:18.441077Z",
            "url": "https://files.pythonhosted.org/packages/f9/5d/e7ca0300393659771690a65437e8ad2321cc6c2da42fa5c87130d164529d/ICPy-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c225bf3d0b8f852f71d2808c180dbb126c16e2abd00bd5bf8a9cb0fc505e046a",
                "md5": "09cff7133f00d06cfb39eb27bba88b12",
                "sha256": "2f65df7f9d9be6f6bd52a77ffc8f0858aaa2c6dd4fc7958a278fb3f15cc2b538"
            },
            "downloads": -1,
            "filename": "ICPy-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "09cff7133f00d06cfb39eb27bba88b12",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
            "size": 5644,
            "upload_time": "2024-03-22T15:21:20",
            "upload_time_iso_8601": "2024-03-22T15:21:20.916718Z",
            "url": "https://files.pythonhosted.org/packages/c2/25/bf3d0b8f852f71d2808c180dbb126c16e2abd00bd5bf8a9cb0fc505e046a/ICPy-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-22 15:21:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jan-glx",
    "github_project": "ICPy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "icpy"
}
        
Elapsed time: 0.20793s