Skip to content
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
Expand Up @@ -25,7 +25,7 @@ Imports:
dplyr (>= 1.1.0),
furrr,
generics (>= 0.1.3),
ggplot2,
ggplot2 (>= 3.5.2),
hardhat,
pillar,
purrr,
Expand Down
53 changes: 53 additions & 0 deletions tests/testthat/_snaps/cal-estimate.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@
`.pred_class_1` ==> class_1
`.pred_class_2` ==> class_2

# Logistic spline switches to linear if too few unique

Code
sl_gam <- cal_estimate_logistic(segment_logistic, Class, smooth = TRUE)
Condition
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.

---

Code
sl_gam <- cal_estimate_logistic(segment_logistic, Class, .by = id, smooth = TRUE)
Condition
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.

# Isotonic estimates work - data.frame

Code
Expand Down Expand Up @@ -523,6 +541,41 @@
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.

---

Code
sl_gam <- cal_estimate_linear(boosting_predictions_oob, outcome, smooth = TRUE)
Condition
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.

---

Code
sl_gam <- cal_estimate_linear(boosting_predictions_oob, outcome, .by = id,
smooth = TRUE)
Condition
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.
Warning:
Too few unique observations for spline-based calibrator. Setting `smooth = FALSE`.

# Multinomial spline switches to linear if too few unique

Code
Expand Down
243 changes: 243 additions & 0 deletions tests/testthat/_snaps/cal-plot.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
# Binary breaks functions work with group argument

Code
get_labs(res)
Output
$colour
[1] "id"

$fill
[1] "id"

$x.sec
NULL

$x
[1] "Bin Midpoint"

$y
[1] "Event Rate"

$y.sec
NULL

$intercept
[1] "intercept"

$slope
[1] "slope"

$ymin
[1] "lower"

$ymax
[1] "upper"

$alt
[1] ""


---

x `.by` cannot select more than one column.
i The following 2 columns were selected:
i group1 and group2
Expand All @@ -11,6 +50,45 @@

# Binary logistic functions work with group argument

Code
get_labs(res)
Output
$colour
[1] "id"

$fill
[1] "id"

$x.sec
NULL

$x
[1] "Probability"

$y
[1] "Predicted Event Rate"

$y.sec
NULL

$intercept
[1] "intercept"

$slope
[1] "slope"

$ymin
[1] "lower"

$ymax
[1] "upper"

$alt
[1] ""


---

x `.by` cannot select more than one column.
i The following 2 columns were selected:
i group1 and group2
Expand All @@ -33,6 +111,171 @@
Caused by error:
! Invalid `event_level` entry: invalid. Valid entries are "first", "second", or "auto".

# regression functions work

Code
get_labs(res)
Output
$x.sec
NULL

$x
[1] "Observed"

$y
[1] "Predicted"

$y.sec
NULL

$intercept
[1] "intercept"

$slope
[1] "slope"

$colour
[1] "colour"

$fill
[1] "fill"

$alt
[1] ""


---

Code
get_labs(res)
Output
$x.sec
NULL

$x
[1] "Observed"

$y
[1] "Predicted"

$y.sec
NULL

$intercept
[1] "intercept"

$slope
[1] "slope"

$colour
[1] "colour"

$fill
[1] "fill"

$alt
[1] ""


---

Code
get_labs(res)
Output
$x.sec
NULL

$x
[1] "Observed"

$y
[1] "Predicted"

$y.sec
NULL

$intercept
[1] "intercept"

$slope
[1] "slope"

$colour
[1] "colour"

$fill
[1] "fill"

$alt
[1] ""


---

Code
get_labs(res)
Output
$x.sec
NULL

$x
[1] "Observed"

$y
[1] "Predicted"

$y.sec
NULL

$intercept
[1] "intercept"

$slope
[1] "slope"

$colour
[1] "colour"

$fill
[1] "fill"

$alt
[1] ""


---

Code
get_labs(res)
Output
$x.sec
NULL

$x
[1] "Observed"

$y
[1] "Predicted"

$y.sec
NULL

$intercept
[1] "intercept"

$slope
[1] "slope"

$colour
[1] "colour"

$fill
[1] "fill"

$alt
[1] ""


# regression plot function errors - grouped_df

x This function does not work with grouped data frames.
Expand Down
18 changes: 8 additions & 10 deletions tests/testthat/test-cal-estimate.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ test_that("Logistic spline estimates work - tune_results", {

test_that("Logistic spline switches to linear if too few unique", {
skip_if_not_installed("modeldata")
skip("until refactored")

segment_logistic$.pred_good <- rep(
x = 1,
Expand All @@ -134,8 +133,8 @@ test_that("Logistic spline switches to linear if too few unique", {
sl_lm <- cal_estimate_logistic(segment_logistic, Class, smooth = FALSE)

expect_identical(
sl_gam,
sl_lm
sl_gam$estimates[[1]]$estimate[[1]],
sl_lm$estimates[[1]]$estimate[[1]]
)

segment_logistic$id <- rep(
Expand All @@ -148,8 +147,8 @@ test_that("Logistic spline switches to linear if too few unique", {
sl_lm <- cal_estimate_logistic(segment_logistic, Class, .by = id, smooth = FALSE)

expect_identical(
sl_gam,
sl_lm
sl_gam$estimates[[1]]$estimate[[1]],
sl_lm$estimates[[1]]$estimate[[1]]
)
})

Expand Down Expand Up @@ -619,7 +618,6 @@ test_that("Linear spline estimates work - tune_results", {

test_that("Linear spline switches to linear if too few unique", {
skip_if_not_installed("modeldata")
skip("until refactored")

boosting_predictions_oob$.pred <- rep(
x = 1:5,
Expand All @@ -632,8 +630,8 @@ test_that("Linear spline switches to linear if too few unique", {
sl_lm <- cal_estimate_linear(boosting_predictions_oob, outcome, smooth = FALSE)

expect_identical(
sl_gam,
sl_lm
sl_gam$estimates[[1]]$estimate[[1]],
sl_lm$estimates[[1]]$estimate[[1]]
)

expect_snapshot(
Expand All @@ -642,8 +640,8 @@ test_that("Linear spline switches to linear if too few unique", {
sl_lm <- cal_estimate_linear(boosting_predictions_oob, outcome, .by = id, smooth = FALSE)

expect_identical(
sl_gam,
sl_lm
sl_gam$estimates[[1]]$estimate[[1]],
sl_lm$estimates[[1]]$estimate[[1]]
)
})

Expand Down
Loading
Loading