cmprsk


Namecmprsk JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/OmriTreidel/cmprsk
SummaryA python wrapper around cmprsk R package
upload_time2023-08-02 10:37:51
maintainer
docs_urlNone
authorOmri Treidel
requires_python
license
keywords competing risks survival analysis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cmprsk - Competing Risks Regression
Regression modeling of sub-distribution functions in competing risks.

A python wrapper around the [cmprsk](https://cran.r-project.org/web/packages/cmprsk/index.html) R package.

*Description*: Estimation, testing and regression modeling of
subdistribution functions in competing risks, as described in Gray
(1988), A class of K-sample tests for comparing the cumulative
incidence of a competing risk, **Ann. Stat. 16:1141-1154, and Fine JP and
Gray RJ (1999), A proportional hazards model for the subdistribution
of a competing risk, JASA, 94:496-509**.

[Original Package documentation](https://cran.r-project.org/web/packages/cmprsk/cmprsk.pdf)

## Requirements

### python
* Only python 3 is now supported. Recommended python version >= 3.8 

###
* The original version of this package was written with `rpy2` version 2.9.4. Since then, `rpy2` had many breaking changes. 
Therefore `cmprsk` version **0.X.Y** only works with `rpy2` version 2.9.X.
* The `cmprsk` package v **1.X.Y** is now up-to-date and is using `rpy2` 3.4.5. 

### Installation steps

* install `R`
* install `cmprsk` R package: open R terminal and run `install.packages("cmprsk")`
* create a virtual environment (recommended)
* install`rpy2` - if using `conda` for creating the virtual environment on MacOS M1 (apple silicon) install `rpy2` using pip (tested on version 3.5.9) 
* install `pandas` (tested on version 1.5.3)
* install `scipy` (tested on version 1.10.1)
* install `pytest` and `pytest-cov` for running unit tests (dev) only

This package is using `rpy2` in order to use import the cmprsk R packge and therefore the [requirements for rpy2](https://rpy2.readthedocs.io/en/version_2.8.x/overview.html?highlight=readline#requirements) must be met.

TL;DR
* Unix like OS: Linux, MacOS, BSD. (May work on Windows, look at [rpy2 binaries])(https://rpy2.readthedocs.io/en/version_2.8.x/overview.html#microsoft-s-windows-precompiled-binaries). 
* python >= 3.5
* R >= 3.3 [how to install R](https://www.datacamp.com/community/tutorials/installing-R-windows-mac-ubuntu)
* readline 7.0 - Should be installed as part of `rpy2`. [how to install on MacOS](http://blogs.perl.org/users/aristotle/2013/07/easy-osx-termreadlinegnu.html) see also the following [issue](https://github.com/conda-forge/rpy2-feedstock/issues/1)
* The`cmprsk` R library (open the R consule and run `install.packages('cmprsk')`)

## Quickstart

For example usage consult the tutorial notebook in this repo: `package_usage.ipynb`

### Example: crr

```python

import pandas as pd

import cmprsk.cmprsk as cmprsk

from cmprsk import utils

data = pd.read_csv('my_data_file.csv')
# assuming that x1,x2,x3, x4 are covatiates. 
# x1 are x4 are categorical with baseline 'd' for x1 and 5 for x2 
static_covariates = utils.as_indicators(data[['x1', 'x2', 'x3', 'x4']], ['x1', 'x4'], bases=['d', 5])

crr_result = cmprsk.crr(data['ftime'], data['fstatus'], static_covariates)
report = crr_result.summary

print(report)

```
`ftime` and `fstatus` can be numpy array or pandas series, and `static_covariates` is a pandas DataFrame.
The `report` is a pandas `DataFrame` as well. 

### Example: cuminc

```python
import matplotlib.plt
import numpy as np
import pandas as pd


from cmprsk import cmprsk

data  = pd.read_csv('cmprsk/cmprsk/tests/example_dataset.csv')
cuminc_res = cmprsk.cuminc(data.ss, data.cc, group=data.gg, strata=data.strt)

# print
cuminc_res.print

# plot using matplotlib

_, ax = plt.subplots()
for name, group in cuminc_res.groups.items():
    ax.plot(group.time, group.est, label=name)
    ax.fill_between(group.time, group.low_ci, group.high_ci, alpha=0.4)
    
ax.set_ylim([0, 1])
ax.legend()
ax.set_title('foo bar')
plt.show()

```
## Development
For running the unit tests run 

    pytest --cov=cmprsk cmprsk/tests/

from the project root. Note: you'll need to install [pytest-cov](https://pypi.org/project/pytest-cov/).

Current coverage
```buildoutcfg
---------- coverage: platform darwin, python 3.9.7-final-0 -----------
Name                             Stmts   Miss  Cover
----------------------------------------------------
cmprsk/__init__.py                   0      0   100%
cmprsk/cmprsk.py                   128     22    83%
cmprsk/rpy_utils.py                 44     10    77%
cmprsk/tests/__init__.py             0      0   100%
cmprsk/tests/test_cmprsk.py         30      0   100%
cmprsk/tests/test_rpy_utils.py      27      1    96%
cmprsk/tests/test_utils.py          37      0   100%
cmprsk/utils.py                     23      1    96%
----------------------------------------------------
TOTAL                              289     34    88%
```

### How to update package:
0. update version in setup.py
1. rm -fr dist directory
2. python setup.py sdist bdist_wheel 
3. twine upload  dist/* --verbose

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/OmriTreidel/cmprsk",
    "name": "cmprsk",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "competing risks,survival analysis",
    "author": "Omri Treidel",
    "author_email": "treidel2@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6d/a6/e643c8758cfc4c36b6f236bdf6bbf159a1b761416d24d712bf153210e1fc/cmprsk-1.1.1.tar.gz",
    "platform": null,
    "description": "# cmprsk - Competing Risks Regression\nRegression modeling of sub-distribution functions in competing risks.\n\nA python wrapper around the [cmprsk](https://cran.r-project.org/web/packages/cmprsk/index.html) R package.\n\n*Description*: Estimation, testing and regression modeling of\nsubdistribution functions in competing risks, as described in Gray\n(1988), A class of K-sample tests for comparing the cumulative\nincidence of a competing risk, **Ann. Stat. 16:1141-1154, and Fine JP and\nGray RJ (1999), A proportional hazards model for the subdistribution\nof a competing risk, JASA, 94:496-509**.\n\n[Original Package documentation](https://cran.r-project.org/web/packages/cmprsk/cmprsk.pdf)\n\n## Requirements\n\n### python\n* Only python 3 is now supported. Recommended python version >= 3.8 \n\n###\n* The original version of this package was written with `rpy2` version 2.9.4. Since then, `rpy2` had many breaking changes. \nTherefore `cmprsk` version **0.X.Y** only works with `rpy2` version 2.9.X.\n* The `cmprsk` package v **1.X.Y** is now up-to-date and is using `rpy2` 3.4.5. \n\n### Installation steps\n\n* install `R`\n* install `cmprsk` R package: open R terminal and run `install.packages(\"cmprsk\")`\n* create a virtual environment (recommended)\n* install`rpy2` - if using `conda` for creating the virtual environment on MacOS M1 (apple silicon) install `rpy2` using pip (tested on version 3.5.9) \n* install `pandas` (tested on version 1.5.3)\n* install `scipy` (tested on version 1.10.1)\n* install `pytest` and `pytest-cov` for running unit tests (dev) only\n\nThis package is using `rpy2` in order to use import the cmprsk R packge and therefore the [requirements for rpy2](https://rpy2.readthedocs.io/en/version_2.8.x/overview.html?highlight=readline#requirements) must be met.\n\nTL;DR\n* Unix like OS: Linux, MacOS, BSD. (May work on Windows, look at [rpy2 binaries])(https://rpy2.readthedocs.io/en/version_2.8.x/overview.html#microsoft-s-windows-precompiled-binaries). \n* python >= 3.5\n* R >= 3.3 [how to install R](https://www.datacamp.com/community/tutorials/installing-R-windows-mac-ubuntu)\n* readline 7.0 - Should be installed as part of `rpy2`. [how to install on MacOS](http://blogs.perl.org/users/aristotle/2013/07/easy-osx-termreadlinegnu.html) see also the following [issue](https://github.com/conda-forge/rpy2-feedstock/issues/1)\n* The`cmprsk` R library (open the R consule and run `install.packages('cmprsk')`)\n\n## Quickstart\n\nFor example usage consult the tutorial notebook in this repo: `package_usage.ipynb`\n\n### Example: crr\n\n```python\n\nimport pandas as pd\n\nimport cmprsk.cmprsk as cmprsk\n\nfrom cmprsk import utils\n\ndata = pd.read_csv('my_data_file.csv')\n# assuming that x1,x2,x3, x4 are covatiates. \n# x1 are x4 are categorical with baseline 'd' for x1 and 5 for x2 \nstatic_covariates = utils.as_indicators(data[['x1', 'x2', 'x3', 'x4']], ['x1', 'x4'], bases=['d', 5])\n\ncrr_result = cmprsk.crr(data['ftime'], data['fstatus'], static_covariates)\nreport = crr_result.summary\n\nprint(report)\n\n```\n`ftime` and `fstatus` can be numpy array or pandas series, and `static_covariates` is a pandas DataFrame.\nThe `report` is a pandas `DataFrame` as well. \n\n### Example: cuminc\n\n```python\nimport matplotlib.plt\nimport numpy as np\nimport pandas as pd\n\n\nfrom cmprsk import cmprsk\n\ndata  = pd.read_csv('cmprsk/cmprsk/tests/example_dataset.csv')\ncuminc_res = cmprsk.cuminc(data.ss, data.cc, group=data.gg, strata=data.strt)\n\n# print\ncuminc_res.print\n\n# plot using matplotlib\n\n_, ax = plt.subplots()\nfor name, group in cuminc_res.groups.items():\n    ax.plot(group.time, group.est, label=name)\n    ax.fill_between(group.time, group.low_ci, group.high_ci, alpha=0.4)\n    \nax.set_ylim([0, 1])\nax.legend()\nax.set_title('foo bar')\nplt.show()\n\n```\n## Development\nFor running the unit tests run \n\n    pytest --cov=cmprsk cmprsk/tests/\n\nfrom the project root. Note: you'll need to install [pytest-cov](https://pypi.org/project/pytest-cov/).\n\nCurrent coverage\n```buildoutcfg\n---------- coverage: platform darwin, python 3.9.7-final-0 -----------\nName                             Stmts   Miss  Cover\n----------------------------------------------------\ncmprsk/__init__.py                   0      0   100%\ncmprsk/cmprsk.py                   128     22    83%\ncmprsk/rpy_utils.py                 44     10    77%\ncmprsk/tests/__init__.py             0      0   100%\ncmprsk/tests/test_cmprsk.py         30      0   100%\ncmprsk/tests/test_rpy_utils.py      27      1    96%\ncmprsk/tests/test_utils.py          37      0   100%\ncmprsk/utils.py                     23      1    96%\n----------------------------------------------------\nTOTAL                              289     34    88%\n```\n\n### How to update package:\n0. update version in setup.py\n1. rm -fr dist directory\n2. python setup.py sdist bdist_wheel \n3. twine upload  dist/* --verbose\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A python wrapper around cmprsk R package",
    "version": "1.1.1",
    "project_urls": {
        "Homepage": "https://github.com/OmriTreidel/cmprsk"
    },
    "split_keywords": [
        "competing risks",
        "survival analysis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2c39d4acf131d64bdf3264b47637be38f1481916b51e391b40d361cb4d6f965b",
                "md5": "759ebc32ac29cd0569f74e618243328e",
                "sha256": "69eaa140b726b4801f5f93a71c7ad6141dd08bacbf66826f3d2d944a6e8b263a"
            },
            "downloads": -1,
            "filename": "cmprsk-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "759ebc32ac29cd0569f74e618243328e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 21908,
            "upload_time": "2023-08-02T10:37:50",
            "upload_time_iso_8601": "2023-08-02T10:37:50.339924Z",
            "url": "https://files.pythonhosted.org/packages/2c/39/d4acf131d64bdf3264b47637be38f1481916b51e391b40d361cb4d6f965b/cmprsk-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6da6e643c8758cfc4c36b6f236bdf6bbf159a1b761416d24d712bf153210e1fc",
                "md5": "c96d84cfb785d0501f96c222c8105584",
                "sha256": "68a7123f80ccec0b040eb4db4944f06da13af34be3cee750caabb051d348586a"
            },
            "downloads": -1,
            "filename": "cmprsk-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "c96d84cfb785d0501f96c222c8105584",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 22411,
            "upload_time": "2023-08-02T10:37:51",
            "upload_time_iso_8601": "2023-08-02T10:37:51.754520Z",
            "url": "https://files.pythonhosted.org/packages/6d/a6/e643c8758cfc4c36b6f236bdf6bbf159a1b761416d24d712bf153210e1fc/cmprsk-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-02 10:37:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "OmriTreidel",
    "github_project": "cmprsk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cmprsk"
}
        
Elapsed time: 0.21919s