Skip to content

When using the "mboost" boost_tree for prediction, an error occurs when case weights are applied. #363

@AKALeon

Description

@AKALeon
library(tidymodels)
library(mboost)
library(censored)
table(lung$status)
> table(lung$status)

  1   2 
 63 165 
data = lung |> 
  mutate(outcome = Surv(time, status == 2),
         case_wts = if_else(status == 2, 1, 165 / 63),
         case_wts = importance_weights(case_wts)) |> 
  select(-time, -status)

boost_tree_spec = boost_tree() |> 
  set_engine('mboost') |> 
  set_mode('censored regression')

rec = recipe(formula = outcome ~ ., data = data) |> 
  step_impute_mean(all_numeric_predictors())

When no case weight is added, everything works normally:

workflow() |> 
  add_recipe(rec) |> 
  add_model(boost_tree_spec) |> 
  fit(data = data) |> 
  augment(new_data = data, 
          eval_time = sort(unique(lung$time))) |> 
  concordance_survival(truth = outcome, 
                       estimate = .pred_time)
# A tibble: 1 × 3
  .metric              .estimator .estimate
  <chr>                <chr>          <dbl>
1 concordance_survival standard       0.736

When case weight is added, there is error:

workflow() |> 
  add_recipe(rec) |> 
  add_model(boost_tree_spec) |> 
  add_case_weights(col = case_wts) |> 
  fit(data = data) |>
  augment(new_data = data, 
          eval_time = sort(unique(lung$time))) |> 
  concordance_survival(truth = outcome, 
                       estimate = .pred_time)
Error in survFit.mboost(object$fit, new_data) : 
  survFit cannot (yet) deal with weights

This error occurs in augment() not in fit():

workflow() |> 
  add_recipe(rec) |> 
  add_model(boost_tree_spec) |> 
  add_case_weights(col = case_wts) |> 
  fit(data = data)
══ Workflow [trained] ═════════════════════════════════════════════════════════════════════
Preprocessor: Recipe
Model: boost_tree()

── Preprocessor ───────────────────────────────────────────────────────────────────────────
1 Recipe Step

• step_impute_mean()

── Case Weights ───────────────────────────────────────────────────────────────────────────
case_wts

── Model ──────────────────────────────────────────────────────────────────────────────────

	 Model-based Boosting

Call:
mboost::blackboost(formula = formula, data = data, weights = weights,     family = family, control = mboost::boost_control(), tree_controls = partykit::ctree_control(teststat = "quadratic",         testtype = "Teststatistic", mincriterion = 0, minsplit = 10,         minbucket = 4, maxdepth = 2, saveinfo = FALSE))


	 Cox Partial Likelihood 

Loss function:  

Number of boosting iterations: mstop = 100 
Step size:  0.1 
Offset:  0 
Number of baselearners:  1 
workflow() |> 
  add_recipe(rec) |> 
  add_model(boost_tree_spec) |> 
  add_case_weights(col = case_wts) |> 
  fit(data = data) |>
  augment(new_data = data, 
          eval_time = sort(unique(lung$time)))
Error in survFit.mboost(object$fit, new_data) : 
  survFit cannot (yet) deal with weights

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