简体   繁体   中英

R :Fitting survival trees with time-varying covariates in RandomForestSRC

In the package LTRCtrees one can fit a decision tree to the special format of the Surv function :Surv(time, time2, event) as per below example

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)

Is it possible to use the same function on a Random Forest using the RandomForestSRC library

library(randomForestSRC)
RF.fit <- rfsrc(Surv(time1, time2, event) ~ age + sex + log(bili), data=pbcseq, nsplit = 3, ntree = 100, importance = TRUE)

Which generates an error:

Error in parseFormula(formula, data, ytry) : 
  Survival formula incorrectly specified.

Wongvibulsin、Wu 和 Zeger(2019 年)的这篇论文扩展了 randomForestSRC 包以处理 TVC,但您可能需要联系作者以获取任何相关代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM