Add Body Mass Index measurement
Usage
addBMI(
x,
conceptSet = getIndexCodelist("body_mass_index"),
indexDate = "cohort_start_date",
window = c(-Inf, 0),
order = "last",
nameStyle = "bmi",
categories = NULL,
inObservation = TRUE,
name = tableName(x)
)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 containbmias 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 column named by appending
_categoriestonameStyleis added, and missing BMI values are labelledmissing.- 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/RtmpNEUAUi/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()
#> Warning: 9 unique codelist concept IDs are not present in `cdm$concept`.
#> Rows: ??
#> Columns: 3
#> $ subject_id <int> 57, 57, 80, 187, 248, 297, 297, 380, 394, 578, 686, …
#> $ cohort_start_date <date> 1970-12-07, 1992-02-27, 1949-11-11, 1987-09-06, 201…
#> $ bmi <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
# }
