treeshap
treeshap copied to clipboard
Error in ranger_surv.unify when type= "chf"
On treeshap version 0.3.0, there is an error thrown by ranger_surv.unify, when type= "chf":
`unified_model_surv <- ranger_surv.unify(rf, train_x, times = c(23), type = "chf")
Error in ranger_surv.unify(rf, train_x, times = c(23), type = "chf") :
times must be a numeric vector and argument
type = 'survival' or type = 'chf' must be set.`
I believe there is some issue here:
stopifnot(`times` must be a numeric vector and argument \n `type = 'survival'` or `type = 'chf'` must be set. = ifelse(!is.null(times), is.numeric(times) && type == "survival", TRUE))
Hi @GLRXV ,
I am not able to reproduce the error with threeshap v0.3.1:
library(treeshap)
data_colon <- data.table::data.table(survival::colon)
data_colon <- na.omit(data_colon[get("etype") == 2, ])
surv_cols <- c("status", "time", "rx")
feature_cols <- colnames(data_colon)[3:(ncol(data_colon) - 1)]
x <- model.matrix(
~ -1 + .,
data_colon[, .SD, .SDcols = setdiff(feature_cols, surv_cols[1:2])]
)
y <- survival::Surv(
event = (data_colon[, get("status")] |>
as.character() |>
as.integer()),
time = data_colon[, get("time")],
type = "right"
)
set.seed(123)
ranger_num_model <- ranger::ranger(
x = x,
y = y,
data = data_colon,
max.depth = 10,
num.trees = 10
)
# to save some time for these tests, compute model here once:
unified_model <- ranger_surv.unify(ranger_num_model, x)
unified_model2 <- ranger_surv.unify(ranger_num_model, x, times = c(23), type = "chf")
Could you please try, if this is working for you as well?