diff --git a/DESCRIPTION b/DESCRIPTION index 2067cdd..e7798ec 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,7 +17,8 @@ Suggests: testthat (>= 3.0.0), withr (>= 2.5.2), tibble (>= 3.0.0), - zeroSum (>= 2.0.6) + zeroSum (>= 2.0.6), + glmnet(>= 4.1.8) Imports: dplyr (>= 1.1.3), readr (>= 2.1.4), diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 2e05f5a..d3b784d 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -48,7 +48,7 @@ generate_mock_data <- function( ){ # expression matrix expr_mat <- matrix( - sample(1:100, n_samples*n_genes, replace = TRUE), + sample(1:10, n_samples*n_genes, replace = TRUE), nrow = n_samples ) |> log() rownames(expr_mat) <- stringr::str_c("sample_", 1:n_samples) @@ -60,9 +60,10 @@ generate_mock_data <- function( pheno_tbl <- tibble::tibble(.rows = n_samples) pheno_tbl[["patient_id"]] <- rownames(expr_mat) pheno_tbl[["progression"]] <- sample( - c(0, 1), + 0:1, size = n_samples, - replace = TRUE + replace = TRUE, + prob = c(.3, .7) ) pheno_tbl[["pfs_years"]] <- runif(n_samples, 0, 4) pheno_tbl[["discrete_var"]] <- sample(1:3, size = n_samples, replace = TRUE) diff --git a/tests/testthat/test-assess_model.R b/tests/testthat/test-assess_model.R index 98aaa7c..93d0b0e 100644 --- a/tests/testthat/test-assess_model.R +++ b/tests/testthat/test-assess_model.R @@ -1,15 +1,15 @@ test_that("assess_model() works", { - set.seed(134) - n <- 10 + set.seed(132) + n <- 50 dir <- withr::local_tempdir() - n_fold <- 1 + n_fold <- 3 lambda <- 1 data <- generate_mock_data( n_samples = n, n_genes = 5, - n_na_in_pheno = 3 + n_na_in_pheno = 1 ) expr_mat <- data[["expr_mat"]] pheno_tbl <- data[["pheno_tbl"]] @@ -20,14 +20,16 @@ test_that("assess_model() works", { model_spec_1 <- ModelSpec( name = "cox-zerosum", fitter = zeroSum::zeroSum, - optional_fitter_args = list(family = "cox", alpha = 1, nFold = n_fold, lambda = lambda), + optional_fitter_args = list(family = "cox", alpha = 1, nFold = n_fold, + lambda = lambda, zeroSum = FALSE), response_type = "survival_censored", base_dir = dir ) model_spec_2 <- ModelSpec( - name = "cox-lasso", - fitter = zeroSum::zeroSum, - optional_fitter_args = list(family = "binomial", alpha = 1, nFold = n_fold, lambda = lambda), + name = "logistic-lasso", + fitter = glmnet::cv.glmnet, + optional_fitter_args = list(family = "binomial", alpha = 1, + nfolds = n_fold, lambda = c(lambda, 2)), response_type = "binary", base_dir = dir ) diff --git a/tests/testthat/test-assess_multiple_models.R b/tests/testthat/test-assess_multiple_models.R index 47f3116..b43683f 100644 --- a/tests/testthat/test-assess_multiple_models.R +++ b/tests/testthat/test-assess_multiple_models.R @@ -58,7 +58,7 @@ test_that("assess_multiple_models() works", { fname = file.path(res_dir, "perf_plot.pdf"), x_metric = "rpp", y_metric = "prec", - show_plots = TRUE + show_plots = FALSE ) expect_no_error(