Competition - hospital readmissions
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    Reducing hospital readmissions

    📖 Background

    You work for a consulting company helping a hospital group better understand patient readmissions. The hospital gave you access to ten years of information on patients readmitted to the hospital after being discharged. The doctors want you to assess if initial diagnoses, number of procedures, or other variables could help them better understand the probability of readmission.

    They want to focus follow-up calls and attention on those patients with a higher probability of readmission.

    💾 The data

    You have access to ten years of patient information (source):

    Information in the file
    • "age" - age bracket of the patient
    • "time_in_hospital" - days (from 1 to 14)
    • "n_procedures" - number of procedures performed during the hospital stay
    • "n_lab_procedures" - number of laboratory procedures performed during the hospital stay
    • "n_medications" - number of medications administered during the hospital stay
    • "n_outpatient" - number of outpatient visits in the year before a hospital stay
    • "n_inpatient" - number of inpatient visits in the year before the hospital stay
    • "n_emergency" - number of visits to the emergency room in the year before the hospital stay
    • "medical_specialty" - the specialty of the admitting physician
    • "diag_1" - primary diagnosis (Circulatory, Respiratory, Digestive, etc.)
    • "diag_2" - secondary diagnosis
    • "diag_3" - additional secondary diagnosis
    • "glucose_test" - whether the glucose serum came out as high (> 200), normal, or not performed
    • "A1Ctest" - whether the A1C level of the patient came out as high (> 7%), normal, or not performed
    • "change" - whether there was a change in the diabetes medication ('yes' or 'no')
    • "diabetes_med" - whether a diabetes medication was prescribed ('yes' or 'no')
    • "readmitted" - if the patient was readmitted at the hospital ('yes' or 'no')

    Acknowledgments: Beata Strack, Jonathan P. DeShazo, Chris Gennings, Juan L. Olmo, Sebastian Ventura, Krzysztof J. Cios, and John N. Clore, "Impact of HbA1c Measurement on Hospital Readmission Rates: Analysis of 70,000 Clinical Database Patient Records," BioMed Research International, vol. 2014, Article ID 781670, 11 pages, 2014.

    suppressPackageStartupMessages(library(tidyverse))
    suppressPackageStartupMessages(library(tidymodels))
    (readmissions <- readr::read_csv('data/hospital_readmissions.csv', show_col_types = FALSE))
    # Plot theme
    theme_set(
        theme_bw() +
        theme(text = element_text(size = 16),
              axis.text.x = element_text(angle = -20))
             )
    glimpse(readmissions)
    readmissions %>%
        map(~ sort(unique(.x), na.last = FALSE))

    💪 Competition challenge

    Create a report that covers the following:

    1. What is the most common primary diagnosis by age group?
    2. Some doctors believe diabetes might play a central role in readmission. Explore the effect of a diabetes diagnosis on readmission rates.
    3. On what groups of patients should the hospital focus their follow-up efforts to better monitor patients with a high probability of readmission?

    Q1. What is the most common primary diagnosis by age group?

    As follows, the most common primary diagnosis in every age group except 40-50 is "Circularoty". The most common primary diagnosis in the youngest age group is "Other".

    readmissions %>%
        group_by(age) %>%
        count(
            name = "n",
            diag_1,
            sort = TRUE
             ) %>%
    	slice_max(order_by = n,
                 n = 1)
    readmissions %>%
        group_by(age) %>%
        count(
            name = "n",
            diag_1,
            sort = TRUE
             ) %>%
    	slice_max(order_by = n,
                 n = 5) %>%
    	ggplot(aes(
            x = age,
            y = n,
            fill = diag_1
                  )) +
    		geom_col(position = "fill") +
    		labs(
                x = "Age group",
                y = "Proportion",
                fill = "Diagnosis group",
                title = "Diagnosis group proportions by age"
                ) +
    		coord_flip()

    Q2. Exploratory analysis of diabetes patients

    (Readmissions <-
     	readmissions %>%
        mutate(
            id = row_number(),
            age = paste0(str_sub(age, 2, 3), "'s") %>% factor()
               ) %>%
        mutate(across(where(is.character), factor)) %>%
     	mutate(
            all_visits = n_emergency + n_inpatient + n_outpatient,
            multi_visits = ifelse(all_visits > 1, "Multiple", "Else")
              ) %>%
    	mutate(across(starts_with("n_"), ~ifelse(. == 0, "None", "Any") %>%
                      factor(levels = c("Any", "None")))) %>%
     	mutate(
            n_visits = ifelse(
                n_emergency == "Any" | n_outpatient == "Any" | n_inpatient == "Any",
                "Any", "None"
                             ) %>% factor(levels = c("Any", "None"))
              ) %>%
    	select(
            id,
            readmitted,
            time_in_hospital,
            starts_with("n_"),
            all_visits,
            multi_visits,
            medical_specialty,
            diag_1,
            glucose_test,
            A1Ctest,
            diabetes_med,
            -n_lab_procedures,
            -n_medications
              ))
    Readmissions %>%
    	ggplot(aes(
            x = time_in_hospital,
            fill = readmitted
                  )) +
    		geom_density(alpha = .3, bw = .5) +
    		geom_vline(xintercept = 3.5, linetype = 2) +
    		scale_x_continuous(n.breaks = 14)
    Readmissions %>%
    	pivot_longer(
            cols = n_procedures:n_visits,
            names_to = "Variable",
            values_to = "Value"
                    ) %>%
    	ggplot(aes(
            fill = readmitted,
            x = Value
                  )) +
    		geom_bar(position = "fill") +
    		facet_wrap(Variable ~ ., scales = "free_x") +
    		coord_flip()
    Readmissions %>%
    	ggplot(aes(
            x = all_visits + 1,
            fill = readmitted
                  )) +
    		geom_density(alpha = .3, bw = .25) +
    		geom_vline(xintercept = 2, linetype = 2) +
    		scale_x_continuous(breaks = c(1, 2, 3, 4, 5, 6, 11, 21, 31, 51), labels = ~. - 1, trans = "log10") +
    		labs(x = "Any visits")
    ‌
    ‌
    ‌