{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Survival Analysis" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-04-16T19:37:27.970806Z", "iopub.status.busy": "2021-04-16T19:37:27.970215Z", "iopub.status.idle": "2021-04-16T19:37:27.972416Z", "shell.execute_reply": "2021-04-16T19:37:27.971942Z" }, "tags": [] }, "outputs": [], "source": [ "# If we're running on Colab, install empiricaldist\n", "# https://pypi.org/project/empiricaldist/\n", "\n", "import sys\n", "IN_COLAB = 'google.colab' in sys.modules\n", "\n", "if IN_COLAB:\n", " !pip install empiricaldist" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-04-16T19:37:27.976032Z", "iopub.status.busy": "2021-04-16T19:37:27.975593Z", "iopub.status.idle": "2021-04-16T19:37:27.977681Z", "shell.execute_reply": "2021-04-16T19:37:27.977307Z" }, "tags": [] }, "outputs": [], "source": [ "# Get utils.py\n", "\n", "from os.path import basename, exists\n", "\n", "def download(url):\n", " filename = basename(url)\n", " if not exists(filename):\n", " from urllib.request import urlretrieve\n", " local, _ = urlretrieve(url, filename)\n", " print('Downloaded ' + local)\n", " \n", "download('https://github.com/AllenDowney/ThinkBayes2/raw/master/soln/utils.py')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-04-16T19:37:27.980924Z", "iopub.status.busy": "2021-04-16T19:37:27.980273Z", "iopub.status.idle": "2021-04-16T19:37:28.658584Z", "shell.execute_reply": "2021-04-16T19:37:28.659033Z" }, "tags": [] }, "outputs": [], "source": [ "from utils import set_pyplot_params\n", "set_pyplot_params()" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "The following cell downloads the data." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-04-16T19:37:28.662755Z", "iopub.status.busy": "2021-04-16T19:37:28.662317Z", "iopub.status.idle": "2021-04-16T19:37:28.664128Z", "shell.execute_reply": "2021-04-16T19:37:28.664481Z" }, "tags": [] }, "outputs": [], "source": [ "download('https://github.com/AllenDowney/ThinkBayes2/raw/master/examples/Osogbo2021.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "I'll use Pandas to load the data into a `DataFrame`." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-04-16T19:37:28.669139Z", "iopub.status.busy": "2021-04-16T19:37:28.668327Z", "iopub.status.idle": "2021-04-16T19:37:28.679256Z", "shell.execute_reply": "2021-04-16T19:37:28.678840Z" } }, "outputs": [ { "data": { "text/html": [ "
| \n", " | TIME(In Days) | \n", "AGE OF PATIENTS | \n", "CENSOR | \n", "AGE AT MENARACHE | \n", "BREASTFEED | \n", "CONTRACEPT | \n", "DETECTION | \n", "NEOADJUVANT | \n", "
|---|---|---|---|---|---|---|---|---|
| 0 | \n", "48 | \n", "44 | \n", "1 | \n", "18 | \n", "1.5 | \n", "2 | \n", "1 | \n", "2 | \n", "
| 1 | \n", "898 | \n", "43 | \n", "0 | \n", "17 | \n", "1.0 | \n", "1 | \n", "1 | \n", "2 | \n", "
| 2 | \n", "36 | \n", "40 | \n", "0 | \n", "15 | \n", "2.0 | \n", "2 | \n", "1 | \n", "2 | \n", "
| 3 | \n", "23 | \n", "56 | \n", "1 | \n", "15 | \n", "1.5 | \n", "1 | \n", "1 | \n", "1 | \n", "
| 4 | \n", "300 | \n", "53 | \n", "0 | \n", "12 | \n", "1.0 | \n", "2 | \n", "1 | \n", "2 | \n", "