Closed topepo closed 9 months ago
The error occurs in parsnip:::augment_censored()
. That calls
predict(x, new_data = new_data, type = "time") # 'x' is a parsnip model
and that fails when new_data
is created by the workflow. For example, using the test data, the workflow's new_data
looks like:
Browse[2]> new_data
# A tibble: 500 × 4
`(Intercept)` X1 X2 event_time
<dbl> <dbl> <dbl> <Surv>
1 1 1 -0.626 3.072882
2 1 1 0.184 1.010515
3 1 0 -0.836 5.739025
4 1 1 1.60 2.483024
5 1 0 0.330 10.896000
6 1 0 -0.820 9.783280+
7 1 1 0.487 3.489154
8 1 1 0.738 6.022507+
9 1 1 0.576 3.636429
10 1 1 -0.305 6.119918
# ℹ 490 more rows
For without a workflow, it is:
Browse[2]> new_data
# A tibble: 500 × 3
X1 X2 event_time
<dbl> <dbl> <Surv>
1 1 -0.626 3.072882
2 1 0.184 1.010515
3 0 -0.836 5.739025
4 1 1.60 2.483024
5 0 0.330 10.896000
6 0 -0.820 9.783280+
7 1 0.487 3.489154
8 1 0.738 6.022507+
9 1 0.576 3.636429
10 1 -0.305 6.119918
# ℹ 490 more rows
Perhaps the addition of the intercept column causes the failure (although the error message does not suggest that).
@topepo which versions did you use here? I can't reproduce with the current dev versions of parsnip, censored, and workflows.
library(tidymodels)
library(censored)
#> Loading required package: survival
set.seed(1)
sim_dat <- prodlim::SimSurv(500) %>%
mutate(event_time = Surv(time, event)) %>%
select(event_time, X1, X2)
workflow() %>%
add_model(proportional_hazards()) %>%
add_formula(event_time ~ .) %>%
fit(data = sim_dat) %>%
augment(new_data = sim_dat)
#> Error in `augment()`:
#> ! The `eval_time` argument is missing, with no default.
#> Backtrace:
#> ▆
#> 1. ├─... %>% augment(new_data = sim_dat)
#> 2. ├─generics::augment(., new_data = sim_dat)
#> 3. └─workflows:::augment.workflow(., new_data = sim_dat)
#> 4. ├─generics::augment(...)
#> 5. └─parsnip:::augment.model_fit(fit, new_data_forged, eval_time = eval_time, ...)
#> 6. └─parsnip:::augment_censored(x, new_data, eval_time = eval_time)
#> 7. └─rlang::abort(...)
workflow() %>%
add_model(proportional_hazards(penalty = 0.001) %>% set_engine("glmnet")) %>%
add_formula(event_time ~ .) %>%
fit(data = sim_dat) %>%
augment(new_data = sim_dat)
#> Error in `augment()`:
#> ! The `eval_time` argument is missing, with no default.
#> Backtrace:
#> ▆
#> 1. ├─... %>% augment(new_data = sim_dat)
#> 2. ├─generics::augment(., new_data = sim_dat)
#> 3. └─workflows:::augment.workflow(., new_data = sim_dat)
#> 4. ├─generics::augment(...)
#> 5. └─parsnip:::augment.model_fit(fit, new_data_forged, eval_time = eval_time, ...)
#> 6. └─parsnip:::augment_censored(x, new_data, eval_time = eval_time)
#> 7. └─rlang::abort(...)
Created on 2023-11-13 with reprex v2.0.2
Surfaced in https://github.com/tidymodels/extratests/pull/120. The corresponding test in extratests should be checked/updated as part of closing this.
Still can't reproduce the difference between glmnet and survival as the engines so closing this now
library(tidymodels)
library(censored)
#> Loading required package: survival
set.seed(1)
sim_dat <- prodlim::SimSurv(500) %>%
mutate(event_time = Surv(time, event)) %>%
select(event_time, X1, X2)
workflow() %>%
add_model(proportional_hazards()) %>%
add_formula(event_time ~ .) %>%
fit(data = sim_dat) %>%
augment(new_data = sim_dat)
#> Error in `augment()`:
#> ! The `eval_time` argument is missing, with no default.
workflow() %>%
add_model(proportional_hazards(penalty = 0.001) %>%
set_engine("glmnet")) %>%
add_formula(event_time ~ .) %>%
fit(data = sim_dat) %>%
augment(new_data = sim_dat)
#> Error in `augment()`:
#> ! The `eval_time` argument is missing, with no default.
Created on 2024-01-16 with reprex v2.0.2
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.
Looking at unit tests for using
augment()
on workflows for survival models and testing that it properly fails wheneval_time
is unspecified (see #200). We should get this error:When using the glmnet model, a glmnet-related error is triggered instead of the one for an improper argument call. This doesn't happen when just parsnip is used, so it is most likely a workflows issue.
Created on 2023-11-09 with reprex v2.0.2