Add the ethnicity of a person to a table
Arguments
- x
A
cdm_tablecontaining a person identifier column namedperson_idorsubject_id.- from
A character vector specifying the ethnicity sources to try, in priority order. The first source that provides a value is used. Available options are:
ethnicity_concept_id to assign ethnicity using the
concept_nameassociated with theethnicity_concept_idcolumn of thepersontable.ethnicity_source_concept_id to assign ethnicity using the
concept_nameassociated with theethnicity_source_concept_idcolumn of thepersontable.race_concept_id to assign ethnicity using the
concept_nameassociated with therace_concept_idcolumn of thepersontable.race_source_concept_id to assign ethnicity using the
concept_nameassociated with therace_source_concept_idcolumn of thepersontable.ethnicity_source_value to assign ethnicity using the value of the column
ethnicity_source_valuein thepersontable.race_source_value to assign ethnicity using the value of the column
race_source_valuein thepersontable.nhs-categories to assign ethnicity using NHS Ethnic Category.
nhs-groups to assign ethnicity using broad groups of NHS Ethnic Category as described in doi:10.1038/s41597-024-02958-1 .
- nameStyle
A character string specifying the name of the new column.
- name
A character string specifying the name of the output table. If
NULL, a temporary table is created.- missingEthnicityValue
A character string used to replace missing ethnicity values.
Examples
# \donttest{
library(omock)
library(duckdb)
library(OmopIndices)
library(dplyr)
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"
)
#> ℹ 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 |>
addEthnicity() |>
select(subject_id, cohort_start_date, ethnicity) |>
glimpse()
#> ℹ Trying to get ethnicity from: ethnicity_concept_id.
#> ✖ Ethnicity could not be added from ethnicity_concept_id.
#> ℹ Trying to get ethnicity from: ethnicity_source_concept_id.
#> ✖ Ethnicity could not be added from ethnicity_source_concept_id.
#> ℹ Trying to get ethnicity from: race_concept_id.
#> ✖ Ethnicity could not be added from race_concept_id.
#> ℹ Trying to get ethnicity from: race_source_concept_id.
#> ✖ Ethnicity could not be added from race_source_concept_id.
#> ! No ethnicity found, variable will be filled with `Missing`.
#> Rows: ??
#> Columns: 3
#> $ subject_id <int> 19, 119, 153, 153, 209, 299, 335, 340, 340, 369, 369…
#> $ cohort_start_date <date> 2018-08-13, 1968-04-07, 2001-11-28, 2008-02-17, 198…
#> $ ethnicity <chr> "Missing", "Missing", "Missing", "Missing", "Missing…
# }
