Type: Package
Title: Diagnostics for Lists of Codes Based on Measurements
Version: 0.2.0
Description: Diagnostics of list of codes based on concepts from the domains measurement and observation. This package works for data mapped to the Observational Medical Outcomes Partnership Common Data Model.
Imports: CDMConnector (≥ 2.0.0), cli, clock, CohortConstructor (≥ 0.4.0), DBI, dplyr, glue, omopgenerics (≥ 1.2.0), PatientProfiles (≥ 1.4.0), purrr, rlang, tidyr
Suggests: CodelistGenerator (≥ 3.5.0), visOmopResults (≥ 1.4.0), duckdb, knitr, omock (≥ 0.4.0), rmarkdown, testthat, ggplot2, gt, flextable, RPostgres, lubridate, odbc
Depends: R (≥ 4.1)
License: Apache License (≥ 2)
Encoding: UTF-8
RoxygenNote: 7.3.3
URL: https://ohdsi.github.io/MeasurementDiagnostics/
BugReports: https://github.com/ohdsi/MeasurementDiagnostics/issues
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2025-12-16 21:05:16 UTC; nuriamb
Author: Edward Burn ORCID iD [aut], Nuria Mercade-Besora ORCID iD [aut, cre], Marta Alcalde-Herraiz ORCID iD [aut]
Maintainer: Nuria Mercade-Besora <nuria.mercadebesora@ndorms.ox.ac.uk>
Repository: CRAN
Date/Publication: 2025-12-17 10:10:33 UTC

MeasurementDiagnostics: Diagnostics for Lists of Codes Based on Measurements

Description

logo

Diagnostics of list of codes based on concepts from the domains measurement and observation. This package works for data mapped to the Observational Medical Outcomes Partnership Common Data Model.

Author(s)

Maintainer: Nuria Mercade-Besora nuria.mercadebesora@ndorms.ox.ac.uk (ORCID)

Authors:

See Also

Useful links:


Function to create a mock cdm reference.

Description

Creates an example dataset that can be used to show how the package works

Usage

mockMeasurementDiagnostics(
  nPerson = 100,
  con = DBI::dbConnect(duckdb::duckdb()),
  writeSchema = "main",
  seed = 111
)

Arguments

nPerson

number of people in the cdm.

con

A DBI connection to create the cdm mock object.

writeSchema

Name of an schema on the same connection with writing permissions.

seed

seed to use when creating the mock data.

Value

cdm object

Examples


library(MeasurementDiagnostics)
cdm <- mockMeasurementDiagnostics()
cdm


Helper for consistent documentation of 'plot'.

Description

Helper for consistent documentation of 'plot'.

Arguments

x

Columns to use as horizontal axes. See options with 'visOmopResults::plotColumns(result)'.

y

Columns to use as horizontal axes. See options with 'visOmopResults::plotColumns(result)'.

plotType

Type of plot, either "boxplot", "barplot", or "densityplot".

facet

Columns to facet by. See options with 'visOmopResults::plotColumns(result)'. Formula input is also allowed to specify rows and columns.

colour

Columns to color by. See options with 'visOmopResults::plotColumns(result)'.

style

Pre-defined style to apply: "default" or "darwin" - the latter just for gt and flextable. If NULL the "default" style is used.


Plot summariseMeasurementTiming results.

Description

Plot summariseMeasurementTiming results.

Usage

plotMeasurementSummary(
  result,
  y = "time",
  plotType = "boxplot",
  timeScale = "days",
  facet = visOmopResults::strataColumns(result),
  colour = c("cdm_name", "codelist_name"),
  style = NULL
)

Arguments

result

A summarised_result object.

y

Variable to plot on y axis, it can be "time" or "measurements_per_subject".

plotType

Type of plot, either "boxplot", "barplot", or "densityplot".

timeScale

Time scale to show, it can be "days" or "years".

facet

Columns to facet by. See options with 'visOmopResults::plotColumns(result)'. Formula input is also allowed to specify rows and columns.

colour

Columns to color by. See options with 'visOmopResults::plotColumns(result)'.

style

Pre-defined style to apply: "default" or "darwin" - the latter just for gt and flextable. If NULL the "default" style is used.

Value

A ggplot.

Examples


library(MeasurementDiagnostics)
library(dplyr)

cdm <- mockMeasurementDiagnostics()

result <- summariseMeasurementUse(
  cdm = cdm,
  codes = list("test_codelist" = c(3001467L, 45875977L))
)

