Skip to content

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

Closed

Description

@eligarcos

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

Activity

  1. kapsner commented on Aug 1, 2024

    @kapsner
    Contributor

    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?

  2. mayer79 commented on Apr 24, 2026

    @mayer79
    Contributor

    Can't reproduce as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions