Skip to content

Commit

Permalink
Merge pull request #29 from hammerlab/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jburos committed Nov 8, 2016
2 parents 34fe50b + 4ad283b commit f059a71
Show file tree
Hide file tree
Showing 7 changed files with 873 additions and 482 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ Overview

Library of Stan Models for Survival Analysis

Features:

* Variety of standard survival models
- Weibull, Exponential, and Gamma parameterization
- PEM models with variety of baseline hazards
- PEM model with varying-coefficients (by group)
- PEM model with time-varying-effects
* Extensible framework - bring your own Stan code, or edit the models above
* Uses [pandas](http://pandas.pydata.org) data frames & [patsy](https://pypi.python.org/pypi/patsy) formulas
* Graphical posterior predictive checking (currently PEM models only)
* Plot posterior estimates of key parameters using [seaborn](https://pypi.python.org/pypi/seaborn)
* Annotate posterior draws of parameter estimates, format as [pandas](http://pandas.pydata.org) dataframes
* Works with extensions to [pystan](https://pystan.readthedocs.io/en/latest/), such as [stancache](http://github.com/jburos/stancache) or [pystan-cache](https://github.com/paulkernfeld/pystan-cache)

Installation / Usage
--------------------

Expand All @@ -20,19 +34,25 @@ Once we push this repo to pypi, you will be able to install using pip, as:
$ pip install survivalstan


For now, please clone the repo:
Or, you can clone the repo:

$ git clone https://github.com/hammerlab/survivalstan.git
$ pip install .

Contributing
------------

TBD
Details to come. For now, please do not hesitate to contribute if you would like.

Example
-------

There are several examples included in the [example-notebooks](), roughly one corresponding to each model.

If you are not sure where to start, [Test pem_survival_model with simulated data.ipynb](https://github.com/hammerlab/survivalstan/blob/master/example-notebooks/Test%20pem_survival_model%20with%20simulated%20data.ipynb) contains the most explanatory text. Many of the other notebooks are sparse on explanation, but do illustrate variations on the different models.

For basic usage:

```
import survivalstan
import stanity
Expand Down Expand Up @@ -61,6 +81,9 @@ testfit_wei = survivalstan.fit_stan_survival_model(
## coefplot for Weibull coefficient estimates
sb.boxplot(x = 'value', y = 'variable', data = testfit_wei['coefs'])
## or, use plot_coefs
survivalstan.utils.plot_coefs([testfit_wei])
## print summary of MCMC draws from posterior for each parameter
print(testfit_wei['fit'])
Expand All @@ -85,13 +108,23 @@ print(testfit_pem['fit'])
## coefplot for PEM model results
sb.boxplot(x = 'value', y = 'variable', data = testfit_pem['coefs'])
## plot baseline hazard (only PEM models)
survivalstan.utils.plot_coefs([testfit_pem], element='baseline')
## posterior-predictive checking (only PEM models)
survivalstan.utils.plot_pp_survival([testfit_pem])
## e.g. compare models using PSIS-LOO
stanity.loo_compare(testfit_wei['loo'], testfit_pem['loo'])
## compare coefplots
sb.boxplot(x = 'value', y = 'variable', hue = 'model_cohort',
data = testfit_pem['coefs'].append(testfit_wei['coefs']))
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
## (or, use survivalstan.utils.plot_coefs)
survivalstan.utils.plot_coefs([testfit_wei, testfit_pem])
```


410 changes: 291 additions & 119 deletions example-notebooks/Test pem_survival_model_gamma with simulated data.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit f059a71

Please sign in to comment.