From 324d6147efdad61c483eeafb8e7f82e844b5d526 Mon Sep 17 00:00:00 2001 From: bcjaeger Date: Fri, 22 Nov 2024 16:33:08 -0500 Subject: [PATCH] test step size of 2 --- R/orsf_vs.R | 8 ++++++++ tests/testthat/test-orsf_vs.R | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/R/orsf_vs.R b/R/orsf_vs.R index 814dfa0f..f7551bcb 100644 --- a/R/orsf_vs.R +++ b/R/orsf_vs.R @@ -57,6 +57,14 @@ orsf_vs <- function(object, arg_name = 'n_predictor_min', bound = 1) + + check_arg_type(arg_value = n_predictor_drop, + arg_name = 'n_predictor_drop', + expected_type = 'numeric') + + check_arg_is_integer(arg_value = n_predictor_drop, + arg_name = 'n_predictor_drop') + check_arg_lt(arg_value = n_predictor_min, arg_name = 'n_predictor_min', bound = length(object$get_names_x()), diff --git a/tests/testthat/test-orsf_vs.R b/tests/testthat/test-orsf_vs.R index c1180140..aa692397 100644 --- a/tests/testthat/test-orsf_vs.R +++ b/tests/testthat/test-orsf_vs.R @@ -108,4 +108,19 @@ test_that( } ) +test_that( + desc = "variable selection with step size > 1", + code = { + + fit_cars <- orsf(mpg ~ ., data = mtcars, n_tree = n_tree_test) + + vs_size_2 <- orsf_vs(fit_cars, n_predictor_min = 1, n_predictor_drop = 2) + + # assert that we eliminated 2 predictors at each step and got down to + # 1 remaining predictor + expect_equal(vs_size_2$n_predictors, c(1,2,4,6,8,10)) + + } +) +