Skip to content

Commit

Permalink
Study population improvements (#424)
Browse files Browse the repository at this point in the history
* filter before join

* filter cohort if existing population
  • Loading branch information
egillax authored Dec 21, 2023
1 parent 3623b52 commit 988221c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions R/PopulationSettings.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ createStudyPopulation <- function(

if (is.null(population)) {
population <- plpData$cohorts
} else {
population <- plpData$cohorts %>%
dplyr::filter(.data$rowId %in% (population %>% dplyr::pull(.data$rowId)))
}

# save the metadata (should have the ?targetId, outcomeId, plpDataSettings and population settings)
Expand Down Expand Up @@ -259,9 +262,9 @@ createStudyPopulation <- function(


# get the outcomes during TAR
outcomeTAR <- population %>%
dplyr::inner_join(plpData$outcomes, by ='rowId') %>%
dplyr::filter(.data$outcomeId == get('oId')) %>%
outcomeTAR <- plpData$outcomes %>%
dplyr::filter(.data$outcomeId == get("oId")) %>%
dplyr::inner_join(population, by = "rowId") %>%
dplyr::select("rowId", "daysToEvent", "tarStart", "tarEnd") %>%
dplyr::filter(.data$daysToEvent >= .data$tarStart & .data$daysToEvent <= .data$tarEnd)

Expand Down Expand Up @@ -331,9 +334,9 @@ createStudyPopulation <- function(
ParallelLogger::logTrace("Removing subjects with prior outcomes (if any)")

# get the outcomes during TAR
outcomeBefore <- population %>%
dplyr::inner_join(plpData$outcomes, by ='rowId') %>%
outcomeBefore <- plpData$outcomes %>%
dplyr::filter(outcomeId == get('oId')) %>%
dplyr::inner_join(population, by = 'rowId') %>%
dplyr::select("rowId", "daysToEvent", "tarStart") %>%
dplyr::filter(.data$daysToEvent < .data$tarStart & .data$daysToEvent > -get('priorOutcomeLookback') )

Expand Down

0 comments on commit 988221c

Please sign in to comment.