Skip to content

Commit

Permalink
Group age distribution by cohort
Browse files Browse the repository at this point in the history
  • Loading branch information
martaalcalde committed Dec 13, 2024
1 parent e5e1658 commit b2ad806
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/cohortDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ cohortDiagnostics <- function(cohort){

cli::cli_bullets(c("*" = "Getting age density"))
results[["cohort_density"]] <- cdm[[tempCohortName]] |>
PatientProfiles::addCohortName() |>
PatientProfiles::summariseResult(
strata = "sex",
includeOverallStrata = FALSE,
group = "cohort_name",
includeOverallGroup = FALSE,
variables = "age",
estimates = "density") |>
suppressMessages()
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-cohortDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ test_that("run with multiple cohorts", {
dplyr::pull("result_type"),
"table")))

# Check density is calculated by cohort
expect_identical(result |>
dplyr::filter(variable_name == "age") |>
dplyr::select("group_level") |>
dplyr::distinct() |>
dplyr::pull() |>
dplyr::arrange(),
c("cohort_1", "cohort_2"))

# cohort and timing and overlap should have been estimated now we have more than one cohort
expect_true(any(stringr::str_detect(
omopgenerics::settings(result) |>
Expand Down

0 comments on commit b2ad806

Please sign in to comment.