Package: cmprsk
cmprsk - Competing Risks RegressionRegression modeling of sub-distribution functions in competing risks.A python wrapper around thecmprskR 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 documentationRequirementspythonOnly python 3 is now supported. Recommended python version >= 3.8The original version of this package was written withrpy2version 2.9.4. Since then,rpy2had many breaking changes.
Thereforecmprskversion0.X.Yonly works withrpy2version 2.9.X.Thecmprskpackage v1.X.Yis now up-to-date and is usingrpy23.4.5.Installation stepsinstallRinstallcmprskR package: open R terminal and runinstall.packages("cmprsk")create a virtual environment (recommended)installrpy2- if usingcondafor creating the virtual environment on MacOS M1 (apple silicon) installrpy2using pip (tested on version 3.5.9)installpandas(tested on version 1.5.3)installscipy(tested on version 1.10.1)installpytestandpytest-covfor running unit tests (dev) onlyThis package is usingrpy2in order to use import the cmprsk R packge and therefore therequirements for rpy2must be met.TL;DRUnix 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.5R >= 3.3how to install Rreadline 7.0 - Should be installed as part ofrpy2.how to install on MacOSsee also the followingissueThecmprskR library (open the R consule and runinstall.packages('cmprsk'))QuickstartFor example usage consult the tutorial notebook in this repo:package_usage.ipynbExample: crrimportpandasaspdimportcmprsk.cmprskascmprskfromcmprskimportutilsdata=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 x2static_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.summaryprint(report)ftimeandfstatuscan be numpy array or pandas series, andstatic_covariatesis a pandas DataFrame.
Thereportis a pandasDataFrameas well.Example: cumincimportmatplotlib.pltimportnumpyasnpimportpandasaspdfromcmprskimportcmprskdata=pd.read_csv('cmprsk/cmprsk/tests/example_dataset.csv')cuminc_res=cmprsk.cuminc(data.ss,data.cc,group=data.gg,strata=data.strt)# printcuminc_res.print# plot using matplotlib_,ax=plt.subplots()forname,groupincuminc_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()DevelopmentFor running the unit tests runpytest --cov=cmprsk cmprsk/tests/from the project root. Note: you'll need to installpytest-cov.Current coverage---------- 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:update version in setup.pyrm -fr dist directorypython setup.py sdist bdist_wheeltwine upload  dist/* --verbose