Closed
Description
I am trying to use the new survival_reg() function in parsnip 0.1.7. When I use this, I get an error when trying to do a fit on a workflow that uses this function. The older version surv_reg(), that is still available in 0.1.7, works as desired.
If this is a duplicate issue, then sorry about that !
# Trying to run code found in Chapter 7 Section 7.4.1 of the
# Tidy Modeling with R book (https://www.tmwr.org/workflows.html#special-model-formulas)
# Load the libraries
library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#> method from
#> required_pkgs.model_spec parsnip
library(survival)
# Create model for use with survival package:
# Use the "old" pre parsnip 0.1.6 function ----- surv_reg()
# As is done in the manual
parametric_model_Old_func <-
surv_reg() %>%
set_engine("survival")
#> Warning: `surv_reg()` was deprecated in parsnip 0.1.6.
#> Please use `survival_reg()` instead.
# Notice the warning about surv_reg() being depreciated and to use survival_reg()
# See this function being used below
# Run the output from above thru translate() function
surv_reg() %>% set_engine("survival") %>% translate()
#> Warning: `surv_reg()` was deprecated in parsnip 0.1.6.
#> Please use `survival_reg()` instead.
#> Parametric Survival Regression Model Specification (regression)
#>
#> Computational engine: survival
#>
#> Model fit template:
#> survival::survreg(formula = missing_arg(), data = missing_arg(),
#> weights = missing_arg(), model = TRUE)
# Create a workflow
parametric_workflow_Old_func <-
workflow() %>%
# Pass the data along as-is:
add_variables(outcome = c(fustat, futime), predictors = c(age, rx)) %>%
add_model(parametric_model_Old_func,
# This formula is given to the model
formula = Surv(futime, fustat) ~ age + strata(rx))
# fit the workflow
parametric_fit_Old_func <- fit(parametric_workflow_Old_func, data = ovarian)
# Take a look at the fitted model
parametric_fit_Old_func
#> ══ Workflow [trained] ══════════════════════════════════════════════════════════
#> Preprocessor: Variables
#> Model: surv_reg()
#>
#> ── Preprocessor ────────────────────────────────────────────────────────────────
#> Outcomes: c(fustat, futime)
#> Predictors: c(age, rx)
#>
#> ── Model ───────────────────────────────────────────────────────────────────────
#> Call:
#> survival::survreg(formula = Surv(futime, fustat) ~ age + strata(rx),
#> data = data, model = TRUE)
#>
#> Coefficients:
#> (Intercept) age
#> 12.8734120 -0.1033569
#>
#> Scale:
#> rx=1 rx=2
#> 0.7695509 0.4703602
#>
#> Loglik(model)= -89.4 Loglik(intercept only)= -97.1
#> Chisq= 15.36 on 1 degrees of freedom, p= 8.88e-05
#> n= 26
# Use the "new" 0.1.6 function ----- survival_reg()
parametric_model_New_func <-
survival_reg() %>%
set_engine("survival")
# Run the output from above thru translate() function
# Here the "issue" raising its head, maybe
survival_reg() %>% set_engine("survival") %>% translate()
#> Parametric Survival Regression Model Specification (censored regression)
#>
#> Computational engine: survival
#>
#> Model fit template:
#> Error: Can't create call to non-callable object
# Notice the Error above
# Create a workflow
# No error or warning when creating workflow !!!!
parametric_workflow_New_func <-
workflow() %>%
# Pass the data along as-is:
add_variables(outcome = c(fustat, futime), predictors = c(age, rx)) %>%
add_model(parametric_model_New_func,
# This formula is given to the model
formula = Surv(futime, fustat) ~ age + strata(rx))
# Fit the workflow
# Bang here
parametric_fit_New_func <- fit(parametric_workflow_New_func, data = ovarian)
#> Error: formula_ is unknown.
# Notice error above
#parametric_fit_New_func
rlang::last_error()
#> <error/rlang_error>
#> formula_ is unknown.
#> Backtrace:
#> 1. generics::fit(parametric_workflow_New_func, data = ovarian)
#> 2. workflows:::fit.workflow(parametric_workflow_New_func, data = ovarian)
#> 3. workflows::.fit_model(workflow, control)
#> 5. workflows:::fit.action_model(...)
#> 6. workflows:::fit_from_formula(spec, mold, control_parsnip, formula)
#> 8. parsnip::fit.model_spec(...)
#> Run `rlang::last_trace()` to see the full context.
rlang::last_trace()
#> <error/rlang_error>
#> formula_ is unknown.
#> Backtrace:
#> █
#> 1. ├─generics::fit(parametric_workflow_New_func, data = ovarian)
#> 2. └─workflows:::fit.workflow(parametric_workflow_New_func, data = ovarian)
#> 3. └─workflows::.fit_model(workflow, control)
#> 4. ├─generics::fit(action_model, workflow = workflow, control = control)
#> 5. └─workflows:::fit.action_model(...)
#> 6. └─workflows:::fit_from_formula(spec, mold, control_parsnip, formula)
#> 7. ├─generics::fit(spec, formula = formula, data = data, control = control_parsnip)
#> 8. └─parsnip::fit.model_spec(...)
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.1 (2021-08-10)
#> os Ubuntu 20.04.2 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/New_York
#> date 2021-08-19
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib
#> assertthat 0.2.1 2019-03-21 [2]
#> backports 1.2.1 2020-12-09 [2]
#> broom * 0.7.9 2021-07-27 [2]
#> class 7.3-19 2021-05-03 [4]
#> cli 3.0.1 2021-07-17 [2]
#> codetools 0.2-18 2020-11-04 [4]
#> colorspace 2.0-2 2021-06-24 [2]
#> crayon 1.4.1 2021-02-08 [2]
#> DBI 1.1.1 2021-01-15 [2]
#> dials * 0.0.9 2020-09-16 [2]
#> DiceDesign 1.9 2021-02-13 [2]
#> digest 0.6.27 2020-10-24 [2]
#> dplyr * 1.0.7 2021-06-18 [2]
#> ellipsis 0.3.2 2021-04-29 [2]
#> evaluate 0.14 2019-05-28 [2]
#> fansi 0.5.0 2021-05-25 [2]
#> foreach 1.5.1 2020-10-15 [2]
#> fs 1.5.0 2020-07-31 [2]
#> furrr 0.2.3 2021-06-25 [2]
#> future 1.21.0 2020-12-10 [2]
#> generics 0.1.0 2020-10-31 [2]
#> ggplot2 * 3.3.5 2021-06-25 [2]
#> globals 0.14.0 2020-11-22 [2]
#> glue 1.4.2 2020-08-27 [2]
#> gower 0.2.2 2020-06-23 [2]
#> GPfit 1.0-8 2019-02-08 [2]
#> gtable 0.3.0 2019-03-25 [2]
#> hardhat 0.1.6 2021-07-14 [2]
#> highr 0.9 2021-04-16 [2]
#> htmltools 0.5.1.1 2021-01-22 [2]
#> infer * 0.5.4 2021-01-13 [2]
#> ipred 0.9-11 2021-03-12 [2]
#> iterators 1.0.13 2020-10-15 [2]
#> knitr 1.33 2021-04-24 [2]
#> lattice 0.20-44 2021-05-02 [4]
#> lava 1.6.9 2021-03-11 [2]
#> lhs 1.1.1 2020-10-05 [2]
#> lifecycle 1.0.0 2021-02-15 [2]
#> listenv 0.8.0 2019-12-05 [2]
#> lubridate 1.7.10 2021-02-26 [2]
#> magrittr 2.0.1 2020-11-17 [2]
#> MASS 7.3-54 2021-05-03 [4]
#> Matrix 1.3-4 2021-06-01 [4]
#> modeldata * 0.1.1 2021-07-14 [2]
#> munsell 0.5.0 2018-06-12 [2]
#> nnet 7.3-16 2021-05-03 [4]
#> parallelly 1.27.0 2021-07-19 [2]
#> parsnip * 0.1.7 2021-07-21 [2]
#> pillar 1.6.2 2021-07-29 [2]
#> pkgconfig 2.0.3 2019-09-22 [2]
#> plyr 1.8.6 2020-03-03 [2]
#> pROC 1.17.0.1 2021-01-13 [2]
#> prodlim 2019.11.13 2019-11-17 [2]
#> purrr * 0.3.4 2020-04-17 [2]
#> R6 2.5.0 2020-10-28 [2]
#> Rcpp 1.0.7 2021-07-07 [2]
#> recipes * 0.1.16 2021-04-16 [2]
#> reprex 2.0.0 2021-04-02 [2]
#> rlang 0.4.11 2021-04-30 [2]
#> rmarkdown 2.9 2021-06-15 [2]
#> rpart 4.1-15 2019-04-12 [4]
#> rsample * 0.1.0 2021-05-08 [2]
#> rstudioapi 0.13 2020-11-12 [2]
#> scales * 1.1.1 2020-05-11 [2]
#> sessioninfo 1.1.1 2018-11-05 [2]
#> stringi 1.6.2 2021-05-17 [2]
#> stringr 1.4.0 2019-02-10 [2]
#> survival * 3.2-11 2021-04-26 [4]
#> tibble * 3.1.3 2021-07-23 [2]
#> tidymodels * 0.1.3 2021-04-19 [2]
#> tidyr * 1.1.3 2021-03-03 [2]
#> tidyselect 1.1.1 2021-04-30 [2]
#> timeDate 3043.102 2018-02-21 [2]
#> tune * 0.1.6 2021-07-21 [2]
#> utf8 1.2.2 2021-07-24 [2]
#> vctrs 0.3.8 2021-04-29 [2]
#> withr 2.4.2 2021-04-18 [2]
#> workflows * 0.2.3 2021-07-16 [2]
#> workflowsets * 0.1.0.9000 2021-08-15 [2]
#> xfun 0.24 2021-06-15 [2]
#> yaml 2.2.1 2020-02-01 [2]
#> yardstick * 0.0.8 2021-03-28 [2]
#> source
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#> CRAN (R 4.0.5)
#> CRAN (R 4.1.1)
#> CRAN (R 4.0.3)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.0.5)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.0)
#> CRAN (R 4.0.5)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.0.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.0.5)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.1)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#> Github (tidymodels/workflowsets@57006c0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.0)
#> CRAN (R 4.1.1)
#>
#> [1] /home/dave/R/x86_64-pc-linux-gnu-library/4.1
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
Created on 2021-08-19 by the reprex package (v2.0.0)
Metadata
Metadata
Assignees
Labels
No labels