Frequency and prognostic outcomes of emergency diagnosis in 13 non-neoplastic conditions in England: A population-based cohort study using linked electronic health records of 1.7 million patients.
The 7 matches
- [1] § Methods › Study population ↔ C2_run_analyses.Rmd, lines 584–633 · score 0.81 · axial spondyloarthritis, rheumatoid arthritis, multiple sclerosis, Lyme disease, coeliac disease, MS
- [2] § Results › Association with prognosis ↔ C2_run_analyses.Rmd, lines 584–633 · score 0.68 · brain tumours, colon cancer, Lyme disease, coeliac disease, MS, tuberculosis
- [3] § Results › Frequency and characteristics of emergency diagnosis ↔ C2_run_analyses.Rmd, lines 635–699 · score 0.66 · 31–35, 66–70, pancreatic cancer, Lyme disease, schizophrenia, age
- [4] § Results › Association with prognosis ↔ C3_report_EDs.Rmd, lines 835–910 · score 0.63 · brain tumours, colon cancer, year mortality, emergency diagnosis, tuberculosis, schizophrenia
- [5] § Results › Association with prognosis ↔ C2_run_analyses.Rmd, lines 701–759 · score 0.56 · axial spondyloarthritis, multiple sclerosis, coeliac disease, Parkinson, SBE, PCOS
- [6] § Results › Frequency and characteristics of emergency diagnosis ↔ C3_report_EDs.Rmd, lines 216–268 · score 0.54 · 31–35, 66–70, deprivation, pancreatic, schizophrenia, Lyme
- [7] § Methods › Statistical analyses ↔ C3_report_EDs.Rmd, lines 216–268 · score 0.50 · IMD twentile, 81–90, age, diagnosis
Paper
Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC
The paper is loaded when this pane is shown.
The authors' code
R Markdown · 765 lines · 33 KB · MIT · 4 matches
- ---
- title: "Emergency diagnoses - basic frequency and analyses"
- author: "Emma Whitfield"
- date: "`r Sys.Date()`"
- output: word_document
- ---
- ```{r setup, include=FALSE}
- knitr::opts_chunk$set(echo = TRUE)
- library(tidyverse)
- library(flextable)
- library(gtsummary)
- library(lubridate)
- library(RMySQL)
- library(glue)
- library(lmtest)
- library(glmmTMB)
- library(boot)
- source('A0_global_vars_R.R')
- sensitivity_analysis <- F # to run sensitivity analysis 1 set to TRUE and offset to FALSE
- offset <- F # to run sensitivity analysis 2 set to TRUE and sensitivity_analysis to FALSE
- exclude_covid <- F # to exclude potential covid bias on prognosis set to TRUE
- td <- today()
- results_filepath <- glue("{results_filepath}{td}")
- if (!file.exists(results_filepath)) {
- dir.create(file.path(results_filepath))
- }
- if (sensitivity_analysis) {
- results_filepath <- glue("{results_filepath}/sensitivity_analysis")
- if (!file.exists(results_filepath)) {
- dir.create(file.path(results_filepath))
- }
- }
- if (offset) {
- results_filepath <- glue("{results_filepath}/offset")
- if (!file.exists(results_filepath)) {
- dir.create(file.path(results_filepath))
- }
- }
- if (exclude_covid) {
- results_filepath <- glue("{results_filepath}/exclude_covid")
- if (!file.exists(results_filepath)) {
- dir.create(file.path(results_filepath))
- }
- }
- if (sensitivity_analysis) {
- ED_defn <- 'emergency hospital admission or A&E attendance'
- } else {
- ED_defn <- 'emergency hospital admission'
- }
- ```
- ```{r display, echo=FALSE, fig.align = "center", warning = FALSE, message = FALSE, results = "asis", fig.width = 16, fig.height = 12}
- if (sensitivity_analysis) {
- cat('# Sensitivity analysis\n')
- }
- if (offset) {
- cat('# Offset death\n')
- }
- if (exclude_covid) {
- cat('# Exclude 2019 diagnoses\n')
- }
- # 1. Useful functions ----
- extract_EDs <- function(pln, condition) {
- db <- dbConnect(
- MySQL(),
- host = host,
- user = user,
- password = password,
- dbname = dbname,
- port = port
- )
- # extract patients and followup
- pat_query <- dbSendQuery(conn = db,
- statement = glue('select * from {sql_schema}.{pln}_{condition}_patients;'))
- patients <- fetch(pat_query, n = -1)
- dbClearResult(pat_query)
- fup_query <- dbSendQuery(conn = db,
- statement = glue('select * from {sql_schema}.{pln}_{condition}_admissions;'))
- admit <- fetch(fup_query, n = -1)
- dbClearResult(fup_query)
- if (sensitivity_analysis) {
- # also get attendances
- fup_query <- dbSendQuery(conn = db,
- statement = glue('select * from {sql_schema}.{pln}_{condition}_attends;'))
- attend <- fetch(fup_query, n = -1)
- dbClearResult(fup_query)
- }
- launders_query <- dbSendQuery(conn = db,
- statement = glue('select * from {sql_schema}.{pln}_{condition}_launders;'))
- launders <- fetch(launders_query, n = -1)
- dbClearResult(launders_query)
- death_query <- dbSendQuery(conn = db,
- statement = glue('select * from {sql_schema}.{pln}_{condition}_death;'))
- death <- fetch(death_query, n = -1)
- dbClearResult(death_query)
- dbDisconnect(db)
- rm(list = c("pat_query", "fup_query", "launders_query", "death_query"))
- patients <- patients %>%
- mutate(diagdate = ymd(diagdate),
- startdate = ymd(startdate),
- enddate = ymd(enddate),
- deathdate = ymd(deathdate)) %>%
- mutate(imd = as.numeric(imd))
- # restrict to only patients diagnosed in relevant periods if needed
- if (sensitivity_analysis) {
- patients <- patients %>%
- filter(diagdate >= ymd('2007-05-01'))
- } else if (exclude_covid) {
- patients <- patients %>%
- filter(diagdate < ymd('2019-01-01'))
- }
- # make sure there are no extra patients
- cases <- unique(patients$patid)
- admit <- admit %>%
- filter(patid %in% cases)
- launders <- launders %>%
- filter(patid %in% cases)
- death <- death %>%
- filter(patid %in% cases)
- launders <- launders %>%
- mutate(recorddate = ymd(recorddate))
- admit <- admit %>%
- mutate(admidate = ymd(admidate)) %>%
- select(-description)
- # add time to diagnosis
- admit_ttd <- admit %>%
- distinct(patid, admidate, .keep_all = T) %>%
- left_join(patients %>% select(patid, diagdate, yob) %>% distinct(), by = join_by(patid)) %>%
- mutate(ttd = as.numeric(difftime(diagdate, admidate, units = "days")))
- # get emergency event closest to diagnosis for each patient
- latest_admit <- admit_ttd %>%
- group_by(patid) %>%
- summarise(earliest_ttd = min(ttd)) %>%
- filter(earliest_ttd <= 30)
- # identify ED patients
- if (sensitivity_analysis) {
- attend <- attend %>%
- filter(patid %in% cases)
- attend <- attend %>%
- mutate(arrivaldate = ymd(arrivaldate)) %>%
- select(-aepatgroup)
- attend_ttd <- attend %>%
- distinct(patid, arrivaldate, .keep_all = T) %>%
- left_join(patients %>% select(patid, diagdate, yob) %>% distinct(), by = join_by(patid)) %>%
- mutate(ttd = as.numeric(difftime(diagdate, arrivaldate, units = "days")))
- latest_attend <- attend_ttd %>%
- group_by(patid) %>%
- summarise(earliest_ttd = min(ttd)) %>%
- filter(earliest_ttd <= 30)
- patients_admit <- patients %>%
- mutate(ED = patid %in% c(latest_admit$patid, latest_attend$patid))
- } else {
- patients_admit <- patients %>%
- mutate(ED = patid %in% latest_admit$patid)
- }
- # get comorbidity score at six months before diagnosis date
- launders <- launders %>%
- filter(ttd >= 180) %>%
- group_by(patid) %>%
- summarise(comorb_score = n_distinct(comorbidity)) %>%
- select(patid, comorb_score)
- patients_admit <- patients_admit %>%
- left_join(launders, by = join_by(patid)) %>%
- mutate(comorb_score = replace_na(comorb_score, 0))
- patients_admit <- patients_admit %>%
- mutate(diagyear = year(diagdate),
- gender = case_when(gender == 1 ~ 'Men',
- gender == 2 ~ 'Women',
- gender == 3 ~ 'Indeterminate',
- gender == 4 ~ 'Unknown',
- gender == 0 ~ 'Data not entered',
- T ~ as.character(gender)),
- diagage = diagyear - yob,
- datasource = case_when(str_detect(datasource, 'ons') ~ 'ons',
- T ~ datasource)) %>%
- select(patid, ED, diagyear, datasource, diagage, gender, comorb_score, imd, diagdate, deathdate)
- # append prognosis
- patients_admit <- patients_admit %>%
- left_join(death, by = join_by(patid))
- return(patients_admit)
- }
- append_hospitalisations <- function(patients_admit, pln, condition) {
- db <- dbConnect(
- MySQL(),
- host = host,
- user = user,
- password = password,
- dbname = dbname,
- port = port
- )
- hosp_query <- dbSendQuery(conn = db,
- statement = glue('select * from {sql_schema}.{pln}_{condition}_hosp;'))
- hosp_records <- fetch(hosp_query, n = -1)
- dbClearResult(hosp_query)
- dbDisconnect(db)
- rm(hosp_query)
- # make sure no extra patients
- cases <- unique(patients_admit$patid)
- hosp_records <- hosp_records %>%
- filter(patid %in% cases)
- # prepare hospital counts
- # make sure not counting any night twice
- hosp_records <- hosp_records %>%
- mutate(diagdate = ymd(diagdate),
- admidate = ymd(admidate),
- discharged = ymd(discharged)) %>%
- group_by(patid) %>%
- arrange(desc(admidate)) %>%
- mutate(next_admission = lag(admidate)) %>%
- ungroup() %>%
- mutate(admidate = if_else(admidate <= diagdate, diagdate + days(1), admidate),
- discharged = if_else(!is.na(next_admission) & (discharged > next_admission), next_admission, discharged),
- discharged = if_else(discharged > diagdate + days(365), diagdate + days(365), discharged))
- # remove stays that start and end on same day - counting number of nights stayed
- hosp_records <- hosp_records %>%
- filter(admidate < discharged) %>%
- mutate(tih = as.integer(difftime(discharged, admidate, units = "days")))
- hosp_summary <- hosp_records %>%
- group_by(patid) %>%
- summarise(total_tih = sum(tih),
- n_admissions = n())
- # now add to patients_admit
- patients_admit <- patients_admit %>%
- left_join(hosp_summary, by = join_by(patid)) %>%
- mutate(total_tih = replace_na(total_tih, 0),
- n_admissions = replace_na(n_admissions, 0))
- return(patients_admit)
- }
- assess_prognosis <- function(patients_admit, pln, condition) {
- # restrict to patients who didn't die on diagnosis date
- no_death <- patients_admit %>%
- filter((diagdate != deathdate) | is.na(deathdate),
- !is.na(imd)) %>%
- mutate(datasource = as.factor(datasource),
- diagyear = diagyear - 1999)
- no_death <- no_death %>%
- mutate(death.bin = (!is.na(death)) & (death > 0) & (death <= 365),
- death_offset = ifelse(death.bin, death, 365))
- # function to bootstrap excess mortality for confidence intervals
- excess_mort <- function(data, indices) {
- d <- data[indices,]
- obs_temp <- d %>%
- group_by(ED) %>%
- summarise(n.pats = n(),
- n.death = sum(death.bin)) %>%
- mutate(prop.death = 100*n.death/n.pats)
- return(obs_temp$prop.death[obs_temp$ED] - obs_temp$prop.death[!obs_temp$ED])
- }
- # if main analysis estimate the excess mortality in ED vs non-ED patients
- if (!(offset | sensitivity_analysis | exclude_covid)) {
- excess_mort_res <- boot(data = no_death, statistic = excess_mort, R = 1000)
- excess_mort_ci <- boot.ci(excess_mort_res, type = "norm")
- }
- # function to bootstrap excess time in hospital
- excess_tih <- function(data, indices) {
- d <- data[indices,]
- obs_temp <- d %>%
- group_by(ED) %>%
- summarise(mean.time = mean(total_tih))
- return(obs_temp$mean.time[obs_temp$ED] - obs_temp$mean.time[!obs_temp$ED])
- }
- # if main analysis estimate the excess tih in ED vs non-ED patients
- if (!(offset | sensitivity_analysis | exclude_covid)) {
- excess_tih_res <- boot(data = no_death, statistic = excess_tih, R = 1000)
- excess_tih_ci <- boot.ci(excess_tih_res, type = "norm")
- }
- obs <- no_death %>%
- group_by(ED) %>%
- summarise(n.pats = n(),
- n.death = sum(death.bin),
- n.admitted = sum(n_admissions > 0),
- mean.admit = mean(n_admissions),
- mean.time = mean(total_tih)) %>%
- mutate(prop.death = 100*n.death/n.pats,
- prop.admitted = 100*n.admitted/n.pats)
- # calculate by diagyr but suppress anything for fewer than 10 patients
- obs_diagyr <- no_death %>%
- group_by(ED, diagyear) %>%
- summarise(n.pats = n(),
- n.death = sum(death.bin),
- n.admitted = sum(n_admissions > 0),
- mean.admit = mean(n_admissions),
- mean.time = mean(total_tih)) %>%
- mutate(prop.death = ifelse(n.death >= 10, 100*n.death/n.pats, NA),
- prop.admitted = ifelse(n.admitted >= 10, 100*n.admitted/n.pats, NA),
- mean.admit = ifelse(n.admitted >= 10, mean.admit, NA),
- mean.time = ifelse(n.admitted >= 10, mean.time, NA))
- # fit death models
- m1 <- glm(death.bin ~ ED + diagage + diagyear + imd + comorb_score + datasource,
- data = no_death,
- family = binomial(link = "logit"))
- death.int <- exp(confint(m1, "EDTRUE"))
- m2 <- glm(death.bin ~ ED,
- data = no_death,
- family = binomial(link = "logit"))
- death.crude.int <- exp(confint(m2, "EDTRUE"))
- # fit hospitalisation models
- if (offset) {
- m3 <- glmmTMB(total_tih ~ ED + diagage + diagyear + imd + comorb_score + datasource + offset(log(death_offset)),
- data = no_death,
- family = nbinom2)
- m4 <- glmmTMB(total_tih ~ ED + offset(log(death_offset)),
- data = no_death,
- family = nbinom2)
- } else {
- m3 <- glmmTMB(total_tih ~ ED + diagage + diagyear + imd + comorb_score + datasource,
- data = no_death,
- family = nbinom2)
- m4 <- glmmTMB(total_tih ~ ED,
- data = no_death,
- family = nbinom2)
- }
- time.int <- exp(confint(m3, "EDTRUE"))
- time.crude.int <- exp(confint(m4, "EDTRUE"))
- if (!(offset | sensitivity_analysis | exclude_covid)) {
- main_prog <- tibble(n.ED = obs$n.pats[obs$ED], n.EDdeath = obs$n.death[obs$ED], death.obs_true = obs$prop.death[obs$ED], n.NED = obs$n.pats[!obs$ED], n.NEDdeath = obs$n.death[!obs$ED], death.obs_false = obs$prop.death[!obs$ED], death.crude = exp(coef(m2)[2]), death.lowcrude = death.crude.int[1], death.upcrude = death.crude.int[2], death = exp(coef(m1)[2]), death.low = death.int[1], death.up = death.int[2], excess.mort = excess_mort_res$t0, excess.lowmort = excess_mort_ci$normal[2], excess.upmort = excess_mort_ci$normal[3], n.EDadmitted = obs$n.admitted[obs$ED], perc.EDadmitted = obs$prop.admitted[obs$ED], time.obs_true = obs$mean.time[obs$ED], n.NEDadmitted = obs$n.admitted[!obs$ED], perc.NEDadmitted = obs$prop.admitted[!obs$ED], time.obs_false = obs$mean.time[!obs$ED], time.crude = time.crude.int[3], time.lowcrude = time.crude.int[1], time.upcrude = time.crude.int[2], time = time.int[3], time.low = time.int[1], time.up = time.int[2], excess.tih = excess_tih_res$t0, excess.lowtih = excess_tih_ci$normal[2], excess.uptih = excess_tih_ci$normal[3])
- } else {
- main_prog <- tibble(n.ED = obs$n.pats[obs$ED], n.EDdeath = obs$n.death[obs$ED], death.obs_true = obs$prop.death[obs$ED], n.NED = obs$n.pats[!obs$ED], n.NEDdeath = obs$n.death[!obs$ED], death.obs_false = obs$prop.death[!obs$ED], death.crude = exp(coef(m2)[2]), death.lowcrude = death.crude.int[1], death.upcrude = death.crude.int[2], death = exp(coef(m1)[2]), death.low = death.int[1], death.up = death.int[2], n.EDadmitted = obs$n.admitted[obs$ED], perc.EDadmitted = obs$prop.admitted[obs$ED], time.obs_true = obs$mean.time[obs$ED], n.NEDadmitted = obs$n.admitted[!obs$ED], perc.NEDadmitted = obs$prop.admitted[!obs$ED], time.obs_false = obs$mean.time[!obs$ED], time.crude = time.crude.int[3], time.lowcrude = time.crude.int[1], time.upcrude = time.crude.int[2], time = time.int[3], time.low = time.int[1], time.up = time.int[2])
- }
- return(list("main_prog" = main_prog, "diagyr_prog" = obs_diagyr))
- }
- assess_gender_prognosis <- function(patients_admit) {
- # compare gender association with death
- # restrict to patients who didn't die on diagnosis date
- no_death <- patients_admit %>%
- filter((diagdate != deathdate) | is.na(deathdate),
- !is.na(imd)) %>%
- mutate(datasource = as.factor(datasource),
- diagyear = diagyear - 1999)
- if (sum(!is.na(no_death$death) & (no_death$death < 0))) {
- errorCondition('Patient has deathdate before emergency diagnosis')
- }
- no_death <- no_death %>%
- mutate(death.bin = (!is.na(death)) & (death > 0) & (death <= 365),
- death_offset = ifelse(death.bin, death, 365))
- m1 <- glm(death.bin ~ ED + gender*(diagage + diagyear + imd + comorb_score + datasource),
- data = no_death,
- family = binomial(link = "logit"))
- m2 <- glm(death.bin ~ gender*(ED + diagage + diagyear + imd + comorb_score + datasource),
- data = no_death,
- family = binomial(link = "logit"))
- death.test <- lrtest(m1, m2)
- if (offset) {
- m3 <- glmmTMB(total_tih ~ ED + gender*(diagage + diagyear + imd + comorb_score + datasource) + offset(log(death_offset)),
- data = no_death,
- family = nbinom2)
- m4 <- glmmTMB(total_tih ~ gender*(ED + diagage + diagyear + imd + comorb_score + datasource) + offset(log(death_offset)),
- data = no_death,
- family = nbinom2)
- } else {
- m3 <- glmmTMB(total_tih ~ ED + gender*(diagage + diagyear + imd + comorb_score + datasource),
- data = no_death,
- family = nbinom2)
- m4 <- glmmTMB(total_tih ~ gender*(ED + diagage + diagyear + imd + comorb_score + datasource),
- data = no_death,
- family = nbinom2)
- }
- hosp.test <- lrtest(m3, m4)
- return(tibble(death.p = death.test$`Pr(>Chisq)`[2], hosp.p = hosp.test$`Pr(>Chisq)`[2]))
- }
- # 2. Loop to process data ----
- res <- tibble(gender = c(), pln = c(), condition = c(), ED = c(), n.pats = c(), ED.p = c())
- timeres <- tibble(gender = c(), pln = c(), condition = c(), diagyear = c(), prop = c(), low.ci = c(), up.ci = c())
- ageres <- tibble(gender = c(), pln = c(), condition = c(), diagage = c(), prop = c(), low.ci = c(), up.ci = c())
- imdres <- tibble(gender = c(), pln = c(), condition = c(), imd = c(), prop = c(), low.ci = c(), up.ci = c())
- prognosis <- tibble(gender = c(), pln = c(), condition = c(), n.ED = c(), n.EDdeath = c(), death.obs_true = c(), n.NED = c(), n.NEDdeath = c(), death.obs_false = c(), death.crude = c(), death.lowcrude = c(), death.upcrude = c(), death = c(), death.low = c(), death.up = c(), excess.mort = c(), excess.lowmort = c(), excess.upmort = c(), n.EDadmitted = c(), perc.EDadmitted = c(), time.obs_true = c(), n.NEDadmitted = c(), perc.NEDadmitted = c(), time.obs_false = c(), time.crude = c(), time.lowcrude = c(), time.upcrude = c(), time = c(), time.low = c(), time.up = c(), excess.tih = c(), excess.lowtih = c(), excess.uptih = c())
- diagyr_prognosis <- tibble(gender = c(), pln = c(), condition = c(), diagyear = c(), ED = c(), n.pats = c(), n.death = c(), n.admitted = c(), prop.death = c(), prop.admitted = c(), mean.admit = c(), mean.time = c())
- gender_diffs <- tibble(pln = c(), condition = c(), death.p = c(), hosp.p = c())
- tidy_res <- function(patients_admit, group_var, cond1, pln1) {
- patients_admit %>%
- group_by({{group_var}}, gender) %>%
- summarise(prop = 100*mean(ED, na.rm = T),
- low.ci = 100*prop.test(sum(ED), n())$conf.int[1],
- up.ci = 100*prop.test(sum(ED), n())$conf.int[2],
- n.ED = sum(ED),
- n.pats = n()) %>%
- mutate(condition = cond1,
- pln = pln1)
- }
- for (cond in conditions) {
- cat("# ", cond, "\n")
- for (plnx in c('gold', 'aurum')) {
- cat("## ", plnx, "\n")
- patients_admit <- extract_EDs(plnx, cond)
- patients_admit <- append_hospitalisations(patients_admit, plnx, cond)
- # ED frequency and trends
- if (!(cond %in% c('ovarian_cancer', 'PCOS'))) {
- patients_admit <- patients_admit %>%
- filter(gender %in% c('Men', 'Women'))
- # compare ED frequency
- EDcross <- table(patients_admit$ED, patients_admit$gender)
- EDp <- chisq.test(EDcross)
- if (any(EDp$expected < 5)) {
- cat("Warning - ", cond, "EP chi-sq has values less than 5")
- knitr::kable(EDp$expected)
- }
- temp_res <- patients_admit %>%
- group_by(gender) %>%
- summarise(ED = sum(ED),
- n.pats = n_distinct(patid)) %>%
- mutate(condition = cond,
- pln = plnx,
- ED.p = EDp$p.value)
- gender_diffs <- gender_diffs %>%
- rbind(assess_gender_prognosis(patients_admit) %>%
- mutate(condition = cond,
- pln = plnx))
- } else {
- temp_res <- patients_admit %>%
- group_by(gender) %>%
- summarise(ED = sum(ED),
- n.pats = n_distinct(patid)) %>%
- mutate(condition = cond,
- pln = plnx,
- ED.p = NA)
- }
- res <- res %>%
- rbind(temp_res)
- timeres <- timeres %>%
- rbind(tidy_res(patients_admit, diagyear, cond, plnx))
- ageres <- ageres %>%
- rbind(tidy_res(patients_admit %>%
- mutate(age_group = case_match(diagage,
- seq(0, 15) ~ "< 16",
- seq(16, 20) ~ "16-20",
- seq(21, 25) ~ "21-25",
- seq(26, 30) ~ "26-30",
- seq(31, 35) ~ "31-35",
- seq(36, 40) ~ "36-40",
- seq(41, 45) ~ "41-45",
- seq(46, 50) ~ "46-50",
- seq(51, 55) ~ "51-55",
- seq(56, 60) ~ "56-60",
- seq(61, 65) ~ "61-65",
- seq(66, 70) ~ "66-70",
- seq(71, 75) ~ "71-75",
- seq(76, 80) ~ "76-80",
- seq(81, 90) ~ "81-90",
- .default = "> 90")),
- age_group, cond, plnx))
- imdres <- imdres %>%
- rbind(tidy_res(patients_admit, imd, cond, plnx))
- for (gen in c('Men', 'Women')) {
- if (cond %in% c('ovarian_cancer', 'PCOS') & (gen == "Men")) next
- # patient characteristics
- cat("### ", gen, "\n")
- t <- patients_admit %>%
- filter(gender == gen) %>%
- mutate(imd5 = case_when(imd %in% seq(1, 4) ~ '1 - Least deprived',
- imd %in% seq(5, 8) ~ '2',
- imd %in% seq(9, 12) ~ '3',
- imd %in% seq(13, 16) ~ '4',
- imd %in% seq(17, 20) ~ '5 - Most deprived',
- T ~ as.character(imd))) %>%
- select(ED, diagage, comorb_score, imd5, datasource) %>%
- tbl_summary(by = ED,
- type = all_continuous() ~ "continuous2",
- statistic = list(
- all_continuous() ~ c("{mean} ({sd})", "{median} ({p25}, {p75})"),
- all_categorical() ~ "{n} ({p}%)"
- ),
- digits = list(all_continuous() ~ 1,
- all_categorical() ~ 1),
- label = list(diagage = "Age at diagnosis", comorb_score = "Comorbidity score", imd5 = "IMD quintile", datasource = "Source of diagnosis")) %>%
- add_n()
- cat("\n")
- cat(knitr::knit_print(t))
- # prognosis
- tmp_prog <- assess_prognosis(patients_admit %>%
- filter(gender == gen),
- plnx, cond)
- prognosis <- prognosis %>%
- rbind(tmp_prog$main_prog %>%
- mutate(gender = gen,
- condition = cond,
- pln = plnx))
- diagyr_prognosis <- diagyr_prognosis %>%
- rbind(tmp_prog$diagyr_prog %>%
- mutate(gender = gen,
- condition = cond,
- pln = plnx))
- }
- }
- }
- # clean up tables
- res <- res %>%
- rowwise() %>%
- mutate(prop = 100*prop.test(ED, n.pats)$estimate,
- low.ci = 100*prop.test(ED, n.pats)$conf.int[1],
- up.ci = 100*prop.test(ED, n.pats)$conf.int[2]) %>%
- mutate(s = glue("{signif(prop, 3)}% ({signif(low.ci, 3)}%, {signif(up.ci, 3)}%) {ED.p}")) %>%
- mutate(condition = case_match(condition,
- "AS" ~ "Axial spondyloarthritis",
- "brain_tumours" ~ "Brain tumours",
- "CHD" ~ "CHD",
- "COPD" ~ "COPD",
- "IBD" ~ "IBD",
- "MS" ~ "Multiple sclerosis",
- "PCOS" ~ "PCOS",
- "RA" ~ "Rheumatoid arthritis",
- "SBE" ~ "SBE",
- "TB" ~ "Tuberculosis",
- "celiac" ~ "Coeliac disease",
- "colon_cancer" ~ "Colon cancer",
- "lung_cancer" ~ "Lung cancer",
- "lyme" ~ "Lyme disease",
- "ovarian_cancer" ~ "Ovarian cancer",
- "pancreatic_cancer" ~ "Pancreatic cancer",
- "parkinsons" ~ "Parkinson's disease",
- "schizophrenia" ~ "Schizophrenia"))
- timeres <- timeres %>%
- mutate(grp = case_match(condition,
- c("AS", "brain_tumours", "celiac", "CHD", "colon_cancer", "COPD", "IBD", "lung_cancer", "lyme") ~ "1",
- .default = "2"),
- condition = case_match(condition,
- "AS" ~ "Axial spondyloarthritis",
- "brain_tumours" ~ "Brain tumours",
- "CHD" ~ "CHD",
- "COPD" ~ "COPD",
- "IBD" ~ "IBD",
- "MS" ~ "Multiple sclerosis",
- "PCOS" ~ "PCOS",
- "RA" ~ "Rheumatoid arthritis",
- "SBE" ~ "SBE",
- "TB" ~ "Tuberculosis",
- "celiac" ~ "Coeliac disease",
- "colon_cancer" ~ "Colon cancer",
- "lung_cancer" ~ "Lung cancer",
- "lyme" ~ "Lyme disease",
- "ovarian_cancer" ~ "Ovarian cancer",
- "pancreatic_cancer" ~ "Pancreatic cancer",
- "parkinsons" ~ "Parkinson's disease",
- "schizophrenia" ~ "Schizophrenia"))
- ageres <- ageres %>%
- mutate(age_group = factor(age_group, levels = c("< 16", "16-20", "21-25", "26-30", "31-35", "36-40", "41-45", "46-50", "51-55", "56-60", "61-65", "66-70", "71-75", "76-80", "81-90", "> 90"), ordered = T)) %>%
- mutate(age_mid = case_match(age_group,
- "< 16" ~ 8,
- "16-20" ~ 18,
- "21-25" ~ 23,
- "26-30" ~ 28,
- "31-35" ~ 33,
- "36-40" ~ 38,
- "41-45" ~ 43,
- "46-50" ~ 48,
- "51-55" ~ 53,
- "56-60" ~ 58,
- "61-65" ~ 63,
- "66-70" ~ 68,
- "71-75" ~ 73,
- "76-80" ~ 78,
- "81-90" ~ 85,
- "> 90" ~ 95),
- grp = case_match(condition,
- c("AS", "brain_tumours", "celiac", "CHD", "colon_cancer", "COPD", "IBD", "lung_cancer", "lyme") ~ "1",
- .default = "2"),
- condition = case_match(condition,
- "AS" ~ "Axial spondyloarthritis",
- "brain_tumours" ~ "Brain tumours",
- "CHD" ~ "CHD",
- "COPD" ~ "COPD",
- "IBD" ~ "IBD",
- "MS" ~ "Multiple sclerosis",
- "PCOS" ~ "PCOS",
- "RA" ~ "Rheumatoid arthritis",
- "SBE" ~ "SBE",
- "TB" ~ "Tuberculosis",
- "celiac" ~ "Coeliac disease",
- "colon_cancer" ~ "Colon cancer",
- "lung_cancer" ~ "Lung cancer",
- "lyme" ~ "Lyme disease",
- "ovarian_cancer" ~ "Ovarian cancer",
- "pancreatic_cancer" ~ "Pancreatic cancer",
- "parkinsons" ~ "Parkinson's disease",
- "schizophrenia" ~ "Schizophrenia"))
- imdres <- imdres %>%
- mutate(grp = case_match(condition,
- c("AS", "brain_tumours", "celiac", "CHD", "colon_cancer", "COPD", "IBD", "lung_cancer", "lyme") ~ "1",
- .default = "2"),
- condition = case_match(condition,
- "AS" ~ "Axial spondyloarthritis",
- "brain_tumours" ~ "Brain tumours",
- "CHD" ~ "CHD",
- "COPD" ~ "COPD",
- "IBD" ~ "IBD",
- "MS" ~ "Multiple sclerosis",
- "PCOS" ~ "PCOS",
- "RA" ~ "Rheumatoid arthritis",
- "SBE" ~ "SBE",
- "TB" ~ "Tuberculosis",
- "celiac" ~ "Coeliac disease",
- "colon_cancer" ~ "Colon cancer",
- "lung_cancer" ~ "Lung cancer",
- "lyme" ~ "Lyme disease",
- "ovarian_cancer" ~ "Ovarian cancer",
- "pancreatic_cancer" ~ "Pancreatic cancer",
- "parkinsons" ~ "Parkinson's disease",
- "schizophrenia" ~ "Schizophrenia"))
- prognosis <- prognosis %>%
- left_join(gender_diffs, by = join_by(condition, pln)) %>%
- mutate(condition = case_match(condition,
- "AS" ~ "Axial spondyloarthritis",
- "brain_tumours" ~ "Brain tumours",
- "CHD" ~ "CHD",
- "COPD" ~ "COPD",
- "IBD" ~ "IBD",
- "MS" ~ "Multiple sclerosis",
- "PCOS" ~ "PCOS",
- "RA" ~ "Rheumatoid arthritis",
- "SBE" ~ "SBE",
- "TB" ~ "Tuberculosis",
- "celiac" ~ "Coeliac disease",
- "colon_cancer" ~ "Colon cancer",
- "lung_cancer" ~ "Lung cancer",
- "lyme" ~ "Lyme disease",
- "ovarian_cancer" ~ "Ovarian cancer",
- "pancreatic_cancer" ~ "Pancreatic cancer",
- "parkinsons" ~ "Parkinson's disease",
- "schizophrenia" ~ "Schizophrenia"))
- diagyr_prognosis <- diagyr_prognosis %>%
- mutate(grp = case_match(condition,
- c("AS", "brain_tumours", "celiac", "CHD", "colon_cancer", "COPD", "IBD", "lung_cancer", "lyme") ~ "1",
- .default = "2"),
- condition = case_match(condition,
- "AS" ~ "Axial spondyloarthritis",
- "brain_tumours" ~ "Brain tumours",
- "CHD" ~ "CHD",
- "COPD" ~ "COPD",
- "IBD" ~ "IBD",
- "MS" ~ "Multiple sclerosis",
- "PCOS" ~ "PCOS",
- "RA" ~ "Rheumatoid arthritis",
- "SBE" ~ "SBE",
- "TB" ~ "Tuberculosis",
- "celiac" ~ "Coeliac disease",
- "colon_cancer" ~ "Colon cancer",
- "lung_cancer" ~ "Lung cancer",
- "lyme" ~ "Lyme disease",
- "ovarian_cancer" ~ "Ovarian cancer",
- "pancreatic_cancer" ~ "Pancreatic cancer",
- "parkinsons" ~ "Parkinson's disease",
- "schizophrenia" ~ "Schizophrenia"))
- # save all analysis results as csvs
- if (!offset) {
- write_csv(res, glue('{results_filepath}/res.csv'))
- write_csv(timeres, glue('{results_filepath}/timeres.csv'))
- write_csv(ageres, glue('{results_filepath}/ageres.csv'))
- write_csv(imdres, glue('{results_filepath}/imdres.csv'))
- write_csv(diagyr_prognosis, glue('{results_filepath}/diagyear_prognosis.csv'))
- }
- write_csv(prognosis, glue('{results_filepath}/prognosis.csv'))
- cat(glue('\nAll results saved at {results_filepath}'))
- cat('\nPlease update analysis_dt in A0_global_vars_R.R accordingly \n')
- ```
- ```{r session_info, echo=FALSE, message = FALSE, results = "asis"}
- cat('# Session information\n')
- print(sessionInfo())
- ```
C2_run_analyses.Rmd at commit a082a9d, under MIT · at the source
Overview
- ECHO (Epidemiology of Cancer Healthcare & Outcomes), Department of Behavioural Science and Health, Institute of Epidemiology and Health Care, UCL (University College London), London, United Kingdom
- Department of General Practice and Primary Care, University of Melbourne, Melbourne, Australia
- Cancer Intelligence, Cancer Research UK, London, United Kingdom
- Safety, Quality & Well-Being Institute, Houston Methodist, Houston, Texas, United States of America
- National Disease Registration Service, NHS England, Leeds, United Kingdom
- Institute of Health Informatics, UCL, London, United Kingdom
- Interdisciplinary Transformation University, Linz, Austria
- Health Data Research UK, London, United Kingdom
- UCL Hospitals Biomedical Research Centre, London, United Kingdom
- British Heart Foundation Data Science Centre, London, United Kingdom
Abstract
The abstract is not reproduced here: the paper's license (none stated) does not allow it. Read it in the paper, at the publisher or on Europe PMC.
Repositories
Its files are read in the Code ↔ Paper reader above, with 7 matches between paragraphs and lines of code.
Zenodo 13710755
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
- 27 September 2026: the link answers (HTTP 200)
Zenodo 16840511
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
- 27 September 2026: the link answers (HTTP 200)
9 files
- A0_global_vars_R.R — R, 17 lines
- A0_global_vars_py.py — Python, 8 lines
- B1_create_sql_extract_fo
llowup.py — Python, 39 lines - B3_create_sql_extract_pr
ognosis.py — Python, 29 lines - C1_table1.Rmd — R, 94 lines
- C2_run_analyses.Rmd — R, 765 lines
- C3_report_EDs.Rmd — R, 915 lines
- LICENSE — License, 21 lines
- README.md — Text, 64 lines
ekw26/atlas-phenotypes
92d97fb92c2624c5ec03159c2c94c17cb2b70e4b, 6 September 2024Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
ekw26/atlas-emergencies
a082a9d528f098780a249bcd82d04a64d1439973, 24 June 2026Availability: 1 check, the latest on 27 September 2026: the link answers
- 27 September 2026: the link answers
9 files
- A0_global_vars_R.R — R, 17 lines
- A0_global_vars_py.py — Python, 8 lines
- B1_create_sql_extract_fo
llowup.py — Python, 39 lines - B3_create_sql_extract_pr
ognosis.py — Python, 29 lines - C1_table1.Rmd — R, 94 lines
- C2_run_analyses.Rmd — R, 765 lines, 4 matches
- C3_report_EDs.Rmd — R, 915 lines, 3 matches
- LICENSE — License, 21 lines
- README.md — Text, 64 lines
Tracing map
Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.
What the map holds:
- 4 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
- 14 scripts, each with its path and the digest of its content;
- 7 matches between paragraphs of the paper and lines of the code (method lexical-v1);
- neither the text of the paper nor the code itself.
Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.
Data
No dataset and no data link were found in the paper.
Data availability statement
The paper has a data availability statement. Its license (none stated) does not allow reproducing it here; in short, from what the harvester recognized in it:
- no repository, dataset or request procedure was recognized in it
Read it in the paper: doi.org/10.1371/journal.pmed.1005182.
Versions
The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.
Version 1, 27 September 2026: the first record
Recorded: type, language, journal, volume, issue, pages, dates, 10 authors, 17 MeSH terms, 1 funder, 50 references.
Cite
This paper
Whitfield, E., White, B., Barclay, M. E., Rafiq, M., Zakkak, N., Berglund, M., Singh, H., McPhail, S., Denaxas, S., & Lyratzopoulos, G. (2026). Frequency and prognostic outcomes of emergency diagnosis in 13 non-neoplastic conditions in England: A population-based cohort study using linked electronic health records of 1.7 million patients. PLoS medicine, 23(8), e1005182. https://
BibTeX
@article{whitfield2026fr
author = {Whitfield, Emma and White, Becky and Barclay, Matthew E and Rafiq, Meena and Zakkak, Nadine and Berglund, Marta and Singh, Hardeep and McPhail, Sean and Denaxas, Spiros and Lyratzopoulos, Georgios},
title = {{Frequency and prognostic outcomes of emergency diagnosis in 13 non-neoplastic conditions in England: A population-based cohort study using linked electronic health records of 1.7 million patients}},
journal = {PLoS medicine},
year = {2026},
month = aug,
volume = {23},
number = {8},
pages = {e1005182},
publisher = {PLOS},
issn = {1549-1277},
doi = {10.1371/
url = {https://
pmid = {42640879},
pmcid = {PMC13505939}
}
RIS
TY - JOUR
AU - Whitfield, Emma
AU - White, Becky
AU - Barclay, Matthew E
AU - Rafiq, Meena
AU - Zakkak, Nadine
AU - Berglund, Marta
AU - Singh, Hardeep
AU - McPhail, Sean
AU - Denaxas, Spiros
AU - Lyratzopoulos, Georgios
TI - Frequency and prognostic outcomes of emergency diagnosis in 13 non-neoplastic conditions in England: A population-based cohort study using linked electronic health records of 1.7 million patients
T2 - PLoS medicine
J2 - PLoS Med
PY - 2026
DA - 2026/
VL - 23
IS - 8
SP - e1005182
SN - 1549-1277
PB - PLOS
DO - 10.1371/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1371/
"type": "article-journal",
"title": "Frequency and prognostic outcomes of emergency diagnosis in 13 non-neoplastic conditions in England: A population-based cohort study using linked electronic health records of 1.7 million patients",
"container-title": "PLoS medicine",
"author": [
{
"family": "Whitfield",
"given": "Emma"
},
{
"family": "White",
"given": "Becky"
},
{
"family": "Barclay",
"given": "Matthew E"
},
{
"family": "Rafiq",
"given": "Meena"
},
{
"family": "Zakkak",
"given": "Nadine"
},
{
"family": "Berglund",
"given": "Marta"
},
{
"family": "Singh",
"given": "Hardeep"
},
{
"family": "McPhail",
"given": "Sean"
},
{
"family": "Denaxas",
"given": "Spiros"
},
{
"family": "Lyratzopoulos",
"given": "Georgios"
}
],
"container-title-short":
"volume": "23",
"issue": "8",
"page": "e1005182",
"DOI": "10.1371/
"PMID": "42640879",
"PMCID": "PMC13505939",
"ISSN": "1549-1277",
"publisher": "PLOS",
"URL": "https://
"language": "en",
"issued": {
"date-parts": [
[
2026,
8,
25
]
]
}
}
The tracing map gets a citation of its own once an author has validated it and it has a DOI.
Similar papers
The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.
- [1] doi:10.1242/jeb.252086 [code]
- Transcriptional predictors of rescue behaviour in ants.Journal: The Journal of experimental biologyIn common: glmmTMB, patchwork, ggplot2, 1 other tool, 1 reference
- [2] doi:10.1038/s41514-026-00391-9 [code]
- Region-specific transcriptional signatures of brain aging in the absence of neuropathology at the single-cell level.Journal: npj agingIn common: glmmTMB, patchwork, ggplot2, 1 other tool, 1 reference
- [3] doi:10.3389/fnsyn.2026.1832103 [code]
- Automated ROI detection allows rapid quantification of synaptic activity across tens of thousands of synapses in cell culture.Journal: Frontiers in synaptic neuroscienceIn common: glmmTMB, ggplot2, tidyverse, 1 reference
- [4] doi:10.1038/s41467-026-76675-1 [code]
- Long-read proteogenomic atlas of human neuronal differentiation reveals isoform diversity informing neurodevelopmental risk mechanisms.Journal: Nature communicationsIn common: glmmTMB, patchwork, ggplot2, 1 other tool
- [5] doi:10.1093/braincomms/fcag217 [code]
- Investigation of stress hormones across multiday seizure cycles.Journal: Brain communicationsIn common: glmmTMB, patchwork, ggplot2, 1 other tool
- [6] doi:10.1038/s41586-026-10444-4 [code]
- A brain reward circuit inhibited by next-generation weight-loss drugs in mice.Journal: NatureIn common: glmmTMB, patchwork, ggplot2, 1 other tool
- [7] doi:10.3390/ijms27135713 [code]
- Chronic Administration of Marinobufagenin in Mice Causes Hyperlocomotion and Decrease in Anxiety by Altering Monoamine Turnover Unaccompanied by Motor Deficits or Oxidative Stress.Journal: International journal of molecular sciencesIn common: glmmTMB, patchwork, ggplot2, 1 other tool
- [8] doi:10.1016/j.celrep.2026.117505 [code]
- Impaired spatial coding and neuronal hyperactivity in the medial entorhinal cortex of aged APP knock-in mice.Journal: Cell reportsIn common: glmmTMB, patchwork, ggplot2, 1 other tool
- [9] doi:10.1038/s41467-026-76676-0 [code]
- Determinants of functional burden pleiotropy and gene dosage responses across human traits.Journal: Nature communicationsIn common: patchwork, ggplot2, tidyverse, 1 reference
- [10] doi:10.1038/s41514-026-00439-w [code]
- Effects of a three-month exercise programme on cognition, mood and neurogenesis: the NeuroFit randomised controlled trial.Journal: npj agingIn common: glmmTMB, ggplot2, tidyverse
Contribute
The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.
Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 4 repositories of the authors' code, each at its verified commit and with its license, 14 scripts, and 7 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:a0492eaa6252906b…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
Request its removal
To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).
Discussion, reproductions, activity
Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.
Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.
Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.
