Add Body Mass Index measurement
Arguments
- x
A
cdm_tablecontaining a person identifier column namedperson_idorsubject_id.- conceptSet
A named concept set supplied as a
codelist,codelist_with_details,concept_set_expression, or named list of concept IDs. It must containobesity,bmias concepts. By default, internal codelists are used.- indexDate
A character string naming the
Datecolumn inxthat defines the index date.- window
A numeric vector of length two,
c(min, max), defining the window forBMIin days relative toindexDate. Use-InforInffor 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), ormin(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.
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, …
# }
