Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
hfrick committed Mar 22, 2023
1 parent 14491d8 commit 2411e10
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion R/censored-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ NULL

utils::globalVariables(
c(
"time", ".time", "object", "new_data", ".label", ".pred", ".cuts",
"eval_time", ".time", "object", "new_data", ".label", ".pred", ".cuts",
".id", ".tmp", "engine", "predictor_indicators", ".strata", "group",
".pred_quantile", ".quantile", "interval", "level", ".pred_linear_pred",
".pred_link", ".pred_time", ".pred_survival", "next_event_time",
Expand Down
2 changes: 1 addition & 1 deletion R/proportional_hazards-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ make_proportional_hazards_survival <- function() {
list(
x = quote(object$fit),
new_data = quote(new_data),
time = rlang::expr(eval_time),
eval_time = rlang::expr(eval_time),
output = "surv",
interval = expr(interval),
conf.int = expr(level)
Expand Down
40 changes: 20 additions & 20 deletions tests/testthat/test-partykit.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ test_that("survival_prob_partykit() works for ctree", {
times = pred_time,
extend = TRUE
) %>%
combine_list_of_survfit_summary(time = pred_time)
combine_list_of_survfit_summary(eval_time = pred_time)

prob <- survival_prob_partykit(mod, new_data = lung_pred, time = pred_time) %>%
prob <- survival_prob_partykit(mod, new_data = lung_pred, eval_time = pred_time) %>%
tidyr::unnest(cols = .pred)
exp_prob <- surv_fit_summary$surv

expect_equal(
prob$.time,
prob$.eval_time,
rep(pred_time, nrow(lung_pred))
)
expect_equal(
prob %>% dplyr::filter(is.infinite(.time)) %>% dplyr::pull(.pred_survival),
prob %>% dplyr::filter(is.infinite(.eval_time)) %>% dplyr::pull(.pred_survival),
rep(c(1, 0), nrow(lung_pred))
)
expect_equal(
prob %>% dplyr::filter(is.finite(.time)) %>% dplyr::pull(.pred_survival),
prob %>% dplyr::filter(is.finite(.eval_time)) %>% dplyr::pull(.pred_survival),
as.vector(exp_prob)
)

Expand All @@ -44,25 +44,25 @@ test_that("survival_prob_partykit() works for ctree", {
times = pred_time,
extend = TRUE
) %>%
combine_list_of_survfit_summary(time = pred_time)
combine_list_of_survfit_summary(eval_time = pred_time)

prob <- survival_prob_partykit(mod, new_data = lung_pred, time = pred_time) %>%
prob <- survival_prob_partykit(mod, new_data = lung_pred, eval_time = pred_time) %>%
tidyr::unnest(cols = .pred)
exp_prob <- surv_fit_summary$surv

expect_equal(
prob %>% dplyr::filter(is.infinite(.time)) %>% dplyr::pull(.pred_survival),
prob %>% dplyr::filter(is.infinite(.eval_time)) %>% dplyr::pull(.pred_survival),
c(1, 0)
)
expect_equal(
prob %>% dplyr::filter(is.finite(.time)) %>% dplyr::pull(.pred_survival),
prob %>% dplyr::filter(is.finite(.eval_time)) %>% dplyr::pull(.pred_survival),
as.vector(exp_prob)
)

# all observations with missings
lung_pred <- lung[c(14, 14), ]

prob <- survival_prob_partykit(mod, new_data = lung_pred, time = pred_time) %>%
prob <- survival_prob_partykit(mod, new_data = lung_pred, eval_time = pred_time) %>%
tidyr::unnest(cols = .pred)

expect_true(all(!is.na(prob$.pred_survival)))
Expand All @@ -87,23 +87,23 @@ test_that("survival_prob_partykit() works for cforest", {
times = pred_time,
extend = TRUE
) %>%
combine_list_of_survfit_summary(time = pred_time)
combine_list_of_survfit_summary(eval_time = pred_time)

set.seed(1234)
prob <- survival_prob_partykit(mod, new_data = lung_pred, time = pred_time) %>%
prob <- survival_prob_partykit(mod, new_data = lung_pred, eval_time = pred_time) %>%
tidyr::unnest(cols = .pred)
exp_prob <- surv_fit_summary$surv

expect_equal(
prob$.time,
prob$.eval_time,
rep(pred_time, nrow(lung_pred))
)
expect_equal(
prob %>% dplyr::filter(is.infinite(.time)) %>% dplyr::pull(.pred_survival),
prob %>% dplyr::filter(is.infinite(.eval_time)) %>% dplyr::pull(.pred_survival),
rep(c(1, 0), nrow(lung_pred))
)
expect_equal(
prob %>% dplyr::filter(is.finite(.time)) %>% dplyr::pull(.pred_survival),
prob %>% dplyr::filter(is.finite(.eval_time)) %>% dplyr::pull(.pred_survival),
as.vector(exp_prob)
)

Expand All @@ -117,26 +117,26 @@ test_that("survival_prob_partykit() works for cforest", {
times = pred_time,
extend = TRUE
) %>%
combine_list_of_survfit_summary(time = pred_time)
combine_list_of_survfit_summary(eval_time = pred_time)

set.seed(1234)
prob <- survival_prob_partykit(mod, new_data = lung_pred, time = pred_time) %>%
prob <- survival_prob_partykit(mod, new_data = lung_pred, eval_time = pred_time) %>%
tidyr::unnest(cols = .pred)
exp_prob <- surv_fit_summary$surv

expect_equal(
prob %>% dplyr::filter(is.infinite(.time)) %>% dplyr::pull(.pred_survival),
prob %>% dplyr::filter(is.infinite(.eval_time)) %>% dplyr::pull(.pred_survival),
c(1, 0)
)
expect_equal(
prob %>% dplyr::filter(is.finite(.time)) %>% dplyr::pull(.pred_survival),
prob %>% dplyr::filter(is.finite(.eval_time)) %>% dplyr::pull(.pred_survival),
as.vector(exp_prob)
)

# all observations with missings
lung_pred <- lung[c(14, 14), ]

prob <- survival_prob_partykit(mod, new_data = lung_pred, time = pred_time) %>%
prob <- survival_prob_partykit(mod, new_data = lung_pred, eval_time = pred_time) %>%
tidyr::unnest(cols = .pred)

expect_true(all(!is.na(prob$.pred_survival)))
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-proportional_hazards-survival.R
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ test_that("predictions with strata and dot in formula", {
{
predict(f_fit, lung2, type = "time")
predict(f_fit, lung2, type = "linear_pred")
predict(f_fit, lung2, type = "survival", time = c(100, 300))
predict(f_fit, lung2, type = "survival", eval_time = c(100, 300))
},
NA
)
Expand All @@ -542,8 +542,8 @@ test_that("predictions with strata and dot in formula", {
predict(f_fit_2, lung2, type = "linear_pred")
)
expect_equal(
predict(f_fit, lung2, type = "survival", time = c(100, 300)),
predict(f_fit_2, lung2, type = "survival", time = c(100, 300))
predict(f_fit, lung2, type = "survival", eval_time = c(100, 300)),
predict(f_fit_2, lung2, type = "survival", eval_time = c(100, 300))
)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-survival_reg-survival.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ test_that("`fix_xy()` works", {
f_fit,
new_data = lung_pred,
type = "hazard",
time = c(100, 200)
eval_time = c(100, 200)
)
xy_pred_hazard <- predict(
xy_fit,
Expand Down

0 comments on commit 2411e10

Please sign in to comment.