Git Product home page Git Product logo

survivalpy's Introduction

SurvivalPy

PyPI version Build Status Codacy Badge Coverage Status

Survival Analysis functionalities for Python. Compatible with Python 2 or 3.

Analysis output is compatible for visualizations with: https://github.com/oncojs/survivalplot

Installation

$ pip install SurvivalPy

Development

A requirements.txt file is provided for use with pip and virtualenv

Example

Sample Data:

time censored Donor ID
1 0 D13
1 1 D54
3 0 D81
4 0 D95
6 1 D32
6 0 D20
9 1 D51

Encoded in python as objects and analyzed:

from survivalpy.survival import Analyzer
from survivalpy.survival import Datum

data = [Datum(1, False, {'id': 'D13'}),
        Datum(1, True, {'id': 'D54'}),
        Datum(3, False, {'id': 'D81'}),
        Datum(4, False, {'id': 'D95'}),
        Datum(6, True, {'id': 'D32'}),
        Datum(6, False, {'id': 'D20'}),
        Datum(9, True, {'id': 'D51'})]


analyzer = Analyzer(data)
results = analyzer.compute()

The results will be a list of intervals. If you serialize to json using the to_json_dict method of the Intervals, it will look like:

>>> results = analyzer.compute()
>>> json_results = list(map(lambda interval: interval.to_json_dict(), results))
>>> print(json.dumps(json_results))
[{"start": 0, "donors": [{"time": 1, "censored": false, "meta": {"id": "D13"}}, {"time": 1, "censored": true, "meta": {"id": "D54"}}], "censored": 1, "died": 1, "cumulativeSurvival": 1, "end": 1}, {"start": 0, "donors": [{"time": 3, "censored": false, "meta": {"id": "D81"}}], "censored": 0, "died": 1, "cumulativeSurvival": 0.8333333333333334, "end": 3}, {"start": 0, "donors": [{"time": 4, "censored": false, "meta": {"id": "D95"}}], "censored": 0, "died": 1, "cumulativeSurvival": 0.8, "end": 4}, {"start": 0, "donors": [{"time": 6, "censored": true, "meta": {"id": "D32"}}, {"time": 6, "censored": false, "meta": {"id": "D20"}}], "censored": 1, "died": 1, "cumulativeSurvival": 0.75, "end": 6}, {"start": 0, "donors": [], "censored": 0, "died": 0, "cumulativeSurvival": 0, "end": 6}]

To perform a log-rank test between two or more curves:

from survivalpy.logrank import LogRankTest
from survivalpy.survival import Analyzer

...

# Two curves expressed as intervals
curves = [analyzer_1.compute(), analyzer_2.compute()]
stats = LogRankTest(survival_results=curves).compute()

The ouput will be a json serializable dictionary of the form:

{"chiSquared": 15.232850289359583, "pValue": 9.503581328784705e-05, "degreesFreedom": 1}

survivalpy's People

Contributors

andricdu avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

philtom-ctds

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.