Skip to content

Commit 0f406df

Browse files
committed
Merge branch 'quosure-passthrough-tests' of https://github.com/topepo/parsnip into quosure-passthrough-tests
2 parents 1909b5d + c38a630 commit 0f406df

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

tests/testthat/test_surv_reg_flexsurv.R

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ ctrl <- fit_control(verbosity = 1, catch = FALSE)
1313
caught_ctrl <- fit_control(verbosity = 1, catch = TRUE)
1414
quiet_ctrl <- fit_control(verbosity = 0, catch = TRUE)
1515

16+
# ------------------------------------------------------------------------------
17+
1618
test_that('flexsurv execution', {
1719
skip_if_not_installed("flexsurv")
18-
20+
1921
library(flexsurv)
2022
data(bc)
21-
23+
2224
set.seed(4566)
2325
bc$group2 <- bc$group
24-
26+
2527
expect_error(
2628
res <- fit(
2729
surv_basic,
@@ -52,3 +54,25 @@ test_that('flexsurv execution', {
5254
)
5355
)
5456
})
57+
58+
test_that('flexsurv prediction', {
59+
skip_if_not_installed("flexsurv")
60+
61+
library(flexsurv)
62+
data(bc)
63+
64+
set.seed(4566)
65+
bc$group2 <- bc$group
66+
67+
res <- fit(
68+
surv_basic,
69+
Surv(recyrs, censrec) ~ group,
70+
data = bc,
71+
control = ctrl,
72+
engine = "flexsurv"
73+
)
74+
exp_pred <- summary(res$fit, head(bc), type = "mean")
75+
exp_pred <- do.call("rbind", unclass(exp_pred))
76+
exp_pred <- tibble(.pred = exp_pred$est)
77+
expect_equal(exp_pred, predict(res, head(bc)))
78+
})

tests/testthat/test_surv_reg_survreg.R

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
library(testthat)
22
library(parsnip)
3-
library(rlang)
43
library(survival)
4+
library(tibble)
55

66
# ------------------------------------------------------------------------------
77

@@ -15,6 +15,8 @@ ctrl <- fit_control(verbosity = 1, catch = FALSE)
1515
caught_ctrl <- fit_control(verbosity = 1, catch = TRUE)
1616
quiet_ctrl <- fit_control(verbosity = 0, catch = TRUE)
1717

18+
# ------------------------------------------------------------------------------
19+
1820
test_that('survival execution', {
1921

2022
expect_error(
@@ -47,3 +49,29 @@ test_that('survival execution', {
4749
)
4850
)
4951
})
52+
53+
test_that('survival prediction', {
54+
55+
res <- fit(
56+
surv_basic,
57+
Surv(time, status) ~ age + sex,
58+
data = lung,
59+
control = ctrl,
60+
engine = "survreg"
61+
)
62+
exp_pred <- predict(res$fit, head(lung))
63+
exp_pred <- tibble(.pred = unname(exp_pred))
64+
expect_equal(exp_pred, predict(res, head(lung)))
65+
66+
exp_quant <- predict(res$fit, head(lung), p = (2:4)/5, type = "quantile")
67+
exp_quant <-
68+
apply(exp_quant, 1, function(x)
69+
tibble(.pred = x, .quantile = (2:4) / 5))
70+
exp_quant <- tibble(.pred = exp_quant)
71+
obs_quant <- predict(res, head(lung), type = "quantile", quantile = (2:4)/5)
72+
73+
expect_equal(as.data.frame(exp_quant), as.data.frame(obs_quant))
74+
75+
})
76+
77+

0 commit comments

Comments
 (0)