Skip to main content

A python wrapper around cmprsk R package

Project description

cmprsk - Competing Risks Regression

Regression modeling of sub-distribution functions in competing risks.

A python wrapper around the cmprsk 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

Requierments

This package is using rpy2 in order to use import the cmprsk R packge and therefore the requierments for rpy2 must be met.

TL;DR

Quickstart

Example: crr

import pandas as pd

import cmprsk.cmprsk as cmprsk

from cmprsk import utils

data = pd.read_csv('my_data_fle')
# 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(ftime, 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

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


from cmprsk import cmprsk

data  = pd.read_csv('cmprsk/cmprsk/tests/test_set.csv')
print(data)


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()

How to update package:

  1. update version in setup.py
  2. rm -fr dist directory
  3. python setup.py sdist bdist_wheel
  4. twine upload dist/* --verbose

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for cmprsk, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size cmprsk-0.1.0-py3-none-any.whl (21.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size cmprsk-0.1.0.tar.gz (7.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page