Skip to contents

Add Body Mass Index measurement

Usage

addBMI(
  x,
  conceptSet = NULL,
  indexDate = "cohort_start_date",
  window = c(-Inf, 0),
  order = "last",
  nameStyle = "bmi",
  categories = NULL,
  inObservation = TRUE,
  name = tableName(x)
)

Arguments

x

A cdm_table containing a person identifier column named person_id or subject_id.

conceptSet

A named concept set supplied as a codelist, codelist_with_details, concept_set_expression, or named list of concept IDs. It must contain obesity, bmi as concepts. By default, internal codelists are used.

indexDate

A character string naming the Date column in x that defines the index date.

window

A numeric vector of length two, c(min, max), defining the window for BMI in days relative to indexDate. Use -Inf or Inf for an unbounded lower or upper limit.

order

A character string specifying how to select among multiple BMI measurements within the window: last (latest), first (earliest), max (highest), or min (lowest).

nameStyle

A character string specifying the name of the new column.

categories

A named list of numeric vectors, each containing the lower and upper bounds of a BMI interval. An additional categorical column is added, and missing BMI values are labelled missing.

inObservation

Logical; whether to restrict records to the person's observation period.

name

A character string specifying the name of the output table. If NULL, a temporary table is created.

Value

The table x with a new column containing the selected BMI value.

Examples

# \donttest{
library(omock)
library(duckdb)
#> Loading required package: DBI
library(OmopIndices)
library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
library(CohortConstructor)

cdm <- mockCdmFromDataset(datasetName = "GiBleed", 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/Rtmplwnqmn/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$cohort <- conceptCohort(
  cdm = cdm,
  conceptSet = list(sinusitis = c(257012L, 4283893L, 4294548L, 40481087L)),
  name = "cohort"
)
#> Registered S3 method overwritten by 'CodelistGenerator':
#>   method            from        
#>   print.code_search omopgenerics
#>  Subsetting table condition_occurrence using 4 concepts with domain:
#>   condition.
#>  Combining tables.
#>  Creating cohort attributes.
#>  Applying cohort requirements.
#>  Merging overlapping records.
#>  Cohort cohort created.

cdm$cohort |>
  addBMI(window = c(-365, 0), order = "last") |>
  select(subject_id, cohort_start_date, bmi) |>
  glimpse()
#> Rows: ??
#> Columns: 3
#> $ subject_id        <int> 19, 19, 61, 119, 119, 119, 140, 149, 149, 153, 299, 
#> $ cohort_start_date <date> 1970-03-31, 1978-02-13, 1974-10-22, 1976-05-18, 198…
#> $ bmi               <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
# }