11.11 HbA1c

Calculate HbA1c in both % (US) and mmol/mol (UK). UK Biobank measurements lie between 15 and 515.2 mmol/mol. In primary care data, some values are given in percent, some in mmol/mol. We filter the allowable range to lie between 4 and 18 (%) or between 20.2 and 173.2 (mmol/mol) to guard against including values recorded under the incorrect unit. Conversion between % and mmol/mol is performed using the IFCC-NGSP master equation (https://doi.org/10.1373/clinchem.2008.103556).

a1c <- gp_clinical %>%
  filter(grepl(a1c_codes, code)) %>%
  mutate(hba1c = coalesce(as.numeric(value1), as.numeric(value2), as.numeric(value3))) %>%
  filter(hba1c > 0) %>%
  mutate(value3 = toupper(value3)) %>%
  mutate(value3 = ifelse(value3 %in%  c("MEA000", "MMOL/M", "MEA097", "UNKNOWN", "MEA001", 
                                        "%", "HBA1C", "%TOTAL HB", "% TOTAL HB", "MEA215", 
                                        "MMOL/MOL HB", "PER CENT", "%TOTAL"), "", value3)) %>%
  mutate(units = ifelse(value3 != "", value3, 
                        ifelse(code %in% c("XaPbt", "42W5."), "MMOL/MOL", "%"))) %>%
  filter(units %in% c("%", "MMOL/MOL")) %>%
  mutate(hba1c_percent = ifelse(units == "%", round(hba1c, 1), 
                                round(hba1c/10.929 + 2.15, 1))) %>%
  mutate(hba1c_mmol_mol = ifelse(units =="%", round(10.929 * (hba1c - 2.15), 1), 
                                 round(hba1c, 1))) %>%
  filter(hba1c_percent > 4 & hba1c_percent < 18) %>%
  dplyr::rename(original_unit = units)

a1c %>% group_by(code, term_description) %>%
  summarize(n=n(), mean=mean(hba1c_percent, na.rm=T)) %>%
  arrange(desc(n)) %>% kable()

ggplot(data=a1c, aes(x = hba1c_percent, color = original_unit)) + geom_density()