一、生存分析R语言基础
我们将使用两个R包:
survival 用于计算存活分析
survminer 用于总结和可视化生存分析结果
library(survival)
library(survminer)
结果展示:
fit2 <- survfit( Surv(stop, event) ~ size, data = bladder )
ggsurvplot(fit2)
二、2万个基因的身存分析(循环)
km_result <- data.frame()
for(i in colnames(precox[,4:ncol(precox)])){
cut <- surv_cutpoint(data = precox,time = "RFS.time",event = "RFS",variables = i,minprop = 0.1)
cat <- surv_categorize(cut)
fit <- survfit(Surv(RFS.time,RFS)~get(i),cat)
fit1 <- summary(fit)
re <- surv_pvalue(fit,cat)
km_result <- rbind(km_result,
cbind(id=i,
riskscore=cut$cutpoint$cutpoint,
pvalue=re$pval))
}