Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in ranger_surv.unify when type= "chf" #38

Open
eligarcos opened this issue Apr 9, 2024 · 1 comment
Open

Error in ranger_surv.unify when type= "chf" #38

eligarcos opened this issue Apr 9, 2024 · 1 comment

Comments

@eligarcos
Copy link

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))

@kapsner
Copy link
Contributor

kapsner commented Aug 1, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants