Learn R Programming

CohortConstructor (version 0.2.2)

stratifyCohorts: Create a new cohort table from stratifying an existing one

Description

stratifyCohorts() creates new cohorts, splitting an existing cohort based on specified columns on which to stratify on.

Usage

stratifyCohorts(
  cohort,
  strata,
  cohortId = NULL,
  removeStrata = TRUE,
  name = tableName(cohort)
)

Value

Cohort table stratified.

Arguments

cohort

A cohort table in a cdm reference.

strata

A strata list that point to columns in cohort table.

cohortId

IDs of the cohorts to include. If NULL all cohorts will be considered. Cohorts not included will be removed from the cohort set.

removeStrata

Whether to remove strata columns from final cohort table.

name

Name of the new cohort.

Examples

Run this code
# \donttest{
library(CohortConstructor)
library(PatientProfiles)

cdm <- mockCohortConstructor()

cdm$my_cohort <- cdm$cohort1 |>
  addAge(ageGroup = list("child" = c(0, 17), "adult" = c(18, Inf))) |>
  addSex() |>
  stratifyCohorts(
    strata = list("sex", c("sex", "age_group")), name = "my_cohort"
  )

cdm$my_cohort

settings(cdm$my_cohort)

attrition(cdm$my_cohort)
# }

Run the code above in your browser using DataLab