Waiting lists

Introduction

The issue

What the politicians say

What the data says

Code
library(readxl)
url <- "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/06/RTT-Overview-Timeseries-Including-Estimates-for-Missing-Trusts-Apr24-XLS-105K-11417.xlsx"
destfile <- basename(url)
curl::curl_download(url, destfile)
wl_df <- read_xlsx(destfile, skip = 11) |>
    mutate(mo = janitor::excel_numeric_to_date(parse_number(...2)))|>
    janitor::clean_names() |>
    select(mo, everything()) |>
    filter(mo >= "2007-08-01") 

wl_df |>
    ggplot() +
    geom_line(aes(mo, as.numeric(median_wait_weeks_3))) +
    geom_smooth(aes(mo, as.numeric(median_wait_weeks_3)), method = "loess")

Code
needs(prophet)

wl_df_pr <- wl_df |>
    select(ds = mo, 
           y = x92nd_percentile_weeks) |>
    mutate(y = as.numeric(y))

m <- prophet(wl_df_pr)
fut <- make_future_dataframe(m, periods = 13)

forecast <- predict(m, fut)

forecast_aug <- forecast |>
    left_join(wl_df, by = c("ds" = "mo")) |>
    mutate(estimated_number_of_unique_patients_mil = as.numeric(estimated_number_of_unique_patients_mil))

plot(m, forecast) + prophet::add_changepoints_to_plot(m, threshold = 0.05) +
    #geom_line(data = forecast_aug, aes(ds, estimated_number_of_unique_patients_mil), colour = "blue") +
    geom_vline(xintercept = c(as.POSIXct("2010-05-06"), as.POSIXct("2015-05-07"), as.POSIXct("2017-06-08"), as.POSIXct("2019-12-09"), as.POSIXct("2020-03-23"))) +
    geom_vline(xintercept = as.POSIXct("2023-12-20"), colour = "green") +
    ggthemes::theme_economist() +
    scale_y_continuous(position = "right", 
                       label = scales::number) 

Code
prophet_plot_components(m, forecast)

Code
needs(qicharts2)

wl_df <- wl_df |>
    filter(!is.na(total_waiting_mil)) 

qicharts2::qic(data = wl_df, x = mo, y = as.numeric(x92nd_percentile_weeks), chart = "i", part = c(15, 34, 93, 148, 153, 190))

Code
wl <- "https://www.england.nhs.uk/statistics/statistical-work-areas/rtt-waiting-times/"

wl_pl <- get_page_links(wl)[c(177, 179:191)]
wl_xls <- map(wl_pl, get_page_csvs) |>
    map_dfr(enframe)

tmpd <- tempdir()

test <- wl_xls |>
    filter(str_detect(value, "/Adm")) 

t <- curl::curl_download(test$value[1], destfile = basename(test$value[1]))

readxl::read_xlsx(t, skip = 13)

here::here()

readxl::read_excel(paste0(here::here("opendata"), "/",t[2]))