Getting started¶
Typical analysis workflow¶
At a high level, the Survival modeling workflow proceeds in several steps:
- Obtain or simulate data: 
survivalstan.sim - Select model to fit: 
survivalstan.models - Transform data, if required by your model:
survivalstan.prep_data_long_surv - Fit model to data: 
survivalstan.fit_stan_survival_model - Check model fit
survivalstan.utils.print_stan_summarysurvivalstan.utils.plot_pp_survival
 - Review inferences from model
survivalstan.utils.plot_coefs, etc
 - Update model: rince and repeat!
 
Some high-level comments:
- Most if not all survivalstan functions accept a list of models.
- It’s rare to analyze your data with one and only one model.
 - Often you run the same model with more interations, or you try alternate specifications of the same model.
 - Use the optional parameter 
model_cohortto “label” each model fit object. 
 - Not all functions will work with all models
- Example, 
survivalstan.utils.plot_grp_coefswill only work for models with grouped-coefficients (ie a varying-coefficient model). - Similarly, 
survivalstan.utils.plot_baseline_hazardwill only work for “PEM” models, which have semi- or non-parametrics baseline hazards. 
 - Example, 
 
Obtain or simulate data¶
- The 
survivalstan.simmodule includes several data-simulation routines. - typically one record per subject
 - “survival status” typically consists of several columns. At a minimum: time and status (1:event, 0:censor)
 
Select the survival model you want to fit¶
- Survivalstan includes Stan code for a variety of models, including:
- Parametric `baseline hazards <>`__ (weibull, gamma, exponential)
 - Semi- and non-parametric baseline hazards (pem_randomwalk, pem_gamma, pem_unstructured)
 - Estimating time-dependent effects
 - Varying-coefficient models
 - Stratified models
 - Competing events models
 
 - Or, you may have your own Stan code - a variation of one of the
above, or your own
- Many of the models provided by Survivalstan include helper functions for regularizing priors, etc.
 
 
Transform data into a format suitable for your model¶
- Many of the models provided by Survivalstan (any that start with “pem”) require that data be provided in a “long” format. See `Survival modeling with long vs wide format <>`__
 - You can use 
prep_data_long_survfunction to transform your data into the long format prior to analysis. 
Fit your model to your data: fit_stan_survival_model¶
- (within 
fit_stan_survival_model):- calls StanSurvivalData() to return a data dictionary for your stan model
 - compiles & optionally caches the compiled model
 - calls 
pystan.stan,stancache.cached_model_fitto fit the model - (tries to) call 
stanity.psislooto summarize fit - (tries to) call 
survivalstan.utils.extract_baseline_hazard,extract_grp_coefs, andextract_coefs - returns a data dictionary containing meta-data about your inputs & outputs
 
 
Check model fit & posterior predictive checking¶
- Try 
survivalstan.utils.plot_baseline_hazard - Try 
survivalstan.utils.plot_pp_survival