Skip to contents

This comprises all the diagnostics that are being offered in this package, this includes:

  • A diagnostic on the OMOP CDM dataset as a whole via databaseDiagnostics.

  • A diagnostic on the codelists associated with cohorts via codelistDiagnostics.

  • A diagnostic on the cohort itself via cohortDiagnostics.

  • A diagnostic on the frequency of the cohort in the dataset population via populationDiagnostics.

Usage

phenotypeDiagnostics(
  cohort,
  databaseDiagnostics = list(),
  codelistDiagnostics = list(),
  cohortDiagnostics = list(),
  populationDiagnostics = list(),
  stagingDirectory = NULL
)

Arguments

cohort

Cohort table in a cdm reference

databaseDiagnostics

A list of arguments that uses databaseDiagnostics. If the list is empty, the default values will be used. Example: In the following example, all diagnostics will be run except person table summary from databaseDiagnostics: *databaseDiagnostics = list( "personTableSummary" = FALSE )

codelistDiagnostics

A list of arguments that uses codelistDiagnostics. If the list is empty, the default values will be used. Example: In the below example, all diagnostics will be run, and a subsample of 1,000 participants will be used to run measurement diagnostics and another independent subsample of 500 participants will be used to run drug diagnostics: *codelistDiagnostics = list( "measurementDiagnosticsSample" = 1000, "drugDiagnosticsSample" = 500 )

cohortDiagnostics

A list of arguments that uses cohortDiagnostics. If the list is empty, the default values will be used. Example: *cohortDiagnostics = list( "cohortSurvival" = TRUE )

populationDiagnostics

A list of arguments that uses populationDiagnostics. If the list is empty, the default values will be used. Example: In the below example, all diagnostics will be run and a subsample of 100,000 participants will be used to run populationDiagnostics. *populationDiagnostics = list( "populationSample" = 100000 )

stagingDirectory

Path to folder to save incremental results and log file

Value

A summarised result

Examples

# \donttest{
library(omock)
library(CohortConstructor)
library(PhenotypeR)

cdm <- mockCdmFromDataset(source = "duckdb")
#>  Loading bundled GiBleed tables from package data.
#>  Adding drug_strength table.
#>  Creating local <cdm_reference> object.
#>  Inserting <cdm_reference> into duckdb.
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#>  /tmp/RtmprdhPUv/duckdb
#> This is removed when the R session ends.
#>  Extensions are re-downloaded each session.
#>  Secrets are lost.
#>  Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#>  Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#>  See ?duckdb_storage for details and alternatives.
cdm$warfarin <- conceptCohort(cdm,
                              conceptSet =  list(warfarin = c(1310149L,
                                                              40163554L)),
                              name = "warfarin")
