Skip to main content

3  Demographics

Authors

Briha Ansari

Patrick Sadil

library(dplyr)
library(ggplot2)
library(readr)

The demographics file captures the descriptive and background characteristics of each Acute to Chronic Pain Signatures Study (A2CPS) participant, including age, sex, gender identity, race, education, employment, marital status, household income, disability status, and pain duration. Almost every A2CPS analysis draws on these fields, so demographics is often the first modality a project touches. Participants also belong to one of two surgical cohorts (knee arthroplasty and thoracic surgery), and since the cohorts differ systematically in age, these demographic variables matter when we interpret cohort comparisons.

The file comes from the NIMH Data Archive (NDA), which stores the raw self-reported values without any derived variables or quality flags. For an overview of the coding, see the data dictionary. We work with the fields as NDA provides them and apply only light cleaning where a specific analysis needs it.

3.1 Starting Project

3.1.1 Locate Data

We assume that the data were downloaded from the NIMH Data Archive (NDA) as a Data Package and saved to data/nda inside the project folder (Appendix C describes what a package contains). Each NDA data structure is a table, <structure>.txt, and any files that the structure references are underneath a folder of the same name, <structure>/. Paths in the text start from the folder that holds the structure’s files (for the MRI data, <structure>/corral-secure/projects/A2CPS/products/consortium-data/pre-surgery), while code chunks spell out the full path from the project folder.

The demographics measure is the heal_demographics01 structure, which uses NDA’s own short field names.

data/nda/heal_demographics01.txt

3.1.2 Extract Data

We read the file without its line of column descriptions, convert record_id to a number, and drop any exact duplicate rows so that a participant appears only once. We then derive the surgical cohort from record_id.

demo_file <- "data/nda/heal_demographics01.txt"

# line 2 of an NDA table describes each column, so take names from line 1 and data from line 3
demo_names <- names(read_tsv(demo_file, n_max = 0, show_col_types = FALSE))
demo <- read_tsv(demo_file, skip = 2, col_names = demo_names) |>
  rename(record_id = src_subject_id) |>
  mutate(record_id = as.numeric(record_id)) |>
  distinct() |>
  mutate(
    cohort = case_when(
      record_id >= 10000 & record_id < 15000 | record_id >= 25000 ~ "TKA",
      .default = "Thoracic"
    )
  )

The downloaded file uses NDA’s short field names (genident_heal, edulevel_heal, and so on). We rename them to the HEAL Common Data Element names, which the NIH HEAL Initiative defined so that measures are recorded consistently and can be compared across HEAL studies. The mapping below comes from the A2CPS crosswalk. The race fields arrive as separate indicator columns (one per category), which the crosswalk keeps as individual HEAL variables.

demo_crosswalk <- c(
  GENIDENT = "genident_heal",
  AI_AN = "ai_an",
  Asian = "asian_heal",
  Bl_AA = "bl_aa",
  NH_PI = "nh_pi",
  White = "white_heal",
  Unkn = "unkn",
  Not_Rep = "not_rep",
  EDULEVEL = "edulevel_heal",
  EMPSTAT = "empstat_heal",
  MARISTAT = "maristat_heal",
  INCMLVL = "incmlvl_heal",
  DISABINSIND = "disabinsind",
  PAINDUR = "paindur_y"
)

demo <- demo |>
  rename(all_of(demo_crosswalk))

A quick look at a few key fields and the cohort label.

demo |>
  select(record_id, cohort, sex, EDULEVEL, PAINDUR) |>
  head()
record_id cohort sex EDULEVEL PAINDUR
10158 TKA F 4 48
10159 TKA F 5 384
10160 TKA F 5 24
10161 TKA F 5 36
10162 TKA F 4 48
10163 TKA F 6 12

Check data types and confirm that coded categoricals come in as expected (sex as text, the coded fields as numbers).

demo |>
  select(record_id, cohort, sex, EDULEVEL, PAINDUR) |>
  glimpse()
Rows: 1,017
Columns: 5
$ record_id <dbl> 10158, 10159, 10160, 10161, 10162, 10163, 10165, 10166, 1016…
$ cohort    <chr> "TKA", "TKA", "TKA", "TKA", "TKA", "TKA", "TKA", "TKA", "TKA…
$ sex       <chr> "F", "F", "F", "F", "F", "F", "F", "M", "F", "F", "F", "M", …
$ EDULEVEL  <dbl> 4, 5, 5, 5, 4, 6, 5, 5, 6, 6, 6, 6, 3, 5, 5, 5, 3, 6, 5, 5, …
$ PAINDUR   <dbl> 48, 384, 24, 36, 48, 12, 9, 120, 24, 48, 36, 48, 48, 12, 10,…

3.1.3 Data Quality

NDA stores the raw self-reported values, so implausible entries are left in place rather than flagged. Pain duration is the clearest example: a few values are negative, and a few are longer than the participant has been alive (pain duration in months exceeding interview_age, which is also in months). We tally those before deciding how to handle them.

