通过 R 中的事件时间在生存分析中进行情节分裂

Episode splitting in survival analysis by the timing of an event in R

是否有可能在 R 的生存分析中通过给定变量拆分情节,类似于在 STATA 中使用 stsplit 以下列方式:stsplit var, at(0) after(time=time)?

我知道生存包允许通过给定的切点来分割情节,例如 survSplit 中的 c(0,5,10,15),但是如果一个变量,比如离婚时间,因人而异,那么为每个人提供分界点是不可能的,而且分割必须基于变量的值(比如毕业,或离婚,或工作终止)。

有没有人知道某个包或知道我可以利用的资源?

经过一番摸索,我认为 survival 包中的 tmerge() 可以实现 stsplit var 可以做的事情,即不仅通过给定的切点(对所有观察都相同)分割剧集,而且通过事件发生在个人身上。

这是我知道如何拆分数据的唯一方法

id<-c(1,2,3)
age<-c(19,20,29)
job<-c(1,1,0)
time<-age-16 ## create time since age 16 ## 

data<-data.frame(id,age,job,time)

  id age job time
1  1  19   1    3
2  2  20   1    4
3  3  29   0   13

## simple split by time ## 
## 0 to up 2 years, 2-5 years, 5+ years ## 

data2<-survSplit(data,cut=c(0,2,5),end="time",start="start",
                event="job")

  id age start time job
1  1  19     0    2   0
2  1  19     2    3   1
3  2  20     0    2   0
4  2  20     2    4   1
5  3  29     0    2   0
6  3  29     2    5   0
7  3  29     5   13   0

但是,如果我想按某个变量拆分,比如每个人完成学业的时间,每个人可能有不同的切点(不同年龄完成学业)。

## split by time dependent variable (age finished school) ##
d1<-data.frame(id,age,time,job)

scend<-c(17,21,24)-16

d2<-data.frame(id,scend)

## create start/stop time ## 
base<-tmerge(d1,d1,id=id,tstop=time)
## create time-dependent covariate ## 
s1<-tmerge(base,d2,id=id,
           finish=tdc(scend))

  id age time job tstart tstop finish
1  1  19    3   1      0     1      0
2  1  19    3   1      1     3      1
3  2  20    4   1      0     4      0
4  3  29   13   0      0     8      0
5  3  29   13   0      8    13      1

我认为 tmerge() 或多或少可以与 STATA 中的 stsplit 函数相媲美。

可能 Epi package is what you are looking for. It offers multiple ways to cut/split the follow-up time using the Lesix objects. Here is the documentationcutLesix() 个。