Name: survivalstan
Owner: Zapier
Description: Library of Stan Models for Survival Analysis
Forked from: hammerlab/survivalstan
Created: 2017-09-29 20:05:28.0
Updated: 2017-09-29 20:05:30.0
Pushed: 2017-07-31 15:00:05.0
Size: 6868
Language: Jupyter Notebook
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
author: Jacki Novik
Library of Stan Models for Survival Analysis
Features:
Documentation is available online.
For help, please reach out to us on gitter.
Install using pip, as:
$ pip install survivalstan
Or, you can clone the repo:
$ git clone https://github.com/hammerlab/survivalstan.git
$ pip install .
Please contribute to survivalstan development by letting us know if you encounter any bugs or have specific feature requests.
In addition, we welcome contributions of:
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 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:
rt survivalstan
rt stanity
rt seaborn as sb
rt matplotlib.pyplot as plt
rt statsmodels
oad flchain test data from R's `survival` package
set = statsmodels.datasets.get_rdataset(package = 'survival', dataname = 'flchain' )
dataset.data.query('futime > 7')
set_index(level = 0, inplace = True)
.g. fit Weibull survival model
fit_wei = survivalstan.fit_stan_survival_model(
model_cohort = 'Weibull model',
model_code = survivalstan.models.weibull_survival_model,
df = d,
time_col = 'futime',
event_col = 'death',
formula = 'age + sex',
iter = 3000,
chains = 4,
make_inits = survivalstan.make_weibull_survival_model_inits
)
oefplot for Weibull coefficient estimates
oxplot(x = 'value', y = 'variable', data = testfit_wei['coefs'])
r, use plot_coefs
ivalstan.utils.plot_coefs([testfit_wei])
rint summary of MCMC draws from posterior for each parameter
t(testfit_wei['fit'])
.g. fit Piecewise-exponential survival model
g = survivalstan.prep_data_long_surv(d, time_col = 'futime', event_col = 'death')
fit_pem = survivalstan.fit_stan_survival_model(
model_cohort = 'PEM model',
model_code = survivalstan.models.pem_survival_model,
df = dlong,
sample_col = 'index',
timepoint_end_col = 'end_time',
event_col = 'end_failure',
formula = 'age + sex',
iter = 3000,
chains = 4,
)
rint summary of MCMC draws from posterior for each parameter
t(testfit_pem['fit'])
oefplot for PEM model results
oxplot(x = 'value', y = 'variable', data = testfit_pem['coefs'])
lot baseline hazard (only PEM models)
ivalstan.utils.plot_coefs([testfit_pem], element='baseline')
osterior-predictive checking (only PEM models)
ivalstan.utils.plot_pp_survival([testfit_pem])
.g. compare models using PSIS-LOO
ity.loo_compare(testfit_wei['loo'], testfit_pem['loo'])
ompare coefplots
oxplot(x = 'value', y = 'variable', hue = 'model_cohort',
data = testfit_pem['coefs'].append(testfit_wei['coefs']))
legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
or, use survivalstan.utils.plot_coefs)
ivalstan.utils.plot_coefs([testfit_wei, testfit_pem])