demo |>
  summarise(
    n = n(),
    pain_negative = sum(PAINDUR < 0, na.rm = TRUE),
    pain_longer_than_life = sum(PAINDUR > interview_age, na.rm = TRUE),
    pain_missing = sum(is.na(PAINDUR))
  )
n pain_negative pain_longer_than_life pain_missing
1017 1 4 88

3.2 Exploratory data analysis

Since the two surgical cohorts are recruited separately, a useful way to get oriented is to compare their basic demographics, because the differences here shape the interpretation of cohort comparisons. We look at age and pain duration.

Pain duration is self-reported and includes imlausible values, so we set the negative ones and the ones longer than the participant has lived to missing before plotting. We work with the field as given and only overwrite the implausible values.

demo <- demo |>
  mutate(
    PAINDUR = if_else(
      PAINDUR >= 0 & PAINDUR <= interview_age,
      PAINDUR,
      NA_real_
    )
  )
ggplot(demo, aes(x = cohort, y = interview_age, fill = cohort)) +
  geom_boxplot(show.legend = FALSE) +
  labs(title = "Age by cohort", x = NULL, y = "Age (months)") +
  theme_minimal()

The knee (TKA) cohort is older on average (a median near 66 years against about 62 for thoracic), which fits the usual clinical profile of knee-arthroplasty candidates.

demo |>
  filter(!is.na(PAINDUR)) |>
  ggplot(aes(x = cohort, y = PAINDUR, fill = cohort)) +
  geom_boxplot(show.legend = FALSE) +
  labs(
    title = "Pain duration by cohort",
    x = NULL,
    y = "Pain duration (months)"
  ) +
  theme_minimal()

The contrast in pain duration is sharper: the TKA cohort reports longer pre-surgical pain (a median around 36 months), while the thoracic cohort reports little or none (a median near zero), consistent with long-standing knee pain against a more acute surgical indication.

The takeaway for planning is that the cohorts are not demographically interchangeable, so age and pain history are natural covariates to consider whenever we pool or compare them.

3.3 Considerations While Working on the Project

3.3.1 Data Generation

Demographic information is self-reported by participants at baseline, following the A2CPS Manual of Procedures.

3.3.2 Data Quality

Initial internal versions of this dataset were stored and processed in a different environment than the NDA. The NDA data are relatively more raw, and several additional quality checks are warranted. The A2CPS DIRC is working on producing a workflow describing the checks that we recommend for the NDA data.

3.3.3 Other

  • Coded fields. Many categorical fields are stored as numbers, and the coding differs from field to field, so keep the HEAL Common Data Element definitions handy.
  • Sparse levels. A few fields have very sparse levels (for example, the handful of "NR" responses in sex), which can make those subgroups unstable.
  • Self-report. These fields are all self-reported at baseline, so the usual survey caveats apply, such as some missingness, rounding, and bias in items like income.

3.3.4 Citations

In publications or presentations including data from A2CPS, please include the following statement as attribution:

Data were provided (in part) by the A2CPS Consortium funded by the National Institutes of Health (NIH) Common Fund, which is managed by the Office of the Director (OD)/Office of Strategic Coordination (OSC). Consortium components and their associated funding sources include Clinical Coordinating Center (U24NS112873), Data Integration and Resource Center (U54DA049110), Omics Data Generation Centers (U54DA049116, U54DA049115, U54DA049113), Multi-site Clinical Center 1 (MCC1) (UM1NS112874), and Multi-site Clinical Center 2 (MCC2) (UM1NS118922).

Note

The following published papers should be cited when referring to A2CPS Protocol and Biomarkers: Sluka et al. (2023) Berardi et al. (2022)

Berardi, G., Frey-Law, L., Sluka, K. A., Bayman, E. O., Coffey, C. S., Ecklund, D., Vance, C. G. T., Dailey, D. L., Burns, J., Buvanendran, A., McCarthy, R. J., Jacobs, J., Zhou, X. J., Wixson, R., Balach, T., Brummett, C. M., Clauw, D., Colquhoun, D., Harte, S. E., … Wandner, L. D. (2022). Multi-site observational study to assess biomarkers for susceptibility or resilience to chronic pain: The acute to chronic pain signatures (A2CPS) study protocol. Frontiers in Medicine, 9. https://doi.org/10.3389/fmed.2022.849214
Sluka, K. A., Wager, T. D., Sutherland, S. P., Labosky, P. A., Balach, T., Bayman, E. O., Berardi, G., Brummett, C. M., Burns, J., Buvanendran, A., et al. (2023). Predicting chronic postsurgical pain: Current evidence and a novel program to develop predictive biomarker signatures. Pain, 164(9), 1912–1926. https://doi.org/10.1097/j.pain.0000000000002938