result |>
  filter(variable_name == "time") |>
  plotMeasurementSummary()

CDMConnector::cdmDisconnect(cdm)


Plot summariseMeasurementTiming results.

Description

Plot summariseMeasurementTiming results.

Usage

plotMeasurementValueAsConcept(
  result,
  x = "count",
  y = "codelist_name",
  facet = c("cdm_name"),
  colour = c("concept_name", "variable_level", visOmopResults::strataColumns(result)),
  style = NULL
)

Arguments

result

A summarised_result object.

x

Columns to use as horizontal axes. See options with 'visOmopResults::plotColumns(result)'.

y

Columns to use as horizontal axes. See options with 'visOmopResults::plotColumns(result)'.

facet

Columns to facet by. See options with 'visOmopResults::plotColumns(result)'. Formula input is also allowed to specify rows and columns.

colour

Columns to color by. See options with 'visOmopResults::plotColumns(result)'.

style

Pre-defined style to apply: "default" or "darwin" - the latter just for gt and flextable. If NULL the "default" style is used.

Value

A ggplot.

Examples


library(MeasurementDiagnostics)

cdm <- mockMeasurementDiagnostics()

result <- summariseMeasurementUse(
  cdm = cdm,
  bySex = TRUE,
  codes = list("test_codelist" = c(3001467L, 45875977L))
)

plotMeasurementValueAsConcept(result)

CDMConnector::cdmDisconnect(cdm)


Plot summariseMeasurementTiming results.

Description

Plot summariseMeasurementTiming results.

Usage

plotMeasurementValueAsNumber(
  result,
  x = "unit_concept_name",
  plotType = "boxplot",
  facet = c("codelist_name", "concept_name"),
  colour = c("cdm_name", "unit_concept_name", visOmopResults::strataColumns(result)),
  style = NULL
)

Arguments

result

A summarised_result object.

x

Columns to use as horizontal axes. See options with 'visOmopResults::plotColumns(result)'.

plotType

Type of plot, either "boxplot", "barplot", or "densityplot".

facet

Columns to facet by. See options with 'visOmopResults::plotColumns(result)'. Formula input is also allowed to specify rows and columns.

colour

Columns to color by. See options with 'visOmopResults::plotColumns(result)'.

style

Pre-defined style to apply: "default" or "darwin" - the latter just for gt and flextable. If NULL the "default" style is used.

Value

A ggplot.

Examples


library(MeasurementDiagnostics)

cdm <- mockMeasurementDiagnostics()

result <- summariseMeasurementUse(
  cdm = cdm,
  bySex = TRUE,
  codes = list("test_codelist" = c(3001467L, 45875977L))
)

plotMeasurementValueAsNumber(result)

CDMConnector::cdmDisconnect(cdm)


Helper for consistent documentation of 'result'.

Description

Helper for consistent documentation of 'result'.

Arguments

result

A summarised_result object.


Diagnostics of a codelist of measurement codes within a cohort

Description

Diagnostics of a codelist of measurement codes within a cohort

Usage

summariseCohortMeasurementUse(
  cohort,
  codes = NULL,
  timing = "during",
  byConcept = TRUE,
  byYear = FALSE,
  bySex = FALSE,
  ageGroup = NULL,
  dateRange = as.Date(c(NA, NA)),
  estimates = list(measurement_summary = c("min", "q25", "median", "q75", "max",
    "density"), measurement_value_as_number = c("min", "q01", "q05", "q25", "median",
    "q75", "q95", "q99", "max", "count_missing", "percentage_missing", "density"),
    measurement_value_as_concept = c("count", "percentage")),
  histogram = NULL,
  checks = c("measurement_summary", "measurement_value_as_number",
    "measurement_value_as_concept")
)

Arguments

cohort

A cohort in which to perform the diagnostics of the measurement codes provided.

codes

A codelist of measurement/observation codes for which to perform diagnostics. If NULL it uses the codelist used to create each of the cohorts.

timing

