如何进行生存分析

引入R包

library("fromto")

准备示例数据

n_samples = 100  
data = data.frame(  
  time = sample(1:500, n_samples, replace = TRUE),  # survival time 
  status = sample(0:1, n_samples, replace = TRUE),  # survival(0 = not occur,1 = occur)  
  gene1 = rnorm(n_samples),  # gene1 expression 
  gene2 = rnorm(n_samples),  # gene2 expression 
  gene3 = rnorm(n_samples),  # gene3 expression
  gene4 = rnorm(n_samples),  # gene4 expression
  gene5 = rnorm(n_samples),  # gene5 expression
  gene6 = rnorm(n_samples),  # gene6 expression
  gene7 = rnorm(n_samples),  # gene7 expression
  gene8 = rnorm(n_samples),  # gene8 expression
  gene9 = rnorm(n_samples),  # gene9 expression
  gene10 = rnorm(n_samples), # gene10 expression
  gene11 = rnorm(n_samples)  # gene11 expression
)

survival_unicox函数执行单因素cox生存分析

res_unicox = survival_unicox(data)

survival_multicox函数执行多因素cox生存分析

res_multicox = survival_multicox(data)

fplot1函数森林图可视化cox分析结果

fplot1(res_unicox,nameplot = "res_unicox", height = 10)

fplot2函数森林图可视化cox分析结果

res_multicox$dataset = "TCGA"
fplot2(res_multicox,nameplot = "mutli_unicox", height = 10)

kmplot1函数执行km生存分析与log-rank检验

kmplot1(data, 
        minprop = 0.3, 
        GeneName = "gene3", 
        CancerType = "unknown", 
        Timeunit = "day")