
Summarise characteristics of cohorts in a cohort table
Source:R/summariseCharacteristics.R
summariseCharacteristics.RdSummarise characteristics of cohorts in a cohort table
Usage
summariseCharacteristics(
cohort,
cohortId = NULL,
strata = list(),
counts = TRUE,
demographics = c("age", "sex", "prior_observation", "future_observation",
"days_in_cohort", "days_to_next_record", "cohort_start_date", "cohort_end_date"),
ageGroup = NULL,
tableIntersectFlag = list(),
tableIntersectCount = list(),
tableIntersectDate = list(),
tableIntersectDays = list(),
cohortIntersectFlag = list(),
cohortIntersectCount = list(),
cohortIntersectDate = list(),
cohortIntersectDays = list(),
conceptIntersectFlag = list(),
conceptIntersectCount = list(),
conceptIntersectDate = list(),
conceptIntersectDays = list(),
otherVariables = character(),
estimates = list(),
weights = NULL
)Arguments
- cohort
A cohort_table object.
- cohortId
A cohort definition id to restrict by. If NULL, all cohorts will be included.
- strata
A list of variables to stratify results. These variables must have been added as additional columns in the cohort table.
- counts
TRUE or FALSE. If TRUE, record and person counts will be produced.
- demographics
A character vector indicating which demographic variables to include in the characterisation, in the order supplied. The following options are allowed:
age Age in years measured at cohort_start_date.
age_in_months Age in months measured at cohort_start_date.
sex Male and Female percentages.
prior_observation Prior number of days in observation at cohort_start_date.
future_observation Future number of days in observation since cohort_start_date.
days_in_cohort Number of days in the cohort, calculated as: cohort_end_date - cohort_start_date + 1.
days_to_next_record Number of days from one record the the following record entry, calculated as: next_cohort_start_date - cohort_end_date.
cohort_start_date
cohort_start_year year of the cohort_start_date.
cohort_start_month year and month of the cohort_start_date. Min/max, mean, median and quantiles are rounded to the nearest month and formatted as YYYY-MM. Standard deviation is returned as a numeric value measured in months.
cohort_end_date
cohort_end_year year of the cohort_end_date.
cohort_end_month year and month of the cohort_end_date, summarised as for cohort_start_month.
Legacy: for backwards compatibility if
demographics = TRUEthe following values will be included: c("age", "sex", "prior_observation", "future_observation", "days_in_cohort", "days_to_next_record", "cohort_start_date", "cohort_end_date"), ifdemographics = FALSEthen character() will be used.- ageGroup
A list of age groups. Age groups appear after
age, or afterage_in_monthsifageis not included, or at the end of the demographics if neither is included.- tableIntersectFlag
A list of arguments that uses PatientProfiles::addTableIntersectFlag() to add variables to summarise.
- tableIntersectCount
A list of arguments that uses PatientProfiles::addTableIntersectCount() to add variables to summarise.
- tableIntersectDate
A list of arguments that uses PatientProfiles::addTableIntersectDate() to add variables to summarise.
- tableIntersectDays
A list of arguments that uses PatientProfiles::addTableIntersectDays() to add variables to summarise.
- cohortIntersectFlag
A list of arguments that uses PatientProfiles::addCohortIntersectFlag() to add variables to summarise.
- cohortIntersectCount
A list of arguments that uses PatientProfiles::addCohortIntersectCount() to add variables to summarise.
- cohortIntersectDate
A list of arguments that uses PatientProfiles::addCohortIntersectDate() to add variables to summarise.
- cohortIntersectDays
A list of arguments that uses PatientProfiles::addCohortIntersectDays() to add variables to summarise.
- conceptIntersectFlag
A list of arguments that uses PatientProfiles::addConceptIntersectFlag() to add variables to summarise.
- conceptIntersectCount
A list of arguments that uses PatientProfiles::addConceptIntersectCount() to add variables to summarise.
- conceptIntersectDate
A list of arguments that uses PatientProfiles::addConceptIntersectDate() to add variables to summarise.
- conceptIntersectDays
A list of arguments that uses PatientProfiles::addConceptIntersectDays() to add variables to summarise.
- otherVariables
Other variables contained in cohort that you want to be summarised.
- estimates
To modify the default estimates for a variable. By default: 'min', 'q25', 'median', 'q75', 'max' for "date", for "numeric" and "integer" variables ("numeric" and "integer" also use 'mean' and 'sd' estimates). 'count' and 'percentage' for "categorical" and "binary". You have to provide them as a list:
list(age = c("median", "density")). You can also use 'date', 'numeric', 'integer', 'binary', 'categorical', 'demographics', 'intersect', 'other', 'table_intersect_count', ... as valid labels, see available estimates usingPatientProfiles::availableEstimates()- weights
Column in cohort that points to weights of each individual.
Examples
# \donttest{
library(dplyr, warn.conflicts = FALSE)
library(CohortCharacteristics)
library(PatientProfiles)
cdm <- mockCohortCharacteristics()
cdm$cohort1 |>
addSex() |>
addAge(
ageGroup = list(c(0, 40), c(41, 150))
) |>
summariseCharacteristics(
strata = list("sex", "age_group"),
cohortIntersectFlag = list(
"Cohort 2 Flag" = list(
targetCohortTable = "cohort2", window = c(-365, 0)
)
),
cohortIntersectCount = list(
"Cohort 2 Count" = list(
targetCohortTable = "cohort2", window = c(-365, 0)
)
)
) |>
glimpse()
#> ℹ adding demographics columns
#> ℹ adding cohortIntersectFlag 1/1
#> window names cast to snake_case:
#> • `-365 to 0` -> `365_to_0`
#> ℹ adding cohortIntersectCount 1/1
#> window names cast to snake_case:
#> • `-365 to 0` -> `365_to_0`
#> ℹ summarising data
#> ℹ summarising cohort cohort_1
#> ℹ summarising cohort cohort_2
#> ℹ summarising cohort cohort_3
#> ✔ summariseCharacteristics finished!
#> Rows: 741
#> Columns: 13
#> $ result_id <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ cdm_name <chr> "PP_MOCK", "PP_MOCK", "PP_MOCK", "PP_MOCK", "PP_MOCK"…
#> $ group_name <chr> "cohort_name", "cohort_name", "cohort_name", "cohort_…
#> $ group_level <chr> "cohort_1", "cohort_1", "cohort_1", "cohort_1", "coho…
#> $ strata_name <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ strata_level <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ variable_name <chr> "Number records", "Number subjects", "Age", "Age", "A…
#> $ variable_level <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, "Female", "Female…
#> $ estimate_name <chr> "count", "count", "min", "q25", "median", "q75", "max…
#> $ estimate_type <chr> "integer", "integer", "integer", "integer", "integer"…
#> $ estimate_value <chr> "4", "4", "4", "8", "14", "21", "26", "14.5", "9.8826…
#> $ additional_name <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ additional_level <chr> "overall", "overall", "overall", "overall", "overall"…
# }