Three options: 1) "any" if the interest is on measurement recorded any time, 2) "during", if interested in measurements while the subject is in the cohort (or in observation if cohort = NULL), and 3) "cohort_start_date" for measurements occurring at cohort start date (or at "observation_period_start_date if cohort = NULL).

byConcept

TRUE or FALSE. If TRUE code use will be summarised by concept.

byYear

TRUE or FALSE. If TRUE code use will be summarised by year.

bySex

TRUE or FALSE. If TRUE code use will be summarised by sex.

ageGroup

If not NULL, a list of ageGroup vectors of length two.

dateRange

Two dates. The first indicating the earliest measurement date and the second indicating the latest possible measurement date.

estimates

A named list indicating, for each measurement diagnostics check, which estimates to retrieve. The names of the list should correspond to the diagnostics checks, and each list element should be a character vector specifying the estimates to compute.

Allowed estimates are those supported by the 'summariseResult()' function in the **PatientProfiles** package. If omitted, all available estimates for each check will be returned.

histogram

Named list where names point to checks for which to get estimates for a histogram, and elements are numeric vectors indicating the bind-width. See function examples. Histogram only available for "measurement_summary" and "measurement_value_as_number".

checks

Diagnostics to run. Options are: "measurement_summary", "measurement_value_as_number", and "measurement_value_as_concept".

Value

A summarised result

Examples


library(MeasurementDiagnostics)

cdm <- mockMeasurementDiagnostics()

result <- summariseCohortMeasurementUse(
  codes = list("test_codelist" = c(3001467L, 45875977L)),
  cohort = cdm$my_cohort, timing = "cohort_start_date"
)

result <- summariseCohortMeasurementUse(
  codes = list("test_codelist" = c(3001467L, 45875977L)),
  cohort = cdm$my_cohort, timing = "cohort_start_date",
  histogram = list(
    "time" = list(
      '0 to 100' = c(0, 100), '110 to 200' = c(110, 200),
      '210 to 300' = c(210, 300), '310 to Inf' = c(310, Inf)
    ),
    "measurements_per_subject" = list(
      '0 to 10' = c(0, 10), '11 to 20' = c(11, 20), '21 to 30' = c(21, 30),
      '31 to Inf' = c(31, Inf)
    ),
    "value_as_number" =  list(
      '0 to 5' = c(0, 5), '6 to 10' = c(6, 10), '11 to 15' = c(11, 15),
      '>15' = c(16, Inf)
    )
  )
)

CDMConnector::cdmDisconnect(cdm = cdm)


Helper for consistent documentation of 'summariseMeasurement' functions.

Description

Helper for consistent documentation of 'summariseMeasurement' functions.

Arguments

cdm

A reference to the cdm object.

codes

A codelist of measurement/observation codes for which to perform diagnostics.

cohort

A cohort in which to perform the diagnostics of the measurement codes provided.

timing

Three options: 1) "any" if the interest is on measurement recorded any time, 2) "during", if interested in measurements while the subject is in the cohort (or in observation if cohort = NULL), and 3) "cohort_start_date" for measurements occurring at cohort start date (or at "observation_period_start_date if cohort = NULL).

byConcept

TRUE or FALSE. If TRUE code use will be summarised by concept.

byYear

TRUE or FALSE. If TRUE code use will be summarised by year.

bySex

TRUE or FALSE. If TRUE code use will be summarised by sex.

ageGroup

If not NULL, a list of ageGroup vectors of length two.

dateRange

Two dates. The first indicating the earliest measurement date and the second indicating the latest possible measurement date.

estimates

A named list indicating, for each measurement diagnostics check, which estimates to retrieve. The names of the list should correspond to the diagnostics checks, and each list element should be a character vector specifying the estimates to compute.

Allowed estimates are those supported by the 'summariseResult()' function in the **PatientProfiles** package. If omitted, all available estimates for each check will be returned.

histogram

Named list where names point to checks for which to get estimates for a histogram, and elements are numeric vectors indicating the bind-width. See function examples. Histogram only available for "measurement_summary" and "measurement_value_as_number".

checks

Diagnostics to run. Options are: "measurement_summary", "measurement_value_as_number", and "measurement_value_as_concept".


Diagnostics of a codelist of measurement codes in the database

Description

Diagnostics of a codelist of measurement codes in the database

Usage

summariseMeasurementUse(
  cdm,
  codes,
  byConcept = TRUE,
  byYear = FALSE,
  bySex = FALSE,
  ageGroup = NULL,
  dateRange = as.Date(c(NA, NA)),
  estimates = list(measurement_summary = c("min", "q25", "median", "q75", "max",
    "density"), measurement_value_as_number = c("min", "q01", "q05", "q25", "median",
    "q75", "q95", "q99", "max", "count_missing", "percentage_missing", "density"),
    measurement_value_as_concept = c("count", "percentage")),
  histogram = NULL,
  checks = c("measurement_summary", "measurement_value_as_number",
    "measurement_value_as_concept")
)

Arguments

cdm

A reference to the cdm object.

codes

A codelist of measurement/observation codes for which to perform diagnostics.

byConcept

TRUE or FALSE. If TRUE code use will be summarised by concept.

byYear

TRUE or FALSE. If TRUE code use will be summarised by year.

bySex

TRUE or FALSE. If TRUE code use will be summarised by sex.

ageGroup

If not NULL, a list of ageGroup vectors of length two.

dateRange

Two dates. The first indicating the earliest measurement date and the second indicating the latest possible measurement date.

estimates

A named list indicating, for each measurement diagnostics check, which estimates to retrieve. The names of the list should correspond to the diagnostics checks, and each list element should be a character vector specifying the estimates to compute.

Allowed estimates are those supported by the 'summariseResult()' function in the **PatientProfiles** package. If omitted, all available estimates for each check will be returned.

histogram

Named list where names point to checks for which to get estimates for a histogram, and elements are numeric vectors indicating the bind-width. See function examples. Histogram only available for "measurement_summary" and "measurement_value_as_number".

checks

Diagnostics to run. Options are: "measurement_summary", "measurement_value_as_number", and "measurement_value_as_concept".

Value

A summarised result

Examples


library(MeasurementDiagnostics)

cdm <- mockMeasurementDiagnostics()

result <- summariseMeasurementUse(
  cdm = cdm, codes = list("test_codelist" = c(3001467L, 45875977L))
)

resultHistogram <- summariseMeasurementUse(
  cdm = cdm,
  codes = list("test_codelist" = c(3001467L, 45875977L)),
  byConcept = TRUE,
  byYear = FALSE,
  bySex = FALSE,
  ageGroup = NULL,
  dateRange = as.Date(c(NA, NA)),
  estimates = list(
    "measurement_summary" = c("min", "q25", "median", "q75", "max", "density"),
    "measurement_value_as_number" = c(
      "min", "q01", "q05", "q25", "median", "q75", "q95", "q99", "max",
      "count_missing", "percentage_missing", "density"
    ),
    "measurement_value_as_concept" = c("count", "percentage")
  ),
  histogram = list(
    "time" = list(
      '0 to 100' = c(0, 100), '110 to 200' = c(110, 200),
      '210 to 300' = c(210, 300), '310 to Inf' = c(310, Inf)
    ),
    "measurements_per_subject" = list(
      '0 to 10' = c(0, 10), '11 to 20' = c(11, 20),
      '21 to 30' = c(21, 30), '31 to Inf' = c(31, Inf)
    ),
    "value_as_number" =  list(
      '0 to 5' = c(0, 5), '6 to 10' = c(6, 10),
      '11 to 15' = c(11, 15), '>15' = c(16, Inf)
    )
  ),
  checks = c("measurement_summary", "measurement_value_as_number", "measurement_value_as_concept")
)

CDMConnector::cdmDisconnect(cdm = cdm)



Helper for consistent documentation of 'table'.

Description

Helper for consistent documentation of 'table'.

Arguments

type

Type of table. Check supported types with ‘visOmopResults::tableType()'. If NULL ’gt' type will be used.

header

Columns to use as header. See options with 'visOmopResults::tableColumns(result)'.

groupColumn

Columns to group by. See options with 'visOmopResults::tableColumns(result)'.

settingsColumn

Columns from settings to include in results. See options with 'visOmopResults::settingsColumns(result)'.

hide

Columns to hide from the visualisation. See options with 'visOmopResults::tableColumns(result)'.

style

Named list that specifies how to style the different parts of the table generated. It can either be a pre-defined style ("default" or "darwin" - the latter just for gt and flextable), or NULL which converts to "default" style, or custom code.

.options

A named list with additional formatting options. 'visOmopResults::tableOptions()' shows allowed arguments and their default values.


Format a measurement_summary object into a visual table

Description

Format a measurement_summary object into a visual table

Usage

tableMeasurementSummary(
  result,
  header = c(visOmopResults::strataColumns(result)),
  groupColumn = c("codelist_name"),
  settingsColumn = character(),
  hide = c("variable_level"),
  style = NULL,
  type = NULL,
  .options = list()
)

Arguments

result

A summarised_result object.

header

Columns to use as header. See options with 'visOmopResults::tableColumns(result)'.

groupColumn

Columns to group by. See options with 'visOmopResults::tableColumns(result)'.

settingsColumn

Columns from settings to include in results. See options with 'visOmopResults::settingsColumns(result)'.

hide

Columns to hide from the visualisation. See options with 'visOmopResults::tableColumns(result)'.

style

Named list that specifies how to style the different parts of the table generated. It can either be a pre-defined style ("default" or "darwin" - the latter just for gt and flextable), or NULL which converts to "default" style, or custom code.

type

Type of table. Check supported types with ‘visOmopResults::tableType()'. If NULL ’gt' type will be used.

.options

A named list with additional formatting options. 'visOmopResults::tableOptions()' shows allowed arguments and their default values.

Value

A formatted table

Examples


library(MeasurementDiagnostics)

cdm <- mockMeasurementDiagnostics()

result <- summariseMeasurementUse(
  cdm = cdm,
  codes = list("test_codelist" = c(3001467L, 45875977L))
)

tableMeasurementSummary(result)

CDMConnector::cdmDisconnect(cdm = cdm)


Format a measurement_summary object into a visual table

Description

Format a measurement_summary object into a visual table

Usage

tableMeasurementValueAsConcept(
  result,
  header = c(visOmopResults::strataColumns(result)),
  groupColumn = c("codelist_name"),
  settingsColumn = character(),
  hide = character(),
  style = NULL,
  type = NULL,
  .options = list()
)

Arguments

result

A summarised_result object.

header

Columns to use as header. See options with 'visOmopResults::tableColumns(result)'.

groupColumn

Columns to group by. See options with 'visOmopResults::tableColumns(result)'.

settingsColumn

Columns from settings to include in results. See options with 'visOmopResults::settingsColumns(result)'.

hide

Columns to hide from the visualisation. See options with 'visOmopResults::tableColumns(result)'.

style

Named list that specifies how to style the different parts of the table generated. It can either be a pre-defined style ("default" or "darwin" - the latter just for gt and flextable), or NULL which converts to "default" style, or custom code.

type

Type of table. Check supported types with ‘visOmopResults::tableType()'. If NULL ’gt' type will be used.

.options

A named list with additional formatting options. 'visOmopResults::tableOptions()' shows allowed arguments and their default values.

Value

A formatted table

Examples


library(MeasurementDiagnostics)

cdm <- mockMeasurementDiagnostics()

result <- summariseMeasurementUse(
  cdm = cdm,
  codes = list("test_codelist" = c(3001467L, 45875977L))
)

tableMeasurementValueAsConcept(result)

CDMConnector::cdmDisconnect(cdm = cdm)


Format a measurement_summary object into a visual table

Description

Format a measurement_summary object into a visual table

Usage

tableMeasurementValueAsNumber(
  result,
  header = c(visOmopResults::strataColumns(result)),
  groupColumn = c("codelist_name"),
  settingsColumn = character(),
  hide = c("variable_name", "variable_level"),
  style = NULL,
  type = NULL,
  .options = list()
)

Arguments

result

A summarised_result object.

header

Columns to use as header. See options with 'visOmopResults::tableColumns(result)'.

groupColumn

Columns to group by. See options with 'visOmopResults::tableColumns(result)'.

settingsColumn

Columns from settings to include in results. See options with 'visOmopResults::settingsColumns(result)'.

hide

Columns to hide from the visualisation. See options with 'visOmopResults::tableColumns(result)'.

style

Named list that specifies how to style the different parts of the table generated. It can either be a pre-defined style ("default" or "darwin" - the latter just for gt and flextable), or NULL which converts to "default" style, or custom code.

type

Type of table. Check supported types with ‘visOmopResults::tableType()'. If NULL ’gt' type will be used.

.options

A named list with additional formatting options. 'visOmopResults::tableOptions()' shows allowed arguments and their default values.

Value

A formatted table

Examples


library(MeasurementDiagnostics)

cdm <- mockMeasurementDiagnostics()

result <- summariseMeasurementUse(
  cdm = cdm,
  codes = list("test_codelist" = c(3001467L, 45875977L))
)

tableMeasurementValueAsNumber(result)

CDMConnector::cdmDisconnect(cdm = cdm)


Helper for consistent documentation of 'timeScale'.

Description

Helper for consistent documentation of 'timeScale'.

Arguments

timeScale

Time scale to show, it can be "days" or "years".


Helper for consistent documentation of 'uniqueCombinations'.

Description

Helper for consistent documentation of 'uniqueCombinations'.

Arguments

uniqueCombinations

Whether to restrict to unique reference and comparator comparisons.