在LTRCtree包中,可以将决策树适合Surv函数的特殊格式:Surv(time,time2,event),如下例所示
set.seed(0)
library(survival)
library(LTRCtrees)
## Create the start-stop-event triplet needed for coxph and LTRC trees
first <- with(pbcseq, c(TRUE, diff(id) !=0)) #first id for each subject
last <- c(first[-1], TRUE) #last id
time1 <- with(pbcseq, ifelse(first, 0, day))
time2 <- with(pbcseq, ifelse(last, futime, c(day[-1], 0)))
event <- with(pbcseq, ifelse(last, status, 0))
event <- 1*(event==2)
pbcseq$time1 <- time1
pbcseq$time2 <- time2
pbcseq$event <- event
## Fit the Cox model and LTRC trees with time-varying covariates
fit.cox <- coxph(Surv(time1, time2, event) ~ age + sex + log(bili), pbcseq)
LTRCIT.fit <- LTRCIT(Surv(time1, time2, event) ~ age + sex + log(bili), pbcseq)
LTRCART.fit <- LTRCART(Surv(time1, time2, event) ~ age + sex + log(bili), pbcseq)
是否可以使用RandomForestSRC库在随机森林中使用相同的功能
library(randomForestSRC)
RF.fit <- rfsrc(Surv(time1, time2, event) ~ age + sex + log(bili), data=pbcseq, nsplit = 3, ntree = 100, importance = TRUE)
哪个会产生错误:
Error in parseFormula(formula, data, ytry) :
Survival formula incorrectly specified.
答案 0 :(得分:0)
This paper扩展了randomForestSRC包以处理TVC,但您可能需要与作者联系以获取任何相关代码。