From a7b07621affdaf2e23f8055225de4365ac78bc30 Mon Sep 17 00:00:00 2001 From: bjaeger Date: Thu, 5 Oct 2023 00:16:10 -0400 Subject: [PATCH] smoothing the new tests --- man/orsf.Rd | 18 ++++++------------ tests/testthat/test-leaf_kaplan.R | 6 ++++-- tests/testthat/test-orsf_formula.R | 6 +++--- tests/testthat/test-orsf_vi.R | 2 ++ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/man/orsf.Rd b/man/orsf.Rd index 67b98670..fe59b988 100644 --- a/man/orsf.Rd +++ b/man/orsf.Rd @@ -383,8 +383,7 @@ function to find linear combinations of predictors. \if{html}{\out{
}}\preformatted{fit_accel <- orsf(pbc_orsf, control = orsf_control_fast(), - formula = Surv(time, status) ~ . - id, - tree_seeds = 1:500) + formula = Surv(time, status) ~ . - id) }\if{html}{\out{
}} } @@ -396,8 +395,7 @@ combinations of predictors: \if{html}{\out{
}}\preformatted{fit_cph <- orsf(pbc_orsf, control = orsf_control_cph(), - formula = Surv(time, status) ~ . - id, - tree_seeds = 1:500) + formula = Surv(time, status) ~ . - id) }\if{html}{\out{
}} } @@ -413,8 +411,7 @@ than the other options. # select 3 predictors out of 5 to be used in # each linear combination of predictors. control = orsf_control_net(df_target = 3), - formula = Surv(time, status) ~ . - id, - tree_seeds = 1:500) + formula = Surv(time, status) ~ . - id) }\if{html}{\out{}} } @@ -475,17 +472,14 @@ the result into \code{orsf()}: \if{html}{\out{
}}\preformatted{fit_rando <- orsf(pbc_orsf, Surv(time, status) ~ . - id, - control = orsf_control_custom(beta_fun = f_rando), - tree_seeds = 1:500) + control = orsf_control_custom(beta_fun = f_rando)) fit_pca <- orsf(pbc_orsf, Surv(time, status) ~ . - id, - control = orsf_control_custom(beta_fun = f_pca), - tree_seeds = 1:500) + control = orsf_control_custom(beta_fun = f_pca)) fit_rlt <- orsf(pbc_orsf, time + status ~ . - id, - control = orsf_control_custom(beta_fun = f_aorsf), - tree_seeds = 1:500) + control = orsf_control_custom(beta_fun = f_aorsf)) }\if{html}{\out{
}} So which fit seems to work best in this example? Let’s find out by diff --git a/tests/testthat/test-leaf_kaplan.R b/tests/testthat/test-leaf_kaplan.R index d9ccd61b..f9156c47 100644 --- a/tests/testthat/test-leaf_kaplan.R +++ b/tests/testthat/test-leaf_kaplan.R @@ -6,11 +6,13 @@ #' @srrstats {G5.5} *Correctness tests are run with a fixed random seed* set.seed(329) +flc <- flc[flc$status==1, ] + weights <- sample(1:5, nrow(flc), replace = TRUE) # fit a normal tree with no bootstrap weights fit <- orsf(flc, - futime + death ~ ., + time + status ~ ., n_tree = 1, weights = weights, tree_seeds = 1, @@ -27,7 +29,7 @@ fit <- orsf(flc, aorsf_surv <- fit$forest$leaf_pred_prob[[1]][[1]] aorsf_time <- fit$forest$leaf_pred_indx[[1]][[1]] -kap <- survfit(Surv(futime, death) ~ 1, data = flc, weights = weights) +kap <- survfit(Surv(time, status) ~ 1, data = flc, weights = weights) test_that( desc = 'aorsf kaplan has same time values as survfit', diff --git a/tests/testthat/test-orsf_formula.R b/tests/testthat/test-orsf_formula.R index ac48a3c7..cccb2ec8 100644 --- a/tests/testthat/test-orsf_formula.R +++ b/tests/testthat/test-orsf_formula.R @@ -68,7 +68,7 @@ test_that( # keeps unique names expect_equal(x_vars, get_names_x(fit_long)) # is the same forest as standard - expect_equal_leaf_summary(fit_long, fit_standard) + expect_equal_leaf_summary(fit_long, fit_standard_pbc) } ) @@ -95,7 +95,7 @@ test_that( ) # different formula but same as standard forest - expect_equal_leaf_summary(fit_surv, fit_standard) + expect_equal_leaf_summary(fit_surv, fit_standard_pbc) } ) @@ -111,7 +111,7 @@ test_that( n_tree = 10, tree_seeds = seeds_standard) - expect_equal_leaf_summary(fit_status_modified, fit_standard) + expect_equal_leaf_summary(fit_status_modified, fit_standard_pbc) expect_error( orsf(pbc_orsf, Surv(status, time) ~ . - id), diff --git a/tests/testthat/test-orsf_vi.R b/tests/testthat/test-orsf_vi.R index 56517df8..e66026b6 100644 --- a/tests/testthat/test-orsf_vi.R +++ b/tests/testthat/test-orsf_vi.R @@ -140,6 +140,8 @@ test_that( desc = 'informative errors for custom functions', code = { + fit_no_vi <- orsf(pbc_vi, formula, importance = 'none', n_tree = 1) + expect_error( orsf_vi_anova(object = 'nope'), regexp = 'inherit'