Python从零开始第五章生物信息学⑤生存分析(log-rank)

目录

Python从零开始第五章生物信息学①提取差异基因

Python从零开始第五章生物信息学②热图及火山图

Python从零开始第五章生物信息学③kegg查询

Python从零开始第五章生物信息学④kegg查询续

Python从零开始第五章生物信息学⑤生存分析(log-rank)

==================================================

R语言之生信⑤TCGA生存分析2

==================================================

正文

生存分析(Survival analysis)是指根据试验或调查得到的数据对生物或人的生存时间进行分析和推断,研究生存时间和结局与众多影响因素间关系及其程度大小的方法,也称生存率分析或存活率分析。

生存分析适合于处理时间-事件数据,生存时间(survival time)是指从某起点事件开始到被观测对象出现终点事件所经历的时间,如从疾病的“确诊”到“死亡”。
生存时间有两种类型:完全数据(complete data)指被观测对象从观察起点到出现终点事件所经历的时间;截尾数据(consored data)或删失数据,指在出现终点事件前,被观测对象的观测过程终止了。由于被观测对象所提供的信息是不完全的,只知道他们的生存事件超过了截尾时间。截尾主要由于失访、退出和终止产生。
生存分析方法大体上可分为三类:非参数法、半参数方法和参数法,用Kaplan-Meier曲线(也称乘积极限法Product limit method)和寿命表法(Life table method)估计生存率和中位生存时间等是非参数的方法,半参数方法指Cox比例风险模型,参数方法指指数模型、Weibull模型、Gompertz模型等分析方法。

非参数法(log-rank)
Log-rank test to compare the survival curves of two or more groups(通过比较两组或者多组之间的的生存曲线,一般是生存率及其标准误,从而研究之间的差异,一般用log rank检验)

《Python从零开始第五章生物信息学⑤生存分析(log-rank)》

  • 导入必须的python包
%reset -f
%clear
# In[*]
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
import lifelines as ll
from IPython.display import HTML
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.plotly as py
import plotly.tools as tls   
from plotly.graph_objs import *
import os
from lifelines.estimation import KaplanMeierFitter
kmf = KaplanMeierFitter()
from lifelines.statistics import logrank_test
os.chdir("D:\\Rwork\\third\\Fig2")
  • 读取数据
sur = pd.read_csv('entropy_surival.csv',header=0,index_col=0)


sur = sur[['sample','entr','PFI_status', 'PFI_time']]

sur['entr'] = np.where(sur['entr'] > sur['entr'].median(), 'high','low')
sur  = sur.dropna(axis=0,how='any')
#sur_high = sur.loc[sur["PPP2R2B"] >sur["PPP2R2B"].median()]
#sur_high = sur_high.loc[:,['futime','fustat','PPP2R2B']]
#sur_high.head(5)
sur['entr']
  • 绘制两组的生存曲线,且比较其P值
# In[*]


f_low = sur['entr'] == 'low'
T_low = sur[f_low]['PFI_time']
C_low = sur[f_low]['PFI_status']
kmf.fit(T_low,event_observed=C_low)
kmf.plot(title='low entr')



# In[*]

f_high = sur['entr'] == 'high'
T_high = sur[f_high]['PFI_time']
C_high = sur[f_high]['PFI_status']
kmf.fit(T_high,event_observed=C_high)
kmf.plot(title='high entr')

  • 得到的结果如下所示:两组的生存存在不同(p< 0.05)
<lifelines.StatisticalResult: 

t_0=-1, alpha=0.95, null_distribution=chi squared, df=1

test_statistic      p    
        7.5138 0.0061  **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
  • 两组的各自生存曲线

    《Python从零开始第五章生物信息学⑤生存分析(log-rank)》
    《Python从零开始第五章生物信息学⑤生存分析(log-rank)》

    原文作者:左手柳叶刀右手小鼠标
    原文地址: https://www.jianshu.com/p/d198d39dd51f
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