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 with simulated annealing and censored regression #121

Open
topepo opened this issue Sep 1, 2024 · 0 comments
Open

error with simulated annealing and censored regression #121

topepo opened this issue Sep 1, 2024 · 0 comments

Comments

@topepo
Copy link
Member

topepo commented Sep 1, 2024

A reprex from Thomas Dilling over email:

library(tidyverse)
library(tidymodels)
library(censored)
#> Loading required package: survival
library(finetune)
library(survival)
tidymodels_prefer()

data(cancer)

lung <- lung %>% drop_na()

lung <- lung %>% mutate(survival = Surv(time, status == 2), 
                        .keep = 'unused')

survival_metrics <- metric_set(concordance_survival,
                               brier_survival)

evaluation_time_points <- seq(30, 1020, 30)

cv_splits <- vfold_cv(lung, v = 10)

lasso_rec <- recipe(survival ~ ., data = lung) %>%
  update_role(survival, new_role = "outcome") %>%
  step_novel(all_nominal_predictors()) %>%
  step_dummy(all_nominal_predictors()) 

lasso <- proportional_hazards(penalty = tune(), mixture = 1) %>%
  set_engine('glmnet') %>%
  set_mode('censored regression')

lasso_wf <- workflow() %>%
  add_recipe(lasso_rec) %>%
  add_model(lasso) 

lasso_grid <- grid_space_filling(penalty(), 
                                 size = 15,
                                 type = "max_entropy")

lasso_param <- lasso_wf %>% 
  extract_parameter_set_dials() %>%
  update(penalty = penalty(c(-9, -1)))

set.seed(100)
lasso_res <- tune_grid(lasso_wf,
                       resamples = cv_splits,
                       grid = lasso_grid,
                       metrics = survival_metrics,
                       eval_time = evaluation_time_points,
                       control = control_grid(save_pred = TRUE))

ctrl_sa <- control_sim_anneal(verbose_iter = TRUE, no_improve = 20L)

lasso_sa <-
  lasso_wf %>%
  tune_sim_anneal(
    resamples = cv_splits,
    metrics = survival_metrics,
    initial = lasso_res,
    param_info = lasso_param,
    eval_time = evaluation_time_points, # Not needed for concordance_survival
    iter = 50,
    control = ctrl_sa
  )
#> Optimizing concordance_survival
#> Error in if (!is.na(eval_time) && any(names(res) == ".eval_time")) {: missing value where TRUE/FALSE needed
#> ✖ Optimization stopped prematurely; returning current results.

Created on 2024-09-01 with reprex v2.1.0

No issues with tune_grid() or tune_bayes().

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

1 participant