Skip to content

Commit

Permalink
assign population if existing and added a test
Browse files Browse the repository at this point in the history
  • Loading branch information
egillax committed Jan 29, 2024
1 parent f212580 commit 118cc7c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/RunPlp.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ runPlp <- function(
# create the population
if(!is.null(plpData$population)) {
ParallelLogger::logInfo('Using existing population')
population <- plpData$population
} else {
ParallelLogger::logInfo('Creating population')
population <- tryCatch({
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-population.R
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,31 @@ test_that("population creation parameters", {

})

testthat::test_that("Providing an existing population and skipping population creation works", {
popSize <- 400
newPopulation <- population[sample.int(nrow.default(population), popSize), ]

tinyPlpData$population <- newPopulation

plpResults <- runPlp(
plpData = tinyPlpData,
outcomeId = 2,
analysisId = "1",
analysisName = "existing population",
populationSettings = createStudyPopulationSettings(),
splitSettings = createDefaultSplitSetting(),
modelSettings = setLassoLogisticRegression(),
executeSettings = createExecuteSettings(
runSplitData = TRUE,
runPreprocessData = FALSE,
runModelDevelopment = TRUE
)
)

trainPredictions <- plpResults$prediction %>%
dplyr::filter(.data$evaluationType == "Train") %>% nrow.default()
testPredictions <- plpResults$prediction %>%
dplyr::filter(.data$evaluationType == "Test") %>% nrow.default()
expect_equal(popSize, trainPredictions + testPredictions)
})

0 comments on commit 118cc7c

Please sign in to comment.