Last updated: 2022-06-13
Checks: 5 2
Knit directory: codemapper_notes/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown is untracked by Git. To know which version of the R
Markdown file created these results, you’ll want to first commit it to
the Git repo. If you’re still working on the analysis, you can ignore
this warning. When you’re finished, you can run
wflow_publish to commit the R Markdown file and build the
HTML.
The global environment had objects present when the code in the R
Markdown file was run. These objects can affect the analysis in your R
Markdown file in unknown ways. For reproduciblity it’s best to always
run the code in an empty environment. Use wflow_publish or
wflow_build to ensure that the code is always run in an
empty environment.
The following objects were defined in the global environment when these results were created:
| Name | Class | Size |
|---|---|---|
| install_codemapper | function | 1.2 Kb |
The command set.seed(20210923) was run prior to running
the code in the R Markdown file. Setting a seed ensures that any results
that rely on randomness, e.g. subsampling or permutations, are
reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version dad9263. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for
the analysis have been committed to Git prior to generating the results
(you can use wflow_publish or
wflow_git_commit). workflowr only checks the R Markdown
file, but you know if there are other scripts or data files that it
depends on. Below is the status of the Git repository when the results
were generated:
Ignored files:
Ignored: .DS_Store
Ignored: .Renviron
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: _targets/meta/process
Ignored: _targets/meta/progress
Ignored: _targets/objects/
Ignored: _targets/user/
Ignored: all_lkps_maps.db
Ignored: renv/library/
Ignored: renv/staging/
Ignored: tar_make.R
Untracked files:
Untracked: analysis/ukb_self_report_caliber_mapping.Rmd
Unstaged changes:
Modified: _targets.R
Modified: _targets/meta/meta
Modified: analysis/index.Rmd
Modified: analysis/read3_icd10_mapping.Rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
There are no past versions. Publish this analysis with
wflow_publish() to start tracking its development.
library(tidyverse)
library(reactable)
library(readxl)
library(crosstalk)
library(targets)
library(codemapper)
library(flextable)
tar_load(ALL_LKPS_MAPS_DB)
con <- DBI::dbConnect(RSQLite::SQLite(), ALL_LKPS_MAPS_DB)
all_lkps_maps <- ukbwranglr::db_tables_to_list(con)
# caliber codes
tar_load(caliber_codes)
caliber_codes_icd10 <- caliber_codes %>%
filter(code_type == "icd10") %>%
mutate(icd10_3char = str_sub(code,
start = 1L,
end = 3L))
# self-reported UKB non-cancer illnesses
coding6 <- tar_read(ukb_codings) %>%
filter(Coding == "6")
coding609 <- tar_read(ukb_codings) %>%
filter(Coding == "609") %>%
rename(icd10 = Meaning) %>%
left_join(coding6[, -1],
by = "Value")
# merge UKB and CALIBER
caliber_codes_coding609 <- coding609 %>%
full_join(caliber_codes_icd10,
by = c("icd10" = "icd10_3char")) %>%
# calculate number of CALIBER diseases per UKB code
group_by(Value) %>%
mutate(n_caliber_mappings_per_ukb = ifelse(!is.na(Value),
yes = sum(!is.na(unique(disease))),
no = NA_integer_)) %>%
ungroup() %>%
# calculate number of UKB codes per CALIBER disease
group_by(disease) %>%
mutate(n_ukb_per_caliber_mappings = ifelse(!is.na(disease),
yes = sum(!is.na(unique(Value))),
no = NA_integer_)) %>%
ungroup() %>%
# cosmetic
arrange(desc(n_caliber_mappings_per_ukb)) %>%
select(-author)
Aim: to assign UKB self-reported non-cancer illness codes to CALIBER conditions.
Approach:
caliber_codes_coding609 %>%
select(-Coding,
data_coding_6 = Value,
icd10_3char = icd10,
ukb_meaning = Meaning) %>%
reactable(filterable = TRUE,
searchable = TRUE,
paginationType = "jump",
showPageSizeOptions = TRUE,
resizable = TRUE,
pageSizeOptions = c(10, 25, 50, 100, 200, 300, 350))
mapping_status_by_caliber_disease <- caliber_codes_coding609 %>%
filter(!is.na(disease)) %>%
distinct(disease,
Value,
.keep_all = TRUE) %>%
group_by(`CALIBER disease` = disease) %>%
summarise(`N UKB self-reported codes mapped` = sum(!is.na(unique(Value))))
mapping_status_by_caliber_disease %>%
reactable(filterable = TRUE,
searchable = TRUE,
paginationType = "jump",
showPageSizeOptions = TRUE,
pageSizeOptions = c(10, 25, 50, 100, 200, 300, 350))
mapping_status_by_ukb_self_report_code <- caliber_codes_coding609 %>%
filter(!is.na(Value) & !is.na(Meaning)) %>%
distinct(Value,
Meaning,
disease,
.keep_all = TRUE) %>%
group_by(`UKB self-reported non-cancer illness` = Meaning) %>%
summarise(ukb_code = head(Value, 1),
`N CALIBER diseases mapped` = sum(!is.na(unique(disease))))
Note that self-reported ‘myasthenia gravis` is coded as both ’1260’ and ‘1437’ by UKB (as stated in the online data dictionary).
mapping_status_by_ukb_self_report_code %>%
reactable(filterable = TRUE,
searchable = TRUE,
paginationType = "jump",
showPageSizeOptions = TRUE,
pageSizeOptions = c(10, 25, 50, 100, 200, 300, 350))
Write a csv file containing UKB self-reported codes that have mapped
to a CALIBER disease (via ICD10), and manually review these. The
category should always be ‘UKB self-reported’, and the
author will be kept as ‘caliber’. Use the UKB-specific
codes as these are more specific to UKB i.e. data coding
6 instead of data coding
609.
# write to csv
ukb_self_report_non_cancer_to_caliber_map_unselected <- caliber_codes_coding609 %>%
filter(n_caliber_mappings_per_ukb > 0) %>%
distinct(disease,
description = Meaning,
code = Value) %>%
mutate(category = "UKB self-reported",
code_type = "data_coding_6",
author = "caliber",
selected = "") %>%
select(all_of(names(caliber_codes)),
selected)
ukb_self_report_non_cancer_to_caliber_map_unselected %>%
write_csv(here::here(file.path("data_small",
"ukb_self_report_non_cancer_to_caliber_map_raw.csv")))
# NOTE: when manually reviewing, save the csv as a separate file without the '_raw' suffix
# test that `ukb_self_report_non_cancer_to_caliber_map.csv` contains the same mappings as `ukb_self_report_non_cancer_to_caliber_map_raw.csv` (apart from the manuall mapping column) - RAISE ERROR AND HALT KNITTING IF NOT
ukb_self_report_non_cancer_to_caliber_map <- read_csv(here::here(file.path("data_small",
"ukb_self_report_non_cancer_to_caliber_map.csv")),
col_types = readr::cols(.default = "c"))
assertthat::are_equal(
x = ukb_self_report_non_cancer_to_caliber_map %>%
select(-selected) %>%
arrange(across(everything())),
y = ukb_self_report_non_cancer_to_caliber_map_unselected %>%
select(-selected) %>%
arrange(across(everything())),
msg = "Manually selected mapping csv does not match 'ukb_self_report_non_cancer_to_caliber_map_raw.csv'. These should be equivalent, with the exception of the 'selected' column. Has the raw version been updated?"
)
# check that only 'Y' or '' are recorded under 'selected' column
assertthat::assert_that(n_distinct(ukb_self_report_non_cancer_to_caliber_map$selected) == 2 &&
all(unique(ukb_self_report_non_cancer_to_caliber_map$selected) %in% c("Y", NA)),
msg = "Check 'ukb_self_report_non_cancer_to_caliber_map.csv': this should only contain values 'Y' and '' under column 'selected'")
Note that in many cases is is appropriate for a single UKB self-reported code to map to more than one CALIBER disease (i.e. ‘one-to-many’ mapping). For example:
ukb_self_report_non_cancer_to_caliber_map %>%
filter(code == "1604") %>%
qflextable()
disease | description | category | code_type | code | author | selected |
Alcohol Problems | alcoholic liver disease / alcoholic cirrhosis | UKB self-reported | data_coding_6 | 1604 | caliber | Y |
Alcoholic liver disease | alcoholic liver disease / alcoholic cirrhosis | UKB self-reported | data_coding_6 | 1604 | caliber | Y |
Fatty Liver | alcoholic liver disease / alcoholic cirrhosis | UKB self-reported | data_coding_6 | 1604 | caliber | |
Liver fibrosis, sclerosis and cirrhosis | alcoholic liver disease / alcoholic cirrhosis | UKB self-reported | data_coding_6 | 1604 | caliber | Y |
Hepatic failure | alcoholic liver disease / alcoholic cirrhosis | UKB self-reported | data_coding_6 | 1604 | caliber |
ukb_self_report_non_cancer_to_caliber_map %>%
filter(code == "1276") %>%
qflextable()
disease | description | category | code_type | code | author | selected |
Diabetic ophthalmic complications | diabetic eye disease | UKB self-reported | data_coding_6 | 1276 | caliber | Y |
Diabetes | diabetic eye disease | UKB self-reported | data_coding_6 | 1276 | caliber | Y |
When a 3-character ICD10 code is listed by CALIBER, this implies that any children codes should also be included in the codelist for that condition. For example, ICD10 ‘E11’ appears under the codelist for ‘Diabetes’, which includes ‘E111 - E119’ (of which ‘E119’, ‘Type 2 diabetes mellitus Without complications’, is the most commonly recorded)1.
These can map directly to a UKB self-reported code in its ICD10 equivalent (e.g. the UKB code for ‘type 2 diabetes’, ‘1223’, maps to ‘E11’ using data coding 609):
caliber_codes %>%
filter(disease == "Diabetes") %>%
filter(code_type == "icd10") %>%
filter(str_detect(code,
"^E..$")) %>%
qflextable()
disease | description | category | code_type | code | author |
Diabetes | Insulin-dependent diabetes mellitus | Insulin dependent diabetes (3) | icd10 | E10 | caliber |
Diabetes | Non-insulin-dependent diabetes mellitus | Non insulin dependent diabetes (4) | icd10 | E11 | caliber |
Diabetes | Malnutrition-related diabetes mellitus | Secondary diabetes (5) | icd10 | E12 | caliber |
Diabetes | Other specified diabetes mellitus | Diabetes not otherwise specified (6) | icd10 | E13 | caliber |
Diabetes | Unspecified diabetes mellitus | Diabetes not otherwise specified (6) | icd10 | E14 | caliber |
In the following example however, while the UKB self-reported code for ‘glaucoma’ (‘1277’) maps to ICD10 H40 using data coding 609, the CALIBER codelist for ‘Glaucoma’ only includes ICD10 codes ‘H401’, ‘H402’ and ‘H409’:2
caliber_codes %>%
filter(disease == "Glaucoma") %>%
filter(code_type == "icd10") %>%
qflextable()
disease | description | category | code_type | code | author |
Glaucoma | Primary open-angle glaucoma | Diagnosis of Glaucoma | icd10 | H401 | caliber |
Glaucoma | Primary angle-closure glaucoma | Diagnosis of Glaucoma | icd10 | H402 | caliber |
Glaucoma | Glaucoma, unspecified | Diagnosis of Glaucoma | icd10 | H409 | caliber |
In this case, I think it’s appropriate to map UKB code ‘1277’ to CALIBER disease ‘Glaucoma’:
ukb_self_report_non_cancer_to_caliber_map %>%
filter(code == "1277") %>%
qflextable()
disease | description | category | code_type | code | author | selected |
Glaucoma | glaucoma | UKB self-reported | data_coding_6 | 1277 | caliber | Y |
I have mapped self-reported viral conditions to CALIBER disease ‘Viral diseases (excl chronic hepatitis/HIV)’ only. For example:
ukb_self_report_non_cancer_to_caliber_map %>%
filter(code == "1568") %>%
qflextable()
disease | description | category | code_type | code | author | selected |
Viral diseases (excl chronic hepatitis/HIV) | measles / morbillivirus | UKB self-reported | data_coding_6 | 1568 | caliber | Y |
Encephalitis | measles / morbillivirus | UKB self-reported | data_coding_6 | 1568 | caliber | |
Meningitis | measles / morbillivirus | UKB self-reported | data_coding_6 | 1568 | caliber | |
Lower Respiratory Tract Infections | measles / morbillivirus | UKB self-reported | data_coding_6 | 1568 | caliber | |
Ear and Upper Respiratory Tract Infections | measles / morbillivirus | UKB self-reported | data_coding_6 | 1568 | caliber | |
Infections of the digestive system | measles / morbillivirus | UKB self-reported | data_coding_6 | 1568 | caliber | |
Infections of Other or unspecified organs | measles / morbillivirus | UKB self-reported | data_coding_6 | 1568 | caliber |
Arguably, this could also be mapped to ‘Infections of Other or unspecified organs’ too. I chose not to as it looked like this disease was meant to be used for ICD10 codes that did not fit into the remaining diseases listed above that specify an infectious site (e.g. ‘Lower Respiratory Tract infections’, ‘Meningitis’ etc).
Also, I did not map self-reported ‘primary biliary cirrhosis’ to CALIBER disease ‘Liver fibrosis, sclerosis and cirrhosis’:
ukb_self_report_non_cancer_to_caliber_map %>%
filter(code == "1506") %>%
qflextable()
disease | description | category | code_type | code | author | selected |
Liver fibrosis, sclerosis and cirrhosis | primary biliary cirrhosis | UKB self-reported | data_coding_6 | 1506 | caliber | |
Autoimmune liver disease | primary biliary cirrhosis | UKB self-reported | data_coding_6 | 1506 | caliber | Y |
I think that perhaps this should be mapped, however ICD10 ‘K74.3’ (‘Primary biliary cirrhosis’) is only listed by CALIBER under ‘Autoimmune liver disease’ (and not ‘Liver fibrosis, sclerosis and cirrhosis’).3
I decided not to map self-reported ‘hepatitis’ to any CALIBER disease, as the CALIBER diseases for hepatitis all describe a specific type of hepatitis:
ukb_self_report_non_cancer_to_caliber_map %>%
filter(code == "1155") %>%
qflextable()
disease | description | category | code_type | code | author | selected |
Infection of liver | hepatitis | UKB self-reported | data_coding_6 | 1155 | caliber | |
Other or unspecified infectious organisms | hepatitis | UKB self-reported | data_coding_6 | 1155 | caliber | |
Autoimmune liver disease | hepatitis | UKB self-reported | data_coding_6 | 1155 | caliber | |
Fatty Liver | hepatitis | UKB self-reported | data_coding_6 | 1155 | caliber |
Also, self-reported ‘bowel / intestinal perforation’:
ukb_self_report_non_cancer_to_caliber_map %>%
filter(code == "1600") %>%
qflextable()
disease | description | category | code_type | code | author | selected |
Bacterial Diseases (excl TB) | bowel / intestinal perforation | UKB self-reported | data_coding_6 | 1600 | caliber | |
Infections of the digestive system | bowel / intestinal perforation | UKB self-reported | data_coding_6 | 1600 | caliber | |
Peritonitis | bowel / intestinal perforation | UKB self-reported | data_coding_6 | 1600 | caliber | |
Benign neoplasm of colon, rectum, anus and anal canal | bowel / intestinal perforation | UKB self-reported | data_coding_6 | 1600 | caliber |
Also, ‘angina’:4
ukb_self_report_non_cancer_to_caliber_map %>%
filter(code == "1074") %>%
qflextable()
disease | description | category | code_type | code | author | selected |
Unstable Angina | angina | UKB self-reported | data_coding_6 | 1074 | caliber | |
Stable angina | angina | UKB self-reported | data_coding_6 | 1074 | caliber |
ukb_self_report_non_cancer_to_caliber_map %>%
reactable(filterable = TRUE,
searchable = TRUE,
paginationType = "jump",
showPageSizeOptions = TRUE,
pageSizeOptions = c(10, 25, 50, 100, 200, 300, 350))
sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur/Monterey 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] flextable_0.7.0 codemapper_0.0.0.9001 targets_0.12.0
[4] crosstalk_1.2.0 readxl_1.4.0 reactable_0.3.0
[7] forcats_0.5.1 stringr_1.4.0 dplyr_1.0.9
[10] purrr_0.3.4 readr_2.1.2 tidyr_1.2.0
[13] tibble_3.1.7 ggplot2_3.3.5 tidyverse_1.3.1
[16] workflowr_1.7.0
loaded via a namespace (and not attached):
[1] fs_1.5.2 bit64_4.0.5 lubridate_1.8.0
[4] httr_1.4.2 rprojroot_2.0.3 tools_4.2.0
[7] backports_1.4.1 bslib_0.3.1 utf8_1.2.2
[10] R6_2.5.1 DBI_1.1.2 colorspace_2.0-3
[13] withr_2.5.0 tidyselect_1.1.2 processx_3.5.3
[16] bit_4.0.4 compiler_4.2.0 git2r_0.30.1
[19] cli_3.3.0 rvest_1.0.2 xml2_1.3.3
[22] officer_0.4.2 sass_0.4.1 scales_1.2.0
[25] callr_3.7.0 systemfonts_1.0.4 digest_0.6.29
[28] rmarkdown_2.14 base64enc_0.1-3 pkgconfig_2.0.3
[31] htmltools_0.5.2 dbplyr_2.2.0 fastmap_1.1.0
[34] highr_0.9 htmlwidgets_1.5.4 rlang_1.0.2
[37] RSQLite_2.2.14 rstudioapi_0.13 shiny_1.7.1
[40] jquerylib_0.1.4 generics_0.1.2 jsonlite_1.8.0
[43] vroom_1.5.7 zip_2.2.0 magrittr_2.0.3
[46] Rcpp_1.0.8.3 munsell_0.5.0 fansi_1.0.3
[49] gdtools_0.2.4 lifecycle_1.0.1 stringi_1.7.6
[52] whisker_0.4 yaml_2.3.5 blob_1.2.3
[55] grid_4.2.0 parallel_4.2.0 promises_1.2.0.1
[58] crayon_1.5.1 haven_2.5.0 hms_1.1.1
[61] knitr_1.39 ps_1.7.0 pillar_1.7.0
[64] uuid_1.1-0 igraph_1.3.1 base64url_1.4
[67] codetools_0.2-18 reprex_2.0.1 glue_1.6.2
[70] evaluate_0.15 getPass_0.2-2 ukbwranglr_0.0.0.9000
[73] data.table_1.14.2 renv_0.13.2 modelr_0.1.8
[76] vctrs_0.4.1 tzdb_0.3.0 httpuv_1.6.5
[79] cellranger_1.1.0 gtable_0.3.0 reactR_0.4.4
[82] assertthat_0.2.1 cachem_1.0.6 xfun_0.30
[85] mime_0.12 xtable_1.8-4 broom_0.8.0
[88] later_1.3.0 memoise_2.0.1 ellipsis_0.3.2
[91] here_1.0.1
Note that codemapper expands 3 character ICD10 codes to include all children.↩︎
I think this could be improved however - other ‘H40’ ICD10 codes should be included under ‘Glaucoma’, and the categories refined to ‘primary’, ‘secondary’, ‘open angle’, ‘closed angle’ etc.↩︎
Suggest that ideally this should be updated in CALIBER at some point.↩︎
The CALIBER codelist for ‘Stable angina’ includes ICD10 codes ‘I201’ and ‘I208’, which are not specific to stable angina - perhaps this should be updated at some point (e.g. merge ‘Stable angina’ and ‘Unstable angina’ into a single disease category, and create subcategories for ‘stable’, ‘unstable’, ‘unspecified’ or ‘other’ variants).↩︎