![](/img/trans.png)
[英]How to present survival data that includes time-varying covariates and fit the model in R
[英]R :Fitting survival trees with time-varying covariates in RandomForestSRC
在包 LTRCtrees 中,可以按照以下示例將決策樹擬合為 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.
Wongvibulsin、Wu 和 Zeger(2019 年)的這篇論文擴展了 randomForestSRC 包以處理 TVC,但您可能需要聯系作者以獲取任何相關代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.