使用surv.ranger调整参数时出错

时间:2018-10-01 09:40:50

标签: r survival-analysis mlr

我想使用带有游骑兵装备的随机森林技术来拟合生存模型。
代码中的数据(df)是示例数据,实际数据由大约1000个观察值和5个变量(包括时间和结果)组成。

library(survival); library(mlr); library(ranger); 
#library(dplyr) also requried
#> Loading required package: ParamHelpers

df <- dplyr::tribble(
  ~Time, ~Outcome, ~factorA,
  10, 1, "Cat1",
  70, 0, "Cat1",
  60, 1, "Cat2",
  10, 1, "Cat1",
  40, 1, "Cat1",
  10, 1, "Cat2",
  10, 1, "Cat1",
  30, 0, "Cat1",
  10, 1, "Cat2",
  20, 0, "Cat1",
  50, 1, "Cat2",
  10, 1, "Cat2",
  50, 0, "Cat1",
  10, 1, "Cat1",
  10, 1, "Cat1",
)


df <- as.data.frame(df)
df$factorA <- factor(df$factorA)

surv_task <- makeSurvTask(data = df, target = c("Time", "Outcome"))

# Ranger params
ran_param <- makeParamSet(
  makeDiscreteParam("splitrule", values = c("logrank", "C", "maxstat"))
)

ctrl <-  makeTuneControlGrid()
rdesc <- makeResampleDesc("CV", iters = 3L)

check <- tuneParams("surv.ranger", surv_task, rdesc, par.set = ran_param, control = ctrl)
#> [Tune] Started tuning learner surv.ranger for parameter set:
#>               Type len Def            Constr Req Tunable Trafo
#> splitrule discrete   -   - logrank,C,maxstat   -    TRUE     -
#> With control class: TuneControlGrid
#> Imputation value: -0
#> [Tune-x] 1: splitrule=logrank
#> Error in `[.data.frame`(num.response, x == y): undefined columns selected

任何人都可以帮助启发错误的原因吗?
正确的方法应该是什么?

0 个答案:

没有答案