对数秩检验

Python 中的生存分析

Shae Wang

Senior Data Scientist

假设检验

  • 一种统计推断方法

  • 原假设 $H_0$:如加州与内华达州居民的平均收入相同。

  • 备择假设 $H_1$:如两州居民的平均收入不同。

  • P 值:在原假设为真时,观察到这些数据的可能性是多少?

假设检验漫画。

Python 中的生存分析

对数秩检验的假设检验

  • 在每个时间点 t 比较各组的生存概率 $S_i$

$H_0$: $S_A(t)=S_B(t)$

$H_1$: $S_A(t)\neq S_B(t)$

  • P 值:若 $S_A(t)=S_B(t)$,出现我们数据的概率是多少?

多条生存曲线 并排的多条生存曲线。

Python 中的生存分析

运行对数秩检验

from lifelines.statistics import logrank_test

logrank_test(durations_A, durations_B, event_observed_A, event_observed_B)
  • .print_summary()
  • .p_value
  • .test_statistic
Python 中的生存分析

对数秩检验示例

该项目会改变婴儿开始说话的时间吗?

t.head(2)
    id  duration  observed
0    1        12         0
1    4         6         1
c.head(2)
    id  duration  observed
0    0        11         1
1    2        14         0
lrt = logrank_test(
    durations_A = t['duration'], 
    durations_B = c['duration'], 
    event_observed_A = t['observed'],
    event_observed_B = c['observed'])
lrt.print_summary()
<lifelines.StatisticalResult: logrank_test>
 null_distribution = chi squared
degrees_of_freedom = 1
         test_name = logrank_test
 test_statistic    p  -log2(p)
           0.09 0.77      0.38
Python 中的生存分析

请牢记…

  • 对数秩检验是非参数假设检验
  • 使用 lifelines 时,数据需为右删失(如受试者 3)
  • 删失需为非信息性
  • 多组($n>2$)对数秩检验用 pairwise_logrank_test()multivariate_logrank_test()

删失漫画。

Python 中的生存分析

开始练习!

Python 中的生存分析

Preparing Video For Download...