Skip to content

Enable fit_xy() for censored regression #829

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 3 commits into from
Oct 25, 2022
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 DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: parsnip
Title: A Common API to Modeling and Analysis Functions
Version: 1.0.2.9000
Version: 1.0.2.9001
Authors@R: c(
person("Max", "Kuhn", , "[email protected]", role = c("aut", "cre")),
person("Davis", "Vaughan", , "[email protected]", role = "aut"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# parsnip (development version)

* The matrix interface for fitting `fit_xy()` now works for the `"censored regression"` mode (#829).

# parsnip 1.0.2

* A bagged neural network model was added (`bag_mlp()`). Engine implementations will live in the baguette package.
Expand Down
9 changes: 3 additions & 6 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,6 @@ fit_xy.model_spec <-
rlang::abort("Please set the mode in the model specification.")
}

if (object$mode == "censored regression") {
rlang::abort("Models for censored regression must use the formula interface.")
}

if (inherits(object, "surv_reg")) {
rlang::abort("Survival models must use the formula interface.")
}
Expand Down Expand Up @@ -408,9 +404,10 @@ check_xy_interface <- function(x, y, cl, model) {
inher(x, c("data.frame", "matrix"), cl)
}

# `y` can be a vector (which is not a class), or a factor (which is not a vector)
# `y` can be a vector (which is not a class), or a factor or
# Surv object (which are not vectors)
if (!is.null(y) && !is.vector(y))
inher(y, c("data.frame", "matrix", "factor"), cl)
inher(y, c("data.frame", "matrix", "factor", "Surv"), cl)

# rule out spark data sets that don't use the formula interface
if (inherits(x, "tbl_spark") | inherits(y, "tbl_spark"))
Expand Down
4 changes: 4 additions & 0 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ check_outcome <- function(y, spec) {
if (!all(map_lgl(y, is.factor))) {
rlang::abort("For a classification model, the outcome should be a factor.")
}
} else if (spec$mode == "censored regression") {
if (!inherits(y, "Surv")) {
rlang::abort("For a censored regression model, the outcome should be a `Surv` object.")
}
}
invisible(NULL)
}
Expand Down
9 changes: 0 additions & 9 deletions tests/testthat/test_proportional_hazards.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,3 @@ test_that("updating", {
test_that("bad input", {
expect_error(proportional_hazards(mode = ", classification"))
})

test_that("wrong fit interface", {
expect_error(
expect_message(
proportional_hazards() %>% fit_xy()
),
"must use the formula interface"
)
})
9 changes: 0 additions & 9 deletions tests/testthat/test_survival_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ test_that("updating", {
test_that("bad input", {
expect_error(survival_reg(mode = ", classification"))
})

test_that("wrong fit interface", {
expect_error(
expect_message(
survival_reg() %>% fit_xy()
),
"must use the formula interface"
)
})