Skip to contents

Add socioeconomic status as a column to a table

Usage

addSocioEconomicStatus(
  x,
  indexDate = "cohort_start_date",
  window = c(-Inf, Inf),
  order = "last",
  from = c("imd", "townsend"),
  nameStyle = "socio_economic_status",
  name = tableName(x),
  missingSocioEconomicStatusValue = "Missing"
)

Arguments

x

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

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 socio_economic_status in days relative to indexDate. Use -Inf or Inf for an unbounded lower or upper limit.

order

A character string specifying which record to select when multiple records are found: first or last.

from

A character vector specifying the socioeconomic status sources to try, in priority order. Supported values are imd, for the Index of Multiple Deprivation, and townsend, for the Townsend deprivation index.

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.

missingSocioEconomicStatusValue

A character string used to replace missing socioeconomic status values.

Value

The table x with a new column containing the patient's socioeconomic status.

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 |>
  addSocioEconomicStatus() |>
  select(subject_id, cohort_start_date, socio_economic_status) |>
  glimpse()
#>  Trying to add Socio-economic status from imd.
#> ! Socio-economic status could not be added from imd.
#>  Trying to add Socio-economic status from townsend.
#> ! Socio-economic status could not be added from townsend.
#> Rows: ??
#> Columns: 3
#> $ subject_id            <int> 19, 19, 61, 119, 119, 119, 140, 149, 149, 153, 2…
#> $ cohort_start_date     <date> 1970-03-31, 1978-02-13, 1974-10-22, 1976-05-18,
#> $ socio_economic_status <chr> "Missing", "Missing", "Missing", "Missing", "Mis…
# }