最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mlr3 - FG model using surv.coxph learner and its performance - Stack Overflow

programmeradmin3浏览0评论

I am trying to use surv.coxph learner and survival::finegray() to train and validate the FG model. I need advice, on whether I am on the right track. Thank you in advance.

library(survival)
library(mlr3proba)
data(cancer, package="survival")
 
# Treat time to death and plasma cell malignancy as competing risks
etime <- with(mgus2, ifelse(pstat==0, futime, ptime))
event <- with(mgus2, ifelse(pstat==0, 2*death, 1))
event <- factor(event, 0:2, labels=c("censor", "pcm", "death"))

mgus2x <- mgus2 %>% select(c("id", "age", "sex"))
 
# FG model for PCM. See ?finegray
pdata <- finegray(Surv(etime, event) ~ ., data=mgus2x, etype ="pcm")
  • Define task
# Define the survival task with groups and weights
task_FG <- TaskSurv$new(
     id = "fg_mgus2",
     backend = pdata,
     time = "fgstart",
     time2 = "fgstop",
     event = "fgstatus",
     type = "counting"
   )

# Set id as group,  fgwt as weights
task_FG$set_col_roles(cols = "id", roles = "group")
task_FG$set_col_roles(cols = "fgwt", roles = "weight")
# task_FG$set_col_roles(cols = "fgstatus", add_to = "stratum") Error: Cannot combine stratification with grouping
 
task_FG
  • Task description
## <TaskSurv:fg_mgus2> (41775 x 5)
## * Target: fgstart, fgstop, fgstatus
## * Properties: groups, weights
## * Features (2):
##  - dbl (1): age
##  - fct (1): sex
## * Groups: id
## * Weights: fgwt

Train the learner

part <- partition(task_FG)
coxFG <- lrn("surv.coxph")
coxFG$train(task_FG, part$train)

Create a prediction and assess performance

p <- coxFG$predict(task_FG, part$test)
p$distr[c(1,63, 126, 186, 225, 289)]$survival(seq(0,400, by=50)) # First rows for id=1:6

Output

##         [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
## 0   1.0000000 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
## 50  0.9838814 0.9757258 0.9829730 0.9829730 0.9717968 0.9822586
## 100 0.9656810 0.9485604 0.9637661 0.9637661 0.9403709 0.9622614
## 150 0.9517421 0.9279320 0.9490702 0.9490702 0.9166055 0.9469723
## 200 0.9445248 0.9173116 0.9414657 0.9414657 0.9044036 0.9390647
## 250 0.9374414 0.9069284 0.9340055 0.9340055 0.8924968 0.9313098
## 300 0.9291849 0.8948763 0.9253138 0.9253138 0.8787041 0.9222781
## 350 0.9214375 0.8836171 0.9171620 0.9171620 0.8658464 0.9138107
## 400 0.8969712 0.8483794 0.8914447 0.8914447 0.8257810 0.8871186
p$score(msr("surv.cindex"))
## Error in `[.default`(truth, , "time") : subscript out of bounds
发布评论

评论列表(0)

  1. 暂无评论