{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting started" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Installation\n", "\n", "You can install `survivalstan` with `pip`:\n", "\n", " pip install survivalstan" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Typical analysis workflow\n", "\n", "At a high level, the Survival modeling workflow proceeds in several steps:\n", "\n", "1. Obtain or simulate data: `survivalstan.sim`\n", "2. Select model to fit: `survivalstan.models`\n", "3. Transform data, if required by your model: `survivalstan.prep_data_long_surv`\n", "4. Fit model to data: `survivalstan.fit_stan_survival_model`\n", "5. Check model fit\n", " - `survivalstan.utils.print_stan_summary`\n", " - `survivalstan.utils.plot_pp_survival`\n", "6. Review inferences from model\n", " - `survivalstan.utils.plot_coefs`, etc\n", "7. Update model: rince and repeat!\n", "\n", "Some high-level comments:\n", "\n", "* **Most if not all survivalstan functions accept a list of models.**\n", " - It's rare to analyze your data with one and only one model. \n", " - Often you run the same model with more interations, or you try alternate specifications of the same model.\n", " - Use the optional parameter `model_cohort` to \"label\" each model fit object.\n", "* Not all functions will work with all models\n", " - Example, `survivalstan.utils.plot_grp_coefs` will only work for models with grouped-coefficients (ie a varying-coefficient model).\n", " - Similarly, `survivalstan.utils.plot_baseline_hazard` will only work for \"PEM\" models, which have semi- or non-parametrics baseline hazards.\n", "\n", "\n", "### Obtain or simulate data\n", "\n", "- The `survivalstan.sim` module includes several data-simulation routines.\n", "- typically one record per subject\n", "- \"survival status\" typically consists of several columns. At a minimum: time and status (1:event, 0:censor)\n", "\n", "### Select the survival model you want to fit\n", "\n", "- Survivalstan includes Stan code for a variety of models, including: \n", " - Parametric [baseline hazards]() (weibull, gamma, exponential)\n", " - Semi- and non-parametric baseline hazards (pem_randomwalk, pem_gamma, pem_unstructured)\n", " - Estimating time-dependent effects\n", " - Varying-coefficient models\n", " - Stratified models\n", " - Competing events models\n", " - .. etc\n", "- Or, you may have your own Stan code - a variation of one of the above, or your own\n", " - Many of the models provided by Survivalstan include helper functions for regularizing priors, etc. \n", "\n", "### Transform data into a format suitable for your model\n", "\n", "- 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]()\n", "- You can use `prep_data_long_surv` function to transform your data into the long format prior to analysis.\n", "\n", "### Fit your model to your data: `fit_stan_survival_model`\n", "- (within `fit_stan_survival_model`):\n", " - calls StanSurvivalData() to return a data dictionary for your stan model\n", " - compiles & optionally caches the compiled model\n", " - calls `pystan.stan`, `stancache.cached_model_fit` to fit the model\n", " - (tries to) call `stanity.psisloo` to summarize fit \n", " - (tries to) call `survivalstan.utils.extract_baseline_hazard`, `extract_grp_coefs`, and `extract_coefs`\n", " - returns a data dictionary containing meta-data about your inputs & outputs\n", "\n", "### Check model fit & posterior predictive checking\n", "- Try `survivalstan.utils.plot_baseline_hazard`\n", "- Try `survivalstan.utils.plot_pp_survival`\n", "\n", "### Update the model (go back to # 2)\n", "\n" ] } ], "metadata": { "anaconda-cloud": {}, "celltoolbar": "Edit Metadata", "kernelspec": { "display_name": "Python [conda env:newbladder2]", "language": "python", "name": "conda-env-newbladder2-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 1 }