#>  Subsetting table drug_exposure using 2 concepts with domain: drug.
#>  Combining tables.
#>  Creating cohort attributes.
#>  Applying cohort requirements.
#>  Merging overlapping records.
#>  Cohort warfarin created.
result <- phenotypeDiagnostics(cdm$warfarin)
#> Logging PhenotypeR progress in
#> /tmp/RtmprdhPUv/phenotypeDiagnostics_log_{date}_{time}1c827db1f311.txt
#>  Creating log file:
#>   /tmp/RtmprdhPUv/phenotypeDiagnostics_log_2026_08_02_16_34_401c827db1f311.txt.
#> [2026-08-02 16:34:40] - Log file created
#> [2026-08-02 16:34:40] - Database diagnostics - getting CDM Snapshot
#> [2026-08-02 16:34:40] - Database diagnostics - summarising person table
#>  The following estimates will be calculated:
#>  date_of_birth: density
#> ! Table is collected to memory as not all requested estimates are supported on
#>   the database side.
#> → Start summary of data, at 2026-08-02 16:34:44.447456
#>  Summary finished, at 2026-08-02 16:34:44.507474
#> [2026-08-02 16:34:44] - Database diagnostics - summarising observation period
#>  retrieving cdm object from cdm_table.
#> Warning: ! There are 2649 individuals not included in the person table.
#>  The following estimates will be calculated:
#>  observation_period_start_date: density
#>  observation_period_end_date: density
#> ! Table is collected to memory as not all requested estimates are supported on
#>   the database side.
#> → Start summary of data, at 2026-08-02 16:34:47.628176
#>  Summary finished, at 2026-08-02 16:34:47.706044
#> [2026-08-02 16:34:48] - Codelist diagnostics - index event breakdown
#> Getting counts of warfarin codes for cohort warfarin
#> Warning: The CDM reference containing the cohort must also contain achilles tables.
#> Returning only index event breakdown.
#> [2026-08-02 16:34:50] - Cohort diagnostics - cohort attrition
#> [2026-08-02 16:34:50] - Cohort diagnostics - cohort count
#>  summarising data
#>  summarising cohort warfarin
#>  summariseCharacteristics finished!
#> → Skipping cohort sampling as all cohorts have less than 20000 individuals.
#> [2026-08-02 16:34:51] - Cohort diagnostics - matched cohorts
#> → Sampling cohort `tmp_022_sampled_independent`
#> Returning entry cohort as the size of the cohorts to be sampled is equal or
#> smaller than `n`.
#>  Generating an age and sex matched cohort for warfarin
#> Starting matching
#>  Creating copy of target cohort.
#>  1 cohort to be matched.
#>  Creating controls cohorts.
#>  Excluding cases from controls
#>  Matching by gender_concept_id and year_of_birth
#>  Removing controls that were not in observation at index date
#>  Excluding target records whose pair is not in observation
#>  Adjusting ratio
#> Binding cohorts
#>  Done
#> → Getting cohorts and indexes
#> [2026-08-02 16:35:01] - Cohort diagnostics - cohort characteristics
#>  adding demographics columns
#>  adding tableIntersectCount 1/1
#> window names cast to snake_case:
#>  `-365 to -1` -> `365_to_1`
#>  summarising data
#>  summarising cohort warfarin
#>  summarising cohort warfarin_sampled
#>  summarising cohort warfarin_matched
#>  summariseCharacteristics finished!
#> [2026-08-02 16:35:06] - Cohort diagnostics - age density
#>  The following estimates will be calculated:
#>  age: density
#> ! Table is collected to memory as not all requested estimates are supported on
#>   the database side.
#> → Start summary of data, at 2026-08-02 16:35:07.617219
#>  Summary finished, at 2026-08-02 16:35:07.739151
#> Using defaults for windows for large scale characteristics: c(-365, -31),
#> c(-30, -1), c(0, 0), c(1, 30), and c(31, 365). These can be changed via passing
#> alternative windows as a global option
#> `PhenotypeR_summariseLargeScaleCharacteristics_window`
#> Using defaults for event tables for large scale characteristics:
#> condition_occurrence, measurement, procedure_occurrence, device_exposure, and
#> observation. These can be changed via passing alternative windows as a global
#> option `PhenotypeR_summariseLargeScaleCharacteristics_eventInWindow`
#> Using defaults for episode tables for large scale characteristics:
#> drug_exposure, drug_era, and visit_occurrence. These can be changed via passing
#> alternative windows as a global option
#> `PhenotypeR_summariseLargeScaleCharacteristics_episodeInWindow`
#> [2026-08-02 16:35:08] - Cohort diagnostics - large scale characteristics
#>  Summarising large scale characteristics 
#>  - getting characteristics from table condition_occurrence (1 of 7)
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table measurement (2 of 7)
#>  - getting characteristics from table measurement (2 of 7) for time window -365…
#>  - getting characteristics from table measurement (2 of 7) for time window -30 …
#>  - getting characteristics from table measurement (2 of 7) for time window 0 an…
#>  - getting characteristics from table measurement (2 of 7) for time window 1 an…
#>  - getting characteristics from table measurement (2 of 7) for time window 31 a…
#>  - getting characteristics from table procedure_occurrence (3 of 7)
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table observation (4 of 7)
#>  - getting characteristics from table observation (4 of 7) for time window -365…
#>  - getting characteristics from table observation (4 of 7) for time window -30 …
#>  - getting characteristics from table observation (4 of 7) for time window 0 an…
#>  - getting characteristics from table observation (4 of 7) for time window 1 an…
#>  - getting characteristics from table observation (4 of 7) for time window 31 a…
#>  - getting characteristics from table drug_exposure (5 of 7)
#>  - getting characteristics from table drug_exposure (5 of 7) for time window -3…
#>  - getting characteristics from table drug_exposure (5 of 7) for time window -3…
#>  - getting characteristics from table drug_exposure (5 of 7) for time window 0 …
#>  - getting characteristics from table drug_exposure (5 of 7) for time window 1 …
#>  - getting characteristics from table drug_exposure (5 of 7) for time window 31…
#>  - getting characteristics from table drug_era (6 of 7)
#>  - getting characteristics from table drug_era (6 of 7) for time window -365 an…
#>  - getting characteristics from table drug_era (6 of 7) for time window -30 and…
#>  - getting characteristics from table drug_era (6 of 7) for time window 0 and 0
#>  - getting characteristics from table drug_era (6 of 7) for time window 1 and 30
#>  - getting characteristics from table drug_era (6 of 7) for time window 31 and …
#>  - getting characteristics from table visit_occurrence (7 of 7)
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#> Formatting result
#> 237 estimates dropped as frequency less than 1%
#>  Summarising large scale characteristics
#>  Summarising large scale characteristics 
#>  - getting characteristics from table condition_occurrence (1 of 7)
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table condition_occurrence (1 of 7) for time wi…
#>  - getting characteristics from table measurement (2 of 7)
#>  - getting characteristics from table measurement (2 of 7) for time window -365…
#>  - getting characteristics from table measurement (2 of 7) for time window -30 …
#>  - getting characteristics from table measurement (2 of 7) for time window 0 an…
#>  - getting characteristics from table measurement (2 of 7) for time window 1 an…
#>  - getting characteristics from table measurement (2 of 7) for time window 31 a…
#>  - getting characteristics from table procedure_occurrence (3 of 7)
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table procedure_occurrence (3 of 7) for time wi…
#>  - getting characteristics from table observation (4 of 7)
#>  - getting characteristics from table observation (4 of 7) for time window -365…
#>  - getting characteristics from table observation (4 of 7) for time window -30 …
#>  - getting characteristics from table observation (4 of 7) for time window 0 an…
#>  - getting characteristics from table observation (4 of 7) for time window 1 an…
#>  - getting characteristics from table observation (4 of 7) for time window 31 a…
#>  - getting characteristics from table drug_exposure (5 of 7)
#>  - getting characteristics from table drug_exposure (5 of 7) for time window -3…
#>  - getting characteristics from table drug_exposure (5 of 7) for time window -3…
#>  - getting characteristics from table drug_exposure (5 of 7) for time window 0 …
#>  - getting characteristics from table drug_exposure (5 of 7) for time window 1 …
#>  - getting characteristics from table drug_exposure (5 of 7) for time window 31…
#>  - getting characteristics from table drug_era (6 of 7)
#>  - getting characteristics from table drug_era (6 of 7) for time window -365 an…
#>  - getting characteristics from table drug_era (6 of 7) for time window -30 and…
#>  - getting characteristics from table drug_era (6 of 7) for time window 0 and 0
#>  - getting characteristics from table drug_era (6 of 7) for time window 1 and 30
#>  - getting characteristics from table drug_era (6 of 7) for time window 31 and …
#>  - getting characteristics from table visit_occurrence (7 of 7)
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#>  - getting characteristics from table visit_occurrence (7 of 7) for time window…
#> Formatting result
#> 237 estimates dropped as frequency less than 1%
#>  Summarising large scale characteristics
#> `cohort_sample` and `matched_sample` cast to character.
#> [2026-08-02 16:35:45] - Population diagnosics - denominator cohort
#> [2026-08-02 16:35:45] - Population diagnosics - sampling person table to 1e+05
#> people
#>  Creating denominator cohorts
#>  Cohorts created in 0 min and 3 sec
#> [2026-08-02 16:35:49] - Population diagnosics - incidence
#>  Getting incidence for analysis 1 of 7
#>  Getting incidence for analysis 2 of 7
#>  Getting incidence for analysis 3 of 7
#>  Getting incidence for analysis 4 of 7
#>  Getting incidence for analysis 5 of 7
#>  Getting incidence for analysis 6 of 7
#>  Getting incidence for analysis 7 of 7
#>  Overall time taken: 0 mins and 9 secs
#> [2026-08-02 16:35:59] - Population diagnosics - prevalence
#>  Getting prevalence for analysis 1 of 7
#>  Getting prevalence for analysis 2 of 7
#>  Getting prevalence for analysis 3 of 7
#>  Getting prevalence for analysis 4 of 7
#>  Getting prevalence for analysis 5 of 7
#>  Getting prevalence for analysis 6 of 7
#>  Getting prevalence for analysis 7 of 7
#>  Time taken: 0 mins and 6 secs
#> `populationDateStart`, `populationDateEnd`, and `populationSample` cast to
#> character.
#> `populationDateStart` and `populationDateEnd` eliminated from settings as all
#> elements are NA.
#> [2026-08-02 16:36:06] - Exporting log file

# }