文档介绍:用R作生存分析
生存分析
and data sets
library() # 查看你的系统中所有已装的libraries
library(survival) # 加载一个library, 也可使用鼠标来做
library(help=survival) # see the list of available functions and data sets. data(aml) # 加载数据 aml
aml # see the data
# 《生存分析》需要的两个 libraries
library(survival)
library(KMsurv) #包含我们教材中所有的数据
# 若想使数据中的变量能够在R中作为一个变量使用,use attach():
> attach(aids)
> infect
> detach(aids)
Objects
#由函数 Surv 产生一个 survival object
Surv (time, time2, event, type)
? time: survival time
? time2: ending time if it is interval censored
? event: censoring variable.
For interval censored data, 0=right censored, 1=event at time, 2=left censored, 3=interval censored.
? type: indicating whether it is right censored, left censored or interval censored or counting process. 默认值是右删失或 counting process
#假设一个观测值为[2, 3],则 R 语句为
Surv(time=2,time2=3, event=3, type = "interval")
#右删失数据
? attach(aml)
? Surv(time,status)
? detach(aml)
#左截断右删失数据
? data(psych)
? attach(psych)
? <- Surv(age, age+time, death)
?
[1] (51,52 ] (58,59 ] (55,57 ] (28,50 ] (21,51+] (19,47 ] (25,57 ] [22] (29,63+] (35,65+] (32,67 ] (36,76 ] (32,71+]
? detach(psych)
三. The Kaplan-Meier Estimates
#计算生存曲线:survfit,有三个重要的参数:formula, , and .
survfit(formula, = , = "log")
=”