Skip to content

Commit

Permalink
allow regression adjust_predictions_custom() without type (closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Dec 10, 2024
1 parent 8172622 commit 1702751
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/tailor.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ fit.tailor <- function(object, .data, outcome, estimate, probabilities = c(),
columns$estimate <- names(tidyselect::eval_select(enquo(estimate), .data))
check_selection(enquo(estimate), columns$estimate, "estimate")
columns$probabilities <- names(tidyselect::eval_select(enquo(probabilities), .data))
if (any(c("probability", "everything") %in%
purrr::map_chr(object$adjustments, purrr::pluck, "inputs"))) {
if ("probability" %in%
purrr::map_chr(object$adjustments, purrr::pluck, "inputs")) {
check_selection(enquo(probabilities), columns$probabilities, "probabilities")
for (col in columns$probabilities) {
check_variable_type(.data[[col]], "probability", "probabilities")
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-adjust-predictions-custom.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ test_that("basic adjust_predictions_custom() usage works", {
)
})

test_that("adjust_predictions_custom() for numerics works without setting type (#61)", {
library(tibble)

set.seed(1)
d_calibration <- tibble(y = rnorm(100), y_pred = y/2 + rnorm(100))
d_test <- tibble(y = rnorm(100), y_pred = y/2 + rnorm(100))

expect_no_error({
tlr <-
tailor() %>%
adjust_numeric_calibration() %>%
adjust_numeric_range(lower_limit = 2) %>%
adjust_predictions_custom(squared = y_pred^2)

tlr_fit <- fit(tlr, d_calibration, outcome = y, estimate = y_pred)
})
})

test_that("adjustment printing", {
expect_snapshot(tailor() %>% adjust_predictions_custom())
})
Expand Down

0 comments on commit 1702751

Please sign in to comment.