{ "cells": [ { "cell_type": "markdown", "id": "560a0699-b258-4d85-a984-785ebfacdbd7", "metadata": {}, "source": [ "# Cox (semiparametric proportional hazard)" ] }, { "cell_type": "markdown", "id": "bf8ce873-7445-4f10-a1f9-aa9a44593851", "metadata": {}, "source": [ "This demonstration requires 2 optional dependencies : [pandas](https://pypi.org/project/pandas/) and [lifelines](https://pypi.org/project/lifelines/). Install them if you wish to reproduce examples outputs. Otherwise, below examples may help you to understand how you can use Cox model with ReLife." ] }, { "cell_type": "markdown", "id": "dc178d4a7653235a", "metadata": {}, "source": [ "### Loading data" ] }, { "cell_type": "markdown", "id": "49c5c2fdc80b3b2a", "metadata": {}, "source": [ "Let's use a [lifelines](https://pypi.org/project/lifelines/) dataset." ] }, { "cell_type": "code", "execution_count": 1, "id": "9345ce34-5550-4eb0-9362-9f08c607ca64", "metadata": {}, "outputs": [], "source": [ "import lifelines\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "id": "c43a4b58a2972191", "metadata": {}, "outputs": [], "source": [ "df = lifelines.datasets.load_canadian_senators()" ] }, { "cell_type": "markdown", "id": "04142090-c0c2-44af-b47b-452a2e3e01a9", "metadata": {}, "source": [ "Clean up the dataset" ] }, { "cell_type": "code", "execution_count": 3, "id": "25d7e066-fec3-4d78-bd6c-d5432558ffcb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Name | \n", "Province / Territory | \n", "reason | \n", "diff_days | \n", "observed | \n", "
|---|---|---|---|---|---|
| 0 | \n", "Abbott, John Joseph Caldwell | \n", "quebec | \n", "Death | \n", "2363 | \n", "True | \n", "
| 1 | \n", "Adams, Michael | \n", "newbrunswick | \n", "Death | \n", "1090 | \n", "True | \n", "
| 2 | \n", "Adams, Willie | \n", "northwestterritories | \n", "Retirement | \n", "11766 | \n", "True | \n", "
| 3 | \n", "Aikins, James Cox | \n", "ontario | \n", "Resignation | \n", "5333 | \n", "True | \n", "
| 4 | \n", "Aikins, James Cox | \n", "ontario | \n", "Death | \n", "3133 | \n", "True | \n", "