Setup

# Load environment file
source(here::here("setup_environment.R"))

# Tidylog messages make notebook output messy
detach("package:tidylog", unload = TRUE)

library(glue)      # for glue()
library(DT)        # for tables

source("checking_functions.R")
get_t1_data = function(date_str, sheet_name = "Raw Data"){

  path = glue("{data_folder}{date_str}/output/{date_str}-Table1-HSMR.xlsx")

  data = 
    read.xlsx(path, sheet = sheet_name) %>%
    select(deaths, pred, pats, smr, crd_rate, location_type, location, 
           location_name)

  return(data)

}

t1_old = get_t1_data(previous_pub)
t1_new = get_t1_data(pub_day)

Check Scotland

scot_data = filter(t1_new, location_name == "Scotland")

print(scot_data)

Compare to previous publication

We do expect there to be differences from the previous release, since they cover different time periods - but any drastic differences may be cause for further investigation.

Get a dataframe with the change from the last publication:

# Columns containing the labels
join_cols = c("location_type", "location", "location_name")

t1_diff = compare_df(t1_new, t1_old, join_by = join_cols, 
                     df1_name = "new", df2_name = "old")

Patients

t1_diff_px = 
  t1_diff %>%
  select(any_of(join_cols), starts_with("pats"))

writeLines(glue("Max % diff: {max(t1_diff_px[, 'pats.diff_pc'])}
                 Min % diff: {min(t1_diff_px[, 'pats.diff_pc'])}"))
make_change_table(t1_diff_px, measure = "pats", quarter_filter = "all")

Deaths

t1_diff_deaths = 
  t1_diff %>%
  select(any_of(join_cols), starts_with("deaths"))

writeLines(glue("Max % diff: {max(t1_diff_deaths[, 'deaths.diff_pc'])}
                 Min % diff: {min(t1_diff_deaths[, 'deaths.diff_pc'])}"))
make_change_table(t1_diff_deaths, measure = "deaths", quarter_filter = "all")


Public-Health-Scotland/hsmr documentation built on June 24, 2024, 1:48 a.m.