python 生存分析
Author(s): Pratik Shukla
作者:Pratik Shukla
This article covers an extensive review with step-by-step explanations and code for how to perform statistical survival analysis used to investigate the time some event takes to occur, such as patient survival during the COVID-19 pandemic, the time to failure of engineering products, or even the time to closing a sale after an initial customer contact.
本文涵盖了详尽的综述,并提供分步说明和有关如何执行统计生存分析的代码,这些统计生存分析用于调查某些事件发生的时间,例如COVID-19大流行期间的患者生存,工程失败的时间。产品,甚至在最初与客户联系后完成销售的时间。
This tutorial’s code is available on Github and its full implementation on Google Colab.
本教程的代码在 Github 上可用 ,其完整实现在 Google Colab上 。
📚 Check out our Monte Carlo Simulation Tutorial with Python 📚
📚查看我们的Python蒙特卡洛模拟教程 📚
Survival analysis is a set of statistical approaches used to determine the time it takes for an event of interest to occur. We use survival analysis to study the time until some event of interest occurs. Time is usually measured in years, months, weeks, days, and other time measuring units. The event of interest could be anything of interest. It could be an actual death, a birth, a retirement, along with others.
生存分析是一组统计方法,用于确定感兴趣事件发生所需的时间。 我们使用生存分析来研究发生某些感兴趣事件之前的时间 。 时间通常以年,月,周,天和其他时间度量单位进行度量。 感兴趣的事件可以是任何感兴趣的事件。 这可能是实际的死亡,出生,退休以及其他情况。
For instance, how can Survival Analysis be useful to analyze the ongoing COVID-19 pandemic data?
例如,生存分析如何用于分析正在进行的COVID-19大流行数据?
We can find the number of days until patients showed COVID-19 symptoms. 我们可以找到直到患者出现COVID-19症状的天数。 We can find for which age group it is deadlier. 我们可以找到哪个年龄段的人更致命。 We can find which treatment has the highest survival probability. 我们可以找到哪种治疗方法具有最高的生存率。 We can find whether a person’s sex has a significant effect on their survival time? 我们可以发现一个人的性别对他们的生存时间是否有重大影响? We can find the median number of days of survival for patients. 我们可以找到患者存活天数的中位数。 We can find which factor has more impact on patients’ survival. 我们可以发现哪个因素对患者的生存影响更大。In this tutorial, we are going to perform a thorough analysis of patients with lung cancer. Do not worry if it seems complicated. Once we go through the logic behind it, we will have the ability to perform survival analysis on any data set. Exciting! Isn’t it?
在本教程中,我们将对肺癌患者进行彻底的分析。 如果看起来很复杂,请不要担心。 一旦了解了其背后的逻辑,我们就可以对任何数据集进行生存分析。 令人兴奋! 是不是
Survival analysis is used in a variety of field such as:
生存分析可用于许多领域,例如:
Cancer studies for patients survival time analyses. 用于患者生存时间分析的癌症研究。Sociology for “event-history analysis.”
社会学 用于“事件历史分析”。
In Engineering for “failure-time analysis.” 在工程学中用于“故障时间分析”。 Time until product failure. 直到产品出现故障的时间。 Time until a warranty claim. 直到保修索赔为止的时间。 Time until a process reaches a critical level. 直到过程达到临界水平的时间。 Time from initial sales contact to a sale. 从初始销售联系到销售的时间。 Time from employee hire to either termination or quit. 从雇用员工到解雇或辞职的时间。 Time from a salesperson hires to their first sale. 从销售人员雇用到首次销售的时间。In cancer studies, typical research questions are:
在癌症研究中 ,典型的研究问题是:
What is the impact of specific clinical characteristics on patient’s survival? For example, is there any difference between people who have higher blood sugar and those who do not? 具体临床特征对患者生存有何影响? 例如,血糖高的人与血糖高的人有什么区别吗? What is the probability that an individual survives a specific time (years, months, days)? For example, given a set of cancer patients, we will tell that if 300 days after a cancer diagnosis has been passed, then the probability of that person being alive at that time will be 0.7. 一个人生存特定时间(年,月,日)的概率是多少? 例如,对于一组癌症患者,我们将告诉您,如果在通过癌症诊断后300天,那么该人当时还活着的概率为0.7。 Are there differences in survival between groups of patients? For example, Let’s say there are two groups of people diagnosed with cancer. Those two groups were given two different kinds of treatments. Our goal here will be to find out if there is a significant difference between the survival time for those two different groups based on the treatment they were given. 两组患者的生存率是否存在差异? 例如,假设有两组人被诊断出患有癌症。 两组均接受两种不同的治疗。 我们的目标是根据所给予的治疗来找出这两个不同组的生存时间之间是否存在显着差异。In this tutorial, we will see the following methods of survival analysis in detail:
在本教程中,我们将详细了解以下生存分析方法:
1) Kaplan-Meier plots to visualize survival curves.
1) Kaplan-Meier图使生存曲线可视化。
2) Nelson-Aalen plots to visualize the cumulative hazard.
2)Nelson-Aalen绘图以可视化累积危害。
3) Log-Rank test to compare the survival curves of two or more groups
3)Log-Rank检验比较两组或更多组的生存曲线
4) Cox-proportional hazards regression finds out the effect of different variables like age, sex, and weight on survival.
4)Cox比例风险回归发现年龄,性别和体重等不同变量对生存的影响。
We will start this tutorial by understanding some basic definitions and concepts related to survival analysis.
我们将通过了解与生存分析有关的一些基本定义和概念来开始本教程。
Survival Time: It is usually referred to as an amount of time until when a subject is alive or actively participates in a survey.
生存时间:通常是指直到受试者存活或积极参与调查为止的时间。
There are three main types of events in survival analysis:
生存分析中有三种主要类型的事件:
1) Relapse: Relapse is defined as a deterioration in the subject’s state of health after a temporary improvement.
1)复发:复发定义为受试者暂时改善后健康状况的恶化。
2) Progression: Progression is defined as the process of developing or moving gradually towards a more advanced state. It basically means that the health of the subject under observation is improving.
2)进步:进步被定义为发展或逐渐走向更高级状态的过程。 这基本上意味着所观察对象的健康状况正在改善。
3) Death: Death is defined as the destruction or permanent end of something. In our case, death will be our event of interest.
3)死亡:死亡被定义为某物的破坏或永久终结。 就我们而言,死亡将是我们关注的事件。
As we discussed above, survival analysis focuses on the occurrence of an event of interest. The event of interest can be anything like birth, death, or retirement. However, there is still a possibility that the event we are interested in does not occur. Such observations are known as censored observations.
如上所述,生存分析的重点是关注事件的发生。 感兴趣的事件可以是出生,死亡或退休之类的东西。 但是,仍然有可能发生我们感兴趣的事件。 这样的观察被称为审查观察。
There are three types of censoring:
审查有以下三种类型:
Right Censoring: The subject under observation is still alive. In this case, we can not have our timing when our event of interest(death) occurs.
正确的检查 :被观察的对象还活着。 在这种情况下,当我们感兴趣的事件(死亡)发生时,我们就没有时间。
Left Censoring: In this type of censoring, the event cannot be observed for some reason. It may also include the event that occurred before the experiment started, such as the number of days from birth when the kid started walking.
左审查:在这种审查中,由于某种原因无法观察到事件。 它也可能包括实验开始之前发生的事件,例如孩子出生后开始走路的天数。
3) Interval Censoring: In this type of data censoring, we only have data for a specific interval, so it is possible that the event of interest does not occur during that time.
3)间隔检查:在这种类型的数据检查中,我们仅具有特定间隔的数据,因此有可能在这段时间内没有发生关注的事件。
Censoring may occur in the following instances:
在以下情况下可能会进行审查:
A patient has not (yet) experienced the event of interest (death or relapse in our case) within a period. 病人在一段时间内还没有经历过所关注的事件(在我们的情况下为死亡或复发)。 A patient is not followed anymore. 不再关注患者。 If a patient moves to another city, then follow-up might not be possible for the hospital staff. 如果患者搬到另一个城市,则医院工作人员可能无法进行后续随访。 We only have the data for a specific interval. 我们只有特定时间间隔的数据。We generally use two related probabilities to analyze survival data for a subject.
我们通常使用两个相关的概率来分析受试者的生存数据。
1) Survival Function(S)
1)生存功能
2) Hazard Function (H)
2)危险功能(H)
To find the survival probability of a subject, we will use the survival function S(t), the Kaplan-Meier Estimator. The survival function is defined as the probability that an individual (subject) survives from the time origin (diagnosis of a disease) to a specified future time t. Please note that the time can be in various forms like minutes, days, weeks, months, or years. For example, S(200)=0.7 means that after 200 days, a subject’s survival probability is 0.7. In many deadly diseases, the survival probability decreases as the period increases. If the subject is alive at the end of an experiment, then that data will be censored.
为了找到受试者的生存概率,我们将使用Kaplan-Meier估计器生存函数S(t)。 生存函数定义为个体(受试者)从时间起点(疾病诊断)到指定的未来时间t生存的概率。 请注意,时间可以有多种形式,例如分钟,几天,几周,几个月或几年。 例如,S(200)= 0.7意味着200天后,受试者的生存概率为0.7。 在许多致命疾病中,生存期随时间的延长而降低。 如果受试者在实验结束时还活着,那么该数据将被审查。
The hazard probability, denoted by H(t), is the probability that an individual (subject) who is under observation at a time t has an event (death) at that time. For example, If h(200) = 0.7 means that after 200 days or on the 200th day, the probability of being dead is 0.7. One thing to keep in mind here is that the hazard function gives us the cumulative probability. We will discuss this in detail later in this tutorial.
危险概率,用H(t)表示,是在时间t被观察的个体(受试者)在该时间发生事件(死亡)的概率。 例如,如果h(200)= 0.7表示在200天之后或在第200天,死亡的概率为0.7。 这里要记住的一件事是,危害函数给了我们累积概率。 我们将在本教程的后面部分对此进行详细讨论。
Notice that, in contrast to the survival function, which focuses on the survival of a subject, the hazard function gives us the probability of a subject being dead on a given time. We can note that higher survival probability and lower hazard probability is good for the subject’s health.
请注意,与专注于对象生存的生存函数相反,危险函数为我们提供了对象在给定时间死亡的可能性。 我们可以注意到,较高的生存概率和较低的危害概率对受试者的健康有益。
Download the public dataset from the UPC.
从UPC下载公共数据集。
The Kaplan–Meier estimator is a non-parametric statistic used to estimate the survival function (probability of a person surviving) from the lifetime data. In medical research, it is often used to measure the fraction of patients living for a specific time after treatment or diagnosis. For example: Calculating the amount of time(year, month, day) a particular patient lived after he/she was diagnosed with cancer or his treatment starts. The estimator is named after Edward L. Kaplan and Paul Meier, who submitted similar manuscripts to the American Statistical Association Journal.
Kaplan-Meier估计器是一种非参数统计量,用于根据生命周期数据估计生存函数(一个幸存者的概率)。 在医学研究中,它通常用于测量在治疗或诊断后特定时间内存活的患者比例。 例如:计算特定患者被诊断出患有癌症或开始治疗后的生存时间(年,月,日)。 估算员以爱德华·卡普兰(Edward L. Kaplan)和保罗·迈耶 ( Paul Meier )的名字命名,后者向《 美国统计协会杂志》提交了类似的手稿。
The probability of survival at time ti, which is denoted by S(ti), is calculated as follow:
S(ti)表示的在时间ti处的生存概率计算如下:
Figure 2: Formula to calculate the probability of survival at time ti. 图2:计算时间ti生存概率的公式。We can also write the equation above in a simple form as follows:
我们还可以按以下简单形式编写上述等式:
Figure 3: Probability of survival time in a simple form S(ti). 图3:简单形式S(ti)的生存时间概率。For Example:
例如:
1) Survival probability at time t=1:
1)在时间t = 1时的生存概率:
Figure 4: Survival probability at time t=1 formula 图4:在时间t = 1公式中的生存概率2) Survival probability at time t=2:
2)在时间t = 2时的生存概率:
Figure 5: Survival probability at time t=2 formula 图5:在时间t = 2时的生存概率3) Survival probability at time t=3:
3)在时间t = 3时的生存概率:
Figure 6: Survival probability at time t=3 formula 图6:在时间t = 3时的生存概率公式In a more generalized way, the probability of survival for a particular time is given by.
以更一般的方式,给出了特定时间生存的概率。
Figure 7: Generalized formula for the probability of survival for a particular time. 图7:特定时间存活概率的通用公式。From the above equations, we can confidently say that.
从以上等式,我们可以自信地说。
Figure 8: Expressing survival generalization. 图8:表达生存概括。1) Import required libraries:
1)导入所需的库:
Figure 9: Importing pandas, numpty, matplotlib.pyplot, and lifelines. 图9:导入熊猫,numpty,matplotlib.pyplot和生命线。2) Read the data set:
2)读取数据集:
Figure 10: Reading the dataset. 图10:读取数据集。3) Print the columns in our data set:
3)打印我们数据集中的列:
Figure 11: Printing the data columns. 图11:打印数据列。4) Get additional information about the dataset:
4)获取有关数据集的其他信息:
It gives us information about the data type of the columns along with their null-value counter. We need to remove the rows with a null value for some of the survival analysis methods.
它为我们提供了有关列的数据类型及其空值计数器的信息。 对于某些生存分析方法,我们需要删除具有空值的行。
Figure 12: Additional info about our dataset. 图12:有关我们的数据集的其他信息。5) Get statistical information about the dataset:
5)获取有关数据集的统计信息:
It gives us some statistical information like the total number of rows, mean, standard deviation, minimum value, 25th percentile, 50th percentile, 75th percentile, and maximum value for each column.
它为我们提供了一些统计信息,例如每列的总行数,平均值,标准差,最小值,25%,50%,75%和最大值。
Figure 13: Obtaining statistical info about our dataset. 图13:获取有关我们的数据集的统计信息。6) Find out sex distribution using histogram:
6)使用直方图找出性别分布:
This gives us a general idea about how our data is distributed. In the following graph, we can see that around 139 values have a status of 1, and approximately 90 values have a status of 2, which means that there are 139 males and around 90 females in our dataset.
这使我们对如何分配数据有一个总体了解。 在下图中,我们可以看到大约139个值的状态为1,大约90个值的状态为2,这意味着我们的数据集中有139位男性和90位女性。
Figure 14: Plotting histogram for the sex of the patient. 图14:绘制患者性别的直方图。7) Create an object for Kaplan-Meier-Fitter:
7)为Kaplan-Meier-Fitter创建一个对象:
Figure 15: Creating an object for the Kaplan-Meier-Fitter. 图15:为Kaplan-Meier-Fitter创建对象。8) Organize the data:
8)整理数据:
Now we need to organize our data. We will add a new column in our dataset that is called “dead.” It stores the data about whether a person that is a part of our experiment is dead or alive(based on the status value). If our status value is 1, then that person is alive, and if our status value is 2, then the person is dead. It is a crucial step for what we need to do in the next step as we are going to store our data in columns called censored and observed. Where observed data stores the value of dead persons in a specific timeline, and censored data stores the value of alive persons or persons that we are not going to investigate.
现在我们需要整理数据。 我们将在数据集中添加一个新列,称为“死”。 它存储有关作为实验一部分的人是死亡还是活着的数据(基于状态值)。 如果我们的状态值为1,则该人还活着;如果我们的状态值为2,则该人已死。 对于下一步需要做的事情,这是至关重要的一步,因为我们要将数据存储在被检查和观察的列中。 观察数据在特定时间范围内存储死者的价值,而审查数据存储在世人员或我们不打算调查的人的价值。
Figure 16: Organizing our data. 图16:整理我们的数据。9) Fitting our data into an object:
9)将数据拟合到一个对象中:
Here our goal is to find the number of days a patient survived before they died. Our event of interest will be “death,” which is stored in the “dead” column. The first argument it takes is the timeline for our experiment.
在这里,我们的目标是找到患者在死亡之前存活的天数。 我们感兴趣的事件是“死亡”,该事件存储在“死亡”列中。 它需要采用的第一个参数是我们实验的时间表。
Figure 17: Fitting the parameter values in our object. 图17:在我们的对象中拟合参数值。10) Generate event table:
10)生成事件表:
One of the most crucial methods of the kmf object is the “event_table.” It gives us various information for our survival analysis. Let’s have a look at it column-by-column.
kmf对象最关键的方法之一是“ event_table”。 它为我们的生存分析提供了各种信息。 让我们逐列查看它。
Figure 18: Printing the event table. 图18:打印事件表。a) event_at: It stores the value of the timeline for our dataset. i.e., when was the patient observed in our experiment or when was the experiment conducted. It can be several minutes, days, months, years, and others. In our case, it is going to be for many days. It stores the value of survival days for the subjects.
a)event_at:它存储我们数据集的时间轴值。 即,何时在我们的实验中观察患者或何时进行实验。 可能是几分钟,几天,几个月,几年等。 就我们而言,这将持续很多天。 它存储受试者的存活天数。
b) at_risk: It stores the number of current patients under observation. In the beginning, it will be the total number of patients we are going to observe in our experiment. If new patients are added at a particular time, then we have to increase their value accordingly. Therefore:
b)at_risk:存储正在观察的当前患者数。 首先,它将是我们将在实验中观察的患者总数。 如果在特定时间增加了新患者,那么我们必须相应地增加他们的价值。 因此:
Figure 19: at_risk variable formula. 图19:at_risk变量公式。c) entrance: It stores the value of new patients in a given timeline. It is possible that while experimenting, other patients are also diagnosed with the disease. To account for that, we have the entrance column.
c)入场:它在给定的时间表中存储新患者的价值。 在进行实验的同时,其他患者也可能被诊断出患有这种疾病。 为了解决这个问题,我们有入口栏。
d) censored: Our ultimate goal is to find the survival probability for a patient. At the end of the experiment, if the person is still alive, we will add him/her to the censored category. We have already discussed the types of censoring.
d)审查:我们的最终目标是找到患者的生存概率。 在实验结束时,如果该人还活着,我们会将其添加到被检查的类别中。 我们已经讨论过审查的类型。
e) observed: It stores the value of the number of subjects that died during the experiment. From a broad perspective, these are the people who met our event of interest.
e)观察到的:它存储了在实验中死亡的受试者人数的值。 从广义上讲,这些人满足了我们的兴趣。
f) removed: It stores the values of patients that are no longer part of our experiment. If a person dies or is censored, then he/she falls into this category. In short, it is an addition of the data in the observed and censored category.
f)删除:它存储不再属于我们实验的患者的值。 如果一个人去世或受到审查,那么他/她就属于这一类。 简而言之,它是观察和审查类别中数据的加法。
Figure 20: removed variable formula. 图20:删除了变量公式。11) Calculating the probability of survival for individual timelines:
11)计算各个时间表的生存概率:
Let’s first see the formula for calculating the survival of a particular person at a given time.
首先让我们看一下在给定时间计算特定人的生存的公式。
Figure 21: Calculating the probability of survival for individual timelines. 图21:计算各个时间轴的生存概率。a) Survival probability at t=0 only:
a)仅在t = 0时的生存概率:
Figure 22: Calculating the survival probability of t=0. 图22:计算t = 0的生存概率。 Figure 23: Calculating the survival probability for a given time and t=0. 图23:计算给定时间和t = 0的生存概率。b) Survival probability at t=5 only:
b)仅在t = 5时的生存概率:
Figure 24: Survival probability of t=5. 图24:t = 5的存活概率。 Figure 25: Calculating the survival probability for a given time. 图25:计算给定时间的生存概率。c) Survival probability at t=11 only:
c)仅在t = 11时的生存概率:
Figure 26: Survival probability at t=11. 图26:在t = 11时的存活概率。 Figure 27: Calculating the survival probability for a given time. 图27:计算给定时间的生存概率。Now what we found here is the probability for a specific time. What we want is the probability for the entire time for a patient. i.e., the probability of patient surviving all the rounds of the experiment.
现在,我们在这里发现的是特定时间的概率。 我们想要的是患者整个时间的概率。 即患者在所有实验中存活下来的概率。
In a nutshell, we want to find the probability of a person surviving all of the time he lived after diagnosis. What we just found is the probability of a particular experiment only.
简而言之,我们想找到一个人在诊断后一直存活的概率。 我们刚刚发现的只是特定实验的概率。
Let us take a straightforward example to understand the concept of conditional probability. For instance, we have a total of 15 balls in a non-transparent box. Out of the 15 balls, we are seven black balls, five red balls, and three green balls. Here is a pictorial view for that.
让我们以一个简单的例子来理解条件概率的概念。 例如,我们在一个不透明的盒子中总共有15个球。 在这15个球中,我们有七个黑球,五个红球和三个绿球。 这是一个图形视图。
Figure 28: Ball figure example. 图28:球形图示例。a) Probability of choosing a red ball:
a)选择一个红球的可能性:
Figure 29: Probability of choosing a red ball. 图29:选择一个红球的可能性。b) Probability of choosing the second red ball:
b)选择第二个红球的可能性:
Since we’ve removed a ball that was red, the total number of red balls we have is 4, and the total number of balls we have is 14.
由于我们移除了红色的球,因此红色球的总数为4,而红色球的总数为14。
Figure 30: Probability of choosing the second red ball. 图30:选择第二个红色球的可能性。If our question is to find the probability of both the balls being red, we will multiply it, and that is precisely what we are going to do in survival analysis. We know that a patient has survived the 1st time interval, and we want to find the probability of him surviving the second time interval given that he has survived the 1st time interval. My point here is we do not want to find the probability of the second time interval only. We want the total probability of him surviving the entire period.
如果我们的问题是找到两个球都变红的可能性,我们将其相乘,而这正是我们在生存分析中要做的事情。 我们知道患者已经在第一个时间间隔中幸存,并且我们希望找到患者在第一个时间间隔中幸存下来的可能性。 我的意思是,我们不想仅找到第二时间间隔的概率。 我们希望他在整个期间幸存的总概率。
In our example, the probability of both balls being red is as following:
在我们的示例中,两个球都变红的概率如下:
Figure 31: Calculating the probability of both balls being red. 图31:计算两个球都变红的概率。In survival analysis, we can write the formula as follows:
在生存分析中,我们可以编写如下公式:
Figure 32: Calculating S(n). 图32:计算S(n)12) Finding survival probability:
12)寻找生存概率:
We want to find the probability that a patient has survived through all the timeline till now. Now we need to find the actual survival probability for a patient.
我们想找到患者迄今为止在所有时间表中存活的可能性。 现在我们需要找到患者的实际生存概率。
a) Survival probability for t=0:
a)t = 0的生存概率:
Figure 33: Calculating the survival probability for t=0. 图33:计算t = 0的生存概率。 Figure 34: Calculating the actual survival probability at a given time. 图34:计算给定时间的实际生存概率。b) Survival probability for t=5:
b)t = 5时的生存概率:
Figure 35: Calculating the survival probability for t=5. 图35:计算t = 5时的生存概率。 Figure 36: 图36:c) Survival probability for t=11:
c)t = 11时的生存概率:
Figure 37: Calculating the survival probability for t=11. 图37:计算t = 11时的生存概率。 Figure 38: Calculating the actual survival probability at a given time. 图38:计算给定时间的实际生存概率。13) Predicting the probability:
13)预测概率:
Now the kmf object’s predict function does all of this work for us. However, it is always good practice to know the logic behind it.
现在,kmf对象的预测函数可以为我们完成所有这些工作。 但是,了解其背后的逻辑始终是一种好习惯。
Figure 39: Displaying the probability values the easy way. 图39:以简单的方式显示概率值。14) Finding the survival probability for an array of the timeline:
14)找到时间轴数组的生存概率:
Figure 40: Predicting the survival probability for an array of values. 图40:预测值数组的生存概率。15) Get survival probability for the whole timeline:
15)获取整个时间轴的生存概率:
Figure 41: Getting the survival probability for the whole timeline. 图41:获取整个时间轴的生存概率。The survival probability for a patient at timeline 0 is 1. Grasping our thoughts, then we gather that the probability that a person dies on the 1st day of diagnosis is near equals to 0. So we can say that the survival probability is as high as possible. As the timeline increases, the probability of survival decreases for a patient.
在时间轴0上,患者的生存概率为1。抓住我们的想法,然后我们得出一个人在诊断的第一天死亡的概率几乎等于0。因此,我们可以说生存概率高达可能。 随着时间线的增加,患者存活的可能性降低。
16) Plot the graph:
16)绘制图形:
Figure 42: Plotting the probability of survival. 图42:绘制生存概率。17) The median number of survival days:
17)平均生存天数:
It provides the number of days where, on average, 50% of the patients survived.
它提供了平均50%的患者存活的天数。
Figure 43: Displaying the median number of days. 图43:显示中位数天数。From the code above, we can say that on average, a person lived 310 days after the day of diagnosis.
从上面的代码中,我们可以说一个人平均在诊断后的310天就生活了。
18) Survival probability with confidence interval:
18)有置信区间的生存概率:
Figure 44: Estimating the survival probability with a confidence interval. 图44:用置信区间估计生存概率。19) Graph for survival probability with confidence interval:
19)带有置信区间的生存概率图:
Figure 45: Plotting the survival function with a confidence interval. 图45:用置信区间绘制生存函数。Now all the information we have is for the survival of a person. Now we will see what is the probability for a person to die at a specific timeline. Here notice that a higher survival probability is suitable for a person, but higher cumulative density (probability of a person to die) is not so good!
现在,我们拥有的所有信息都是为了一个人的生存。 现在,我们将看到一个人在特定时间轴上死亡的概率是多少。 在这里请注意,较高的生存概率适合一个人,但是较高的累积密度(一个人死亡的可能性)并不是那么好!
20) Probability of a person dying:
20)一个人死亡的概率:
Figure 46: Probability of a person dying. 图46:一个人死亡的可能性。Here the denominator value is subjected at risk in the previous row.
在此,分母值在前一行中处于风险中。
The formula for cumulative density:
累积密度的公式:
Figure 47: The formula for cumulative density. 图47:累积密度公式。a) Probability of a person dying at t=0:
a)一个人在t = 0时死亡的概率:
Figure 48: Probability of a person dying at t=0. 图48:一个人在t = 0时死亡的概率。b) Probability of a person dying at t=5:
b)一个人在t = 5时死亡的概率:
Figure 49: Probability of a person dying at t=5. 图49:在t = 5时一个人死亡的概率。c) Probability of a person dying at t=11:
c)一个人在t = 11时死亡的概率:
Figure 50: Probability of a person dying at t=11. 图50:在t = 11时一个人死亡的概率。Find the cumulative density:
找到累积密度:
d) Cumulative density at t=0:
d)t = 0时的累积密度:
Figure 51: Calculating the cumulative density at t=0. 图51:计算t = 0时的累积密度。e) Cumulative density at t=5:
e)t = 5时的累积密度:
Figure 52: Calculating the cumulative density at t=5. 图52:计算t = 5时的累积密度。f) Cumulative density at t=11:
f)t = 11时的累积密度:
Figure 53: Calculate the cumulative density at t=11. 图53:计算t = 11时的累积密度。 Figure 54: Displaying the probability of a subject dying. 图54:显示对象死亡的可能性。21) Plot the graph for cumulative density:
21)绘制累积密度图:
Figure 55: Plotting the cumulative density. 图55:绘制累积密度。Notice that, as the number of survival days increases the probability of a person dying increases.
请注意,随着生存天数的增加,一个人死亡的可能性也会增加。
22) The cumulative density with confidence interval:
22)带有置信区间的累积密度:
Figure 56: Calculate the cumulative density with a confidence interval. 图56:用置信区间计算累积密度。23) Graph for cumulative density with a confidence interval:
23)带有置信区间的累积密度图:
Figure 57: Plotting the cumulative density with a confidence interval. 图57:用置信区间绘制累积密度。24) Get cumulative density for a particular day:
24)获取特定日期的累积密度:
Figure 58: Find cumulative density at a specific time. 图58:查找特定时间的累积密度。25) The median time to an event:
25)事件发生的中位数时间:
We can get the amount of time remaining from the median survival time.
我们可以从中位生存时间获得剩余时间。
Figure 59: Calculating the conditional median time to an event of interest. 图59:计算到感兴趣事件的条件中值时间。26) Graph for the median time to the event:
26)图表显示事件的中位数时间:
Figure 60: Plotting the graph for the median time to an event. 图60:绘制事件的中位时间图。Until now, we discussed the Kaplan-Meier survival function. Using that, we can get the probability of the event of interest (death in our case) not occurring by that time. The survival functions are a great way to summarize and visualize the survival dataset; however, it is not the only way. We can visualize the aggregate information on survival using the Nelson-Aalen hazard function h(t). The hazard function h(t) gives us the probability that a subject under observation at time t has an event of interest (death) at that time. To get the information about the hazard function, we cannot transform the Kaplan-Meier estimator. For that, there is a proper nonparametric estimator of the cumulative hazard function:
到目前为止,我们讨论了Kaplan-Meier生存函数。 使用该方法,我们可以得到感兴趣的事件(在本例中为死亡)在该时间之前未发生的概率。 生存函数是汇总和可视化生存数据集的好方法。 但是,这不是唯一的方法。 我们可以使用Nelson-Aalen危险函数h(t)可视化生存的汇总信息。 危险函数h(t)为我们提供了在时间t观察的对象在该时间具有关注事件(死亡)的概率。 要获取有关危害函数的信息,我们无法变换Kaplan-Meier估计量。 为此,有一个适当的累积危害函数的非参数估计量:
Cumulative Hazard Function:
累积危害功能:
Figure 61: Formula to calculate the cumulative hazard function. 图61:用于计算累积危害函数的公式。1) Import required libraries:
1)导入所需的库:
Figure 62: Importing NelsonAalenFitter from lifelines. 图62:从生命线导入NelsonAalenFitter。2) Create an object of Nelson-Aalen-Fitter:
2)创建一个Nelson-Aalen-Fitter对象:
Figure 63: Creating an object of Nelson-Aalen-Fitter. 图63:创建Nelson-Aalen-Fitter的对象。3) Fitting the data:
3)拟合数据:
Figure 64: Fitting the data into the object. 图64:将数据拟合到对象中4) Finding the cumulative hazard:
4)查找累积危害:
Here we’ll use the event table generated in the previous part to understand how the hazard function actually works.
在这里,我们将使用上一部分中生成的事件表来了解危害函数的实际工作方式。
Figure 65: Finding the cumulative hazard. 图65:查找累积危害。Here is the formula to find the non-cumulative hazard probability at a specific time:
以下是用于查找特定时间的非累积危害概率的公式:
Figure 66: Formula to calculate the non-cumulative hazard probability at a specific time. 图66:用于计算特定时间的非累积危害概率的公式。a) Finding the hazard probability at t=0:
a)在t = 0处找到危险概率:
Figure 67: Finding the hazard probability at t=0. 图67:找到在t = 0时的危险概率。b) Finding the hazard probability at t=5:
b)在t = 5时找到危险概率:
Figure 68: Finding the hazard probability at t=5. 图68:找到在t = 5时的危险概率。c) Finding the hazard probability at t=11:
c)找出在t = 11时的危险概率:
Figure 69: Finding the hazard probability at t-11. 图69:找到在t-11时的危险概率。d) Finding the cumulative hazard probability at t=0:
d)求出t = 0时的累积危害概率:
Figure 70: Finding the cumulative hazard probability at t=0. 图70:求出t = 0时的累积危害概率。e) Finding the cumulative hazard probability at t=5:
e)在t = 5时求出累积危险概率:
Figure 71: Finding the cumulative hazard probability at t=5. 图71:求出t = 5时的累积危害概率。f) Finding the cumulative hazard probability at t=11:
f)求出t = 11时的累积危害概率:
Figure 72: Finding the cumulative hazard probability at t=11. 图72:求出t = 11时的累积危害概率。 Figure 73: Displaying the cumulative hazard. 图73:显示累积危害。5) Plot the graph for cumulative hazard:
5)绘制累积危害图:
Figure 74: Plot the graph for cumulative hazards. 图74:绘制累积危害图。The cumulative hazard has a less clear understanding than the survival functions, but the hazard functions are based on more advanced survival analysis techniques.
累积危害对生存功能的理解不如生存功能清晰,但是危害功能基于更先进的生存分析技术。
6) Predict a value:
6)预测一个值:
Figure 75: Predicting the value of a certain point. 图75:预测某个点的值。7) Cumulative hazard probability with confidence interval:
7)带有置信区间的累积危险概率:
Figure 76: Calculating the cumulative hazard probability with a confidence interval. 图76:以置信区间计算累积危害概率。8) Graph for cumulative hazard probability with confidence interval:
8)带有置信区间的累积危险概率图:
Figure 77: Plotting the confidence interval. 图77:绘制置信区间9) Cumulative hazard vs. cumulative density:
9)累积危害与累积密度:
Figure 78: Plotting the cumulative hazard and cumulative density 图78:绘制累积危害和累积密度Until now, we saw how we could find the survival probability and hazard probability for all of our observations. Now it is time to perform some analysis on our data to determine whether there is any difference in survival probability if we divide our data into groups based on specific characteristics. Let’s divide our data into two groups based on sex: Male and Female. Our goal here is to check is there any significant difference in survival rate if we divide our dataset based on sex. Later in this tutorial, we will see on what basis do we divide the data into groups.
到现在为止,我们已经了解了如何才能为所有观察结果找到生存概率和危险概率。 现在是时候对我们的数据进行一些分析,以确定如果根据特定特征将数据分为几组,生存率是否存在差异。 让我们根据性别将数据分为两类:男性和女性。 我们的目标是检查如果我们根据性别划分数据集,则存活率是否存在显着差异。 在本教程的后面,我们将看到我们将数据分为几类。
1) Import required libraries:
1)导入所需的库:
Figure 79: Importing pandas, numpy, matplotlib.pyplot, and KaplanMeierFitter from lifelines in Python. 图79:从Python的生命线导入pandas,numpy,matplotlib.pyplot和KaplanMeierFitter。2) Read the dataset:
2)读取数据集:
Figure 80: Reading the dataset. 图80:读取数据集。3) Organize our data:
3)整理我们的数据:
Figure 81: Organizing the data. 图81:组织数据。4) Create two objects of Kaplan-Meier-Fitter():
4)创建两个Kaplan-Meier-Fitter()对象:
Figure 82: Creating the two objects of the Kaplan-Meier-Fitter. 图82:创建Kaplan-Meier-Fitter的两个对象。5) Divide the data into groups:
5)将数据分为几组:
Figure 83: Dividing the data into groups. 图83:将数据分成几组。6) Male data:
6)男性资料:
Figure 84: Viewing the data of the male group. 图84:查看男性组的数据。7) Female data:
7)女性资料:
Figure 85: Displaying the data of the female group. 图85:显示女性组的数据。8) Fit data into our objects:
8)使数据适合我们的对象:
Figure 86: Fitting the male and female data into objects. 图86:将男性和女性数据拟合到对象中。9) Event table for the male group:
9) Event table for the male group:
Figure 87: Event table for the male group. Figure 87: Event table for the male group.10) Event table for the female group:
10) Event table for the female group:
Figure 88: Event table for the female group. Figure 88: Event table for the female group.11) Predicting survival probabilities:
11) Predicting survival probabilities:
Now we can predict the survival probability for both the groups.
Now we can predict the survival probability for both the groups.
Figure 89: Predicting the value based on time. Figure 89: Predicting the value based on time. Figure 90: Predicting the value based on time. Figure 90: Predicting the value based on time.12) Get the complete list of survival probabilities:
12) Get the complete list of survival probabilities:
a) Survival probability for a male group:
a) Survival probability for a male group:
Figure 91: Get complete data of the survival function for the male group. Figure 91: Get complete data of the survival function for the male group.b) Survival probability for the female group:
b) Survival probability for the female group:
Figure 92: Get complete data of the survival function for the male group. Figure 92: Get complete data of the survival function for the male group.13) Plot the graph for survival probabilities:
13) Plot the graph for survival probabilities:
Figure 93: Plotting the graph for survival probabilities. Figure 93: Plotting the graph for survival probabilities.Here we can notice that the probability of females surviving lung cancer is higher than that of males. Therefore, from this data, we can say that medical researchers should focus more on the factors that lead to male patients’ poor survival rates.
Here we can notice that the probability of females surviving lung cancer is higher than that of males. Therefore, from this data, we can say that medical researchers should focus more on the factors that lead to male patients' poor survival rates.
14) Get the cumulative density:
14) Get the cumulative density:
a) For the male group:
a) For the male group:
Figure 94: Cumulative density for the male group. Figure 94: Cumulative density for the male group.b) For the female group:
b) For the female group:
Figure 95: Cumulative density for the female group. Figure 95: Cumulative density for the female group.15) Plot the graph for cumulative density:
15) Plot the graph for cumulative density:
Figure 96: Plotting the graph for cumulative density for both groups. Figure 96: Plotting the graph for cumulative density for both groups.16) Hazard function:
16) Hazard function:
Figure 97: Importing the NelsonAalenFitter. Figure 97: Importing the NelsonAalenFitter.17) Fit the data into our objects:
17) Fit the data into our objects:
Figure 98: Fitting the data into our objects. Figure 98: Fitting the data into our objects.18) Cumulative hazard probability:
18) Cumulative hazard probability:
a) For the male group:
a) For the male group:
Figure 99: Cumulative hazard for the male group. Figure 99: Cumulative hazard for the male group.b) For the female group:
b) For the female group:
Figure 100: Cumulative hazard for the female group. Figure 100: Cumulative hazard for the female group.19) Plot the graph for cumulative hazard probability:
19) Plot the graph for cumulative hazard probability:
Figure 101: Plotting the graph for cumulative hazard. Figure 101: Plotting the graph for cumulative hazard.20) The median time to event for the male group:
20) The median time to event for the male group:
Figure 102: Finding the conditional median to the event of interest. Figure 102: Finding the conditional median to the event of interest.21) The median time to event graph for the male group:
21) The median time to event graph for the male group:
Figure 103: Plotting the conditional time to event for the male group. Figure 103: Plotting the conditional time to event for the male group.22) The median time to event for the female group:
22) The median time to event for the female group:
Figure 104: Finding the conditional median time to event of interest for the female group. Figure 104: Finding the conditional median time to event of interest for the female group.23) The median time to event graph for the female group:
23) The median time to event graph for the female group:
Figure 105: Conditional median time left for an event for the female group. Figure 105: Conditional median time left for an event for the female group.24) Survival probability with a confidence interval for the male group:
24) Survival probability with a confidence interval for the male group:
Figure 106: Calculating the survival probability with a confidence interval for the male group. Figure 106: Calculating the survival probability with a confidence interval for the male group.25) Survival probability graph with a confidence interval for the male group:
25) Survival probability graph with a confidence interval for the male group:
Figure 107: Confidence survival function and plot with a confidence interval for the male group. Figure 107: Confidence survival function and plot with a confidence interval for the male group.26) Survival probability with a confidence interval for the female group:
26) Survival probability with a confidence interval for the female group:
Figure 108: Survival probability with a confidence interval for the female group. Figure 108: Survival probability with a confidence interval for the female group.27) Survival probability graph with a confidence interval for the female group:
27) Survival probability graph with a confidence interval for the female group:
Figure 109: Plotting the survival function with a confidence interval for the female group. Figure 109: Plotting the survival function with a confidence interval for the female group.28) Comparison of cumulative density vs. cumulative hazard:
28) Comparison of cumulative density vs. cumulative hazard:
a) For the male group:
a) For the male group:
Figure 110: Plot the cumulative hazard and cumulative density. Figure 110: Plot the cumulative hazard and cumulative density.b) For the female group:
b) For the female group:
Figure 111: Plotting the cumulative hazard and cumulative density. Figure 111: Plotting the cumulative hazard and cumulative density.The log-rank test is a hypothesis test that is used to compare the survival distribution of two samples.
The log-rank test is a hypothesis test that is used to compare the survival distribution of two samples.
Goal: Our goal is to see if there is any significant difference between the groups being compared.
Goal: Our goal is to see if there is any significant difference between the groups being compared.
Null Hypothesis: The null hypothesis states that there is no significant difference between the groups being studied. If there is a significant difference between those groups, then we have to reject our null hypothesis.
Null Hypothesis : The null hypothesis states that there is no significant difference between the groups being studied. If there is a significant difference between those groups, then we have to reject our null hypothesis.
How do we say that there is a significant difference?
How do we say that there is a significant difference?
A p-value between 0 and 1 denotes the statistical significance. The smaller the p-value, the more significant the statistical difference between groups being studied is. Notice that our goal is to find if there is any difference between the groups we are comparing. If yes, we can do more research on why there are lower survival chances for a particular group based on various information like their diet, lifestyle, and others.
A p-value between 0 and 1 denotes the statistical significance. The smaller the p-value, the more significant the statistical difference between groups being studied is. Notice that our goal is to find if there is any difference between the groups we are comparing. If yes, we can do more research on why there are lower survival chances for a particular group based on various information like their diet, lifestyle, and others.
Less than (5% = 0.05) P-value means there is a significant difference between the groups we compared. We can partition our groups based on their sex, age, race, treatment method, and others.
Less than (5% = 0.05) P-value means there is a significant difference between the groups we compared. We can partition our groups based on their sex, age, race, treatment method, and others.
It’s a test to find out the value of P.
It's a test to find out the value of P.
1) Get the variables for the Log-rank test:
1) Get the variables for the Log-rank test:
Figure 112: Defining the variables for the log-rank test. Figure 112: Defining the variables for the log-rank test.2) Performing the Log-rank test:
2) Performing the Log-rank test:
Figure 113: Performing the log-rank test. Figure 113: Performing the log-rank test.3) Print the p-value:
3) Print the p-value:
Figure 114: Printing the p-value. Figure 114: Printing the p-value.We have compared the survival distributions of two different groups using the famous statistical method, the Log-rank test. Here we can notice that the p-value is 0.00131(<0.005) for our groups, which denotes that we have to reject the null hypothesis and admit that the survival function for both groups is significantly different. The p-values give us strong evidence that “sex” was associated with the number of survival days. In short, we can say that the “sex” of a person makes a significant difference in survival probability.
We have compared the survival distributions of two different groups using the famous statistical method, the Log-rank test. Here we can notice that the p-value is 0.00131(<0.005) for our groups, which denotes that we have to reject the null hypothesis and admit that the survival function for both groups is significantly different. The p-values give us strong evidence that “sex” was associated with the number of survival days. In short, we can say that the “sex” of a person makes a significant difference in survival probability.
The cox-proportional hazard model is a regression model generally used by medical researchers to determine the relationship between the survival time of a subject and one or more predictor variables. In short, we want to find out how different parameters like age, sex, weight, height affects the survival time of a subject.
The cox-proportional hazard model is a regression model generally used by medical researchers to determine the relationship between the survival time of a subject and one or more predictor variables. In short, we want to find out how different parameters like age, sex, weight, height affects the survival time of a subject.
In the previous section, we saw Kaplan-Meier, Nelson-Aalen, and Log-Rank-Test. However, in that, we were only able to consider one variable at a time, and one more thing to notice is that we were performing operations only on categorical variables like sex, status, and others. It can not be used for non-categorical data like age, weight, or height. As a solution for that, we use the Cox proportional hazards regression analysis, which works for both quantitative predictors non-categorical variables and for categorical variables.
In the previous section, we saw Kaplan-Meier, Nelson-Aalen, and Log-Rank-Test. However, in that, we were only able to consider one variable at a time, and one more thing to notice is that we were performing operations only on categorical variables like sex, status, and others. It can not be used for non-categorical data like age, weight, or height. As a solution for that, we use the Cox proportional hazards regression analysis, which works for both quantitative predictors non-categorical variables and for categorical variables.
In medical research, we are generally considering more than one factor to diagnose a person’s health or survival time. i.e., we generally make use of their sex, age, blood pressure, and blood sugar to find out if there is any significant difference between those in different groups. For example, if we are grouping our data based on a person’s age, our goal will be to determine which age group has a higher survival chance. Is that children’s group, adult group, or old persons’ group? Now what we need to find is on what basis we make a group? To find that, we use cox regression and find the coefficients of different parameters. Let’s see how that works!
In medical research, we are generally considering more than one factor to diagnose a person's health or survival time. ie, we generally make use of their sex, age, blood pressure, and blood sugar to find out if there is any significant difference between those in different groups. For example, if we are grouping our data based on a person's age, our goal will be to determine which age group has a higher survival chance. Is that children's group, adult group, or old persons' group? Now what we need to find is on what basis we make a group? To find that, we use cox regression and find the coefficients of different parameters. Let's see how that works!
The ultimate purpose of the cox-proportional hazard method is to notice how different factors in our dataset impact the event of interest.
The ultimate purpose of the cox-proportional hazard method is to notice how different factors in our dataset impact the event of interest.
Hazard function:
Hazard function:
Figure 115: Hazard function formula. Figure 115: Hazard function formula.The value of exp(bi) is called the Hazard Ratio (HR). We will understand this by taking an example.
The value of exp(bi) is called the Hazard Ratio (HR). We will understand this by taking an example.
Figure 116: Defining the hazard ratio. Figure 116: Defining the hazard ratio.1) Import required libraries:
1) Import required libraries:
Figure 117: Importing the required libraries with Python. Figure 117: Importing the required libraries with Python.2) Read the CSV file:
2) Read the CSV file:
Figure 118: Read the CSV file. Figure 118: Read the CSV file.3) Delete rows that contain null values:
3) Delete rows that contain null values:
Next, we need to delete the rows which have null values. Our model cannot work on rows which has null values. If we do not preprocess our data, then we might get an error.
Next, we need to delete the rows which have null values. Our model cannot work on rows which has null values. If we do not preprocess our data, then we might get an error.
Figure 119: Drop rows with null values. Figure 119: Drop rows with null values.4) Create an object for the KapanMeierFitter:
4) Create an object for the KapanMeierFitter:
Figure 120: Create an object for the KapanMeierFitter. Figure 120: Create an object for the KapanMeierFitter.5) Organize the data:
5) Organize the data:
Figure 121: Organizing the data. Figure 121: Organizing the data.6) Fit the data into an object:
6) Fit the data into an object:
Figure 122: Fitting the data into an object. Figure 122: Fitting the data into an object.7) Generating the event table:
7) Generating the event table:
Figure 123: Generating the event table. Figure 123: Generating the event table.8) Get the required columns:
8) Get the required columns:
Figure 124: Get the required columns from the data. Figure 124: Get the required columns from the data.9) Fit the data and print the summary:
9) Fit the data and print the summary:
Figure 125: Get the summary using CoxPHFitter. Figure 125: Get the summary using CoxPHFitter. Figure 126: Displaying the data. Figure 126: Displaying the data.In the picture above, notice the p-value for each column in our dataset. Next, we know that p-value<0.05 is considered statistically significant. Here we can see that “sex” and “ph.ecog” have p-values less than 0.05. So we can say that while grouping our data for analysis, we should focus on dividing the data based on these two factors.
In the picture above, notice the p-value for each column in our dataset. Next, we know that p-value<0.05 is considered statistically significant. Here we can see that “sex” and “ph.ecog” have p-values less than 0.05. So we can say that while grouping our data for analysis, we should focus on dividing the data based on these two factors.
Figure 127: Hazard Ratio formula. Figure 127: Hazard Ratio formula. Figure 128: Hazard Ratio values. Figure 128: Hazard Ratio values.Here notice the p-value for “sex” is 0.01, and the Hazard Ratio(HR) is 0.57, which indicates a strong relationship between the patients’ sex and decreased risk of death. For example, holding the other covariates constant, being female (sex=2) reduces the hazard by a factor of 0.57, or 43%. That means that females have higher survival chances. Next, the p-value for ph.ecog is <0.005, and the Hazard Ratio(HR) is 2.09, which indicates a strong relationship between the ph.ecog value and the increased risk of death. Holding the other covariates constant, a higher value of ph.ecog is associated with poor survival. Here person with higher ph.ecog value has a 109% higher risk of death. So, in short, we can say that doctors should try to reduce the value of ph.ecog in patients by providing relevant medicines. Next, notice that the Hazard Ratio(HR) for Age is 1.01, suggesting only a 1% increase for a higher age group. So we can say that there is no significant difference between different age groups.
Here notice the p-value for “sex” is 0.01, and the Hazard Ratio(HR) is 0.57, which indicates a strong relationship between the patients' sex and decreased risk of death. For example, holding the other covariates constant, being female (sex=2) reduces the hazard by a factor of 0.57, or 43%. That means that females have higher survival chances. Next, the p-value for ph.ecog is <0.005, and the Hazard Ratio(HR) is 2.09, which indicates a strong relationship between the ph.ecog value and the increased risk of death. Holding the other covariates constant, a higher value of ph.ecog is associated with poor survival. Here person with higher ph.ecog value has a 109% higher risk of death. So, in short, we can say that doctors should try to reduce the value of ph.ecog in patients by providing relevant medicines. Next, notice that the Hazard Ratio(HR) for Age is 1.01, suggesting only a 1% increase for a higher age group. So we can say that there is no significant difference between different age groups.
10) Check which factor affects the most from the graph:
10) Check which factor affects the most from the graph:
In the following graph, we can notice the difference in “sex” and “ph.ecog” data.
In the following graph, we can notice the difference in “sex” and “ph.ecog” data.
Figure 129: Plot the result on a graph. Figure 129: Plot the result on a graph.11) Check our theory with real observations:
11) Check our theory with real observations:
Let’s check our conclusions with real data from our observations.
Let's check our conclusions with real data from our observations.
Figure 130: Conclusion table. Figure 130: Conclusion table. Figure 131: Plotting our data. Figure 131: Plotting our data.In the above graph, we can see that person 23 has the highest chance of survival, while person 17 has the least chance of survival. By checking the main table, we can notice a significant change in the ph.ecog value. We can also see that people 21 and 23 have higher chances of survival as they have the least value of ph.ecog.
In the above graph, we can see that person 23 has the highest chance of survival, while person 17 has the least chance of survival. By checking the main table, we can notice a significant change in the ph.ecog value. We can also see that people 21 and 23 have higher chances of survival as they have the least value of ph.ecog.
Okay, so this is it for this tutorial. Thank you for reading. Your feedback is always welcome.
Okay, so this is it for this tutorial. 感谢您的阅读。 Your feedback is always welcome.
This is a revamped version of the original article published on KDNuggets.
This is a revamped version of the original article published on KDNuggets .
📚 If you enjoyed this piece, check out our tutorial on neural networks from scratch with Python code and math in detail.📚
📚 If you enjoyed this piece, check out our tutorial on neural networks from scratch with Python code and math in detail.📚
DISCLAIMER: The views expressed in this article are those of the author(s) and do not represent the views of Carnegie Mellon University. These writings do not intend to be final products, yet rather a reflection of current thinking, along with being a catalyst for discussion and improvement.
DISCLAIMER: The views expressed in this article are those of the author(s) and do not represent the views of Carnegie Mellon University. These writings do not intend to be final products, yet rather a reflection of current thinking, along with being a catalyst for discussion and improvement.
Published via Towards AI
Published via Towards AI
For attribution in academic contexts, please cite this work as:
For attribution in academic contexts, please cite this work as:
Shukla, et al., “Survival Analysis with Python Tutorial - How, What, When, and Why”, Towards AI, 2020Google Colab Implementation
Google Colab Implementation
Github Repository
Github Repository
[1] Lifelines Example, https://lifelines.readthedocs.io/en/latest/Examples.html
[1] Lifelines Example, https://lifelines.readthedocs.io/en/latest/Examples.html
[2] Kaplan — Meier Estimator, Wikipedia, https://en.wikipedia.org/wiki/Kaplan%E2%80%93Meier_estimator
[2] Kaplan — Meier Estimator, Wikipedia, https://en.wikipedia.org/wiki/Kaplan%E2%80%93Meier_estimator
[3] Lifelines, Univariate NelsonAalenFilter, https://lifelines.readthedocs.io/en/latest/fitters/univariate/NelsonAalenFitter.html
[3] Lifelines, Univariate NelsonAalenFilter, https://lifelines.readthedocs.io/en/latest/fitters/univariate/NelsonAalenFitter.html
[4] STHDA, Statistical Tools for High-throughput Data Analysis, http://www.sthda.com/english/wiki/cox-proportional-hazards-model
[4] STHDA, Statistical Tools for High-throughput Data Analysis, http://www.sthda.com/english/wiki/cox-proportional-hazards-model
翻译自: https://medium.com/towards-artificial-intelligence/survival-analysis-with-python-tutorial-how-what-when-and-why-19a5cfb3c312
python 生存分析
相关资源:泰坦尼克数据集及预测生存源码