> setwd(dir="D:/onedrive/Desktop/xxx/数据")
> data<-read.csv("GGL.csv",header=T)
> GGL<-data
> str(GGL)
'data.frame': 365 obs. of 3 variables:
$ time : num 24.3 24.3 24.8 25.3 25.9 ...
$ status: int 0 0 1 0 0 0 0 0 0 0 ...
$ group : num 0 0 1 0 1 0 0 0 0 0 ...
对变量转换成因子,并添加标签
> GGL$group<-factor(GGL$group,levels=c(0,1),labels=c("LPA","Non-LPA"))
> library("survival")
> library("survminer")
用函数Surv() 创建生存对象:
> surv.obj <- Surv(time = GGL$time, event = GGL$status)
> surv.obj
[1] 24.26000+ 24.33000+ 24.79000 25.28000+ 25.87000+ 25.97000+
[7] 26.33000+ 26.63000+ 26.76000+ 27.02000+ 27.06000+ 27.48000+
生存率的K-M估计的计算用函数survfit() 实现: