3.2 Custom defined outcome for DR

Define customized outcome for diabetes-related eye disease using demographic dataset. We use 5901 family of fields which include:

  • f.5901.0.0
  • f.5901.1.0
  • f.5901.2.0
  • f.5901.3.0

These fields record age at which DR was diagnosed at four different time points. Here are the steps for defining the first occurrence event data for this outcome:

  1. Negative values that indicate incidence but unknown date of the event is converted to a numeric value 999.
  2. dr_self = 1 if the event happened, or 0 otherwise.
  3. age_dr_self: we take the youngest age at which a person was identified as having DR, and individuals with unknown date of this event is coded as NA.
  4. If age is greater than 998, then we are uncertain of when the outcome was actually identified, so they are converted back to NA.
  5. dr_self is set to NA for individuals who were identified to have an outcome but with missing age when the outcome was identified.
  6. To obtain the date of a DR event, we add DOB (decimal date) and age at which the outcome was identified.
custom_outcome_fields_table_wide <- demog %>%
  mutate(f.5901.0.0 = replace(f.5901.0.0, which(f.5901.0.0 < 0), 999)) %>% 
  mutate(f.5901.1.0 = replace(f.5901.1.0, which(f.5901.1.0 < 0), 999)) %>% 
  mutate(f.5901.2.0 = replace(f.5901.2.0, which(f.5901.2.0 < 0), 999)) %>% 
  mutate(f.5901.3.0 = replace(f.5901.3.0, which(f.5901.3.0 < 0), 999)) %>% 
  mutate(dr_self = as.numeric(!is.na(f.5901.0.0) | !is.na(f.5901.1.0) | !is.na(f.5901.2.0) | !is.na(f.5901.3.0))) %>%
  mutate(age_dr_self = pmin(f.5901.0.0, f.5901.1.0, f.5901.2.0, f.5901.3.0, na.rm=T)) %>%
  mutate(age_dr_self = replace(age_dr_self, which(age_dr_self > 998), NA)) %>%
  mutate(dr_self = replace(dr_self, which(is.na(age_dr_self) & dr_self==1), NA)) %>%
  mutate(date_dr_self = as.Date(date_decimal(decimal_date(DOB) + age_dr_self))) %>% 
  select(f.eid,date_dr_self)

custom_outcome_fields_table_long <- 
  custom_outcome_fields_table_wide %>% 
  pivot_longer(-f.eid, names_to = "field", values_to = "event_dt", values_drop_na = T)

custom_outcome_fields_table_long <-
  custom_outcome_fields_table_long %>% 
  mutate(field = ifelse(field == "date_dr_self", "dr_self", field))