Skip to content

Soft-deprecate surv_reg() #454

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

Merged
merged 7 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

* A new linear SVM model `svm_linear()` is now available with the `LiblineaR` engine (#424) and the `kernlab` engine (#438), and the `LiblineaR` engine is available for `logistic_reg()` as well (#429). These models can use sparse matrices via `fit_xy()` (#447).

* New model specification `survival_reg()` for the new mode `"censored regression"`. (#444)
* New model specification `survival_reg()` for the new mode `"censored regression"` (#444). `surv_reg()` is now soft-deprecated (#448).

# parsnip 0.1.5

Expand Down
16 changes: 16 additions & 0 deletions R/surv_reg.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#' General Interface for Parametric Survival Models
#'
#' @description
#' `r lifecycle::badge("deprecated")`
#'
#' This function is soft-deprecated in favor of `survival_reg()` which uses the
#' `"censored regression"` mode.
#'
#' `surv_reg()` is a way to generate a _specification_ of a model
#' before fitting and allows the model to be created using
#' R. The main argument for the
Expand Down Expand Up @@ -51,9 +57,19 @@
#' # Parameters can be represented by a placeholder:
#' surv_reg(dist = varying())
#'
#' # ->
#' show_engines("survival_reg")
#'
#' survival_reg()
#' # Parameters can be represented by a placeholder:
#' survival_reg(dist = varying())
#'
#' @keywords internal
#' @export
surv_reg <- function(mode = "regression", dist = NULL) {

lifecycle::deprecate_soft("0.1.6", "surv_reg()", "survival_reg()")

args <- list(
dist = enquo(dist)
)
Expand Down
1 change: 1 addition & 0 deletions man/figures/lifecycle-archived.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions man/figures/lifecycle-defunct.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions man/figures/lifecycle-deprecated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions man/figures/lifecycle-experimental.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions man/figures/lifecycle-maturing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions man/figures/lifecycle-questioning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions man/figures/lifecycle-stable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions man/figures/lifecycle-superseded.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 25 additions & 6 deletions man/surv_reg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/testthat/test_surv_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ source("helpers.R")
# ------------------------------------------------------------------------------

test_that('primary arguments', {
rlang::local_options(lifecycle_verbosity = "quiet")

basic <- surv_reg()
basic_flexsurv <- translate(basic %>% set_engine("flexsurv"))

Expand Down Expand Up @@ -46,6 +48,8 @@ test_that('primary arguments', {
})

test_that('engine arguments', {
rlang::local_options(lifecycle_verbosity = "quiet")

fs_cl <- surv_reg()
expect_equal(translate(fs_cl %>% set_engine("flexsurv", cl = .99))$method$fit$args,
list(
Expand All @@ -60,6 +64,8 @@ test_that('engine arguments', {


test_that('updating', {
rlang::local_options(lifecycle_verbosity = "quiet")

expr1 <- surv_reg() %>% set_engine("flexsurv", cl = varying())
expr1_exp <- surv_reg(dist = "lnorm") %>% set_engine("flexsurv", cl = .99)
expect_equal(update(expr1, dist = "lnorm", cl = 0.99), expr1_exp)
Expand All @@ -75,7 +81,14 @@ test_that('updating', {
})

test_that('bad input', {
rlang::local_options(lifecycle_verbosity = "quiet")

expect_error(surv_reg(mode = ", classification"))
expect_error(translate(surv_reg() %>% set_engine("wat")))
expect_error(translate(surv_reg() %>% set_engine(NULL)))
})

test_that("deprecation warning", {
rlang::local_options(lifecycle_verbosity = "warning")
expect_warning(surv_reg())
})
9 changes: 6 additions & 3 deletions tests/testthat/test_surv_reg_flexsurv.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ library(tibble)

source(test_path("helper-objects.R"))


basic_form <- Surv(time, status) ~ age
complete_form <- Surv(time) ~ age

surv_basic <- surv_reg() %>% set_engine("flexsurv")

# ------------------------------------------------------------------------------

test_that('flexsurv execution', {
skip_if_not_installed("flexsurv")

rlang::local_options(lifecycle_verbosity = "quiet")
surv_basic <- surv_reg() %>% set_engine("flexsurv")

expect_error(
res <- fit(
surv_basic,
Expand Down Expand Up @@ -53,6 +53,9 @@ test_that('flexsurv execution', {
test_that('flexsurv prediction', {
skip_if_not_installed("flexsurv")

rlang::local_options(lifecycle_verbosity = "quiet")
surv_basic <- surv_reg() %>% set_engine("flexsurv")

res <- fit(
surv_basic,
Surv(time, status) ~ age,
Expand Down
12 changes: 8 additions & 4 deletions tests/testthat/test_surv_reg_survreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ source(test_path("helper-objects.R"))
basic_form <- Surv(time, status) ~ group
complete_form <- Surv(time) ~ group

surv_basic <- surv_reg() %>% set_engine("survival")
surv_lnorm <- surv_reg(dist = "lognormal") %>% set_engine("survival")

# ------------------------------------------------------------------------------

test_that('survival execution', {

skip_on_travis()

rlang::local_options(lifecycle_verbosity = "quiet")
surv_basic <- surv_reg() %>% set_engine("survival")
surv_lnorm <- surv_reg(dist = "lognormal") %>% set_engine("survival")

expect_error(
res <- fit(
surv_basic,
Expand Down Expand Up @@ -51,6 +51,10 @@ test_that('survival execution', {
test_that('survival prediction', {
skip_on_travis()

rlang::local_options(lifecycle_verbosity = "quiet")
surv_basic <- surv_reg() %>% set_engine("survival")
surv_lnorm <- surv_reg(dist = "lognormal") %>% set_engine("survival")

res <- fit(
surv_basic,
Surv(time, status) ~ age + sex,
Expand Down