Skip to content

Commit

Permalink
Merge pull request #36 from humaniverse/health-index-ics
Browse files Browse the repository at this point in the history
Health index ics
  • Loading branch information
matthewgthomas authored Dec 5, 2024
2 parents 37a8c78 + b3e3efc commit 3201c0b
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Description: A package to distribute and summarise on UK health data.
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Imports:
tibble
Depends:
Expand Down
55 changes: 54 additions & 1 deletion R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ NULL

#' England Health Index (ONS) - subdomains
#'
#' A dataset containing overall health index scores for the English lower tier
#' A dataset containing subdomain health index scores for the English lower tier
#' local authorities from 2015-2021.
#'
#' @format A data frame with 2,149 rows and 16 variables:
Expand Down Expand Up @@ -237,6 +237,59 @@ NULL
#' @source \url{https://www.ons.gov.uk/}
"england_health_index_indicators"

#' England Health Index (ONS)
#'
#' A dataset containing overall health index scores for the English Integrated
#' Care Boards from 2015-2021.
#'
#' @format A data frame with 294 rows and 7 variables:
#' \describe{
#' \item{icb22_code}{2022 Integrated Care Board code}
#' \item{icb22_name}{2022 Integrated Care Board name}
#' \item{year}{Year}
#' \item{overall_score}{The overall health index score}
#' \item{healthy_people_domain_score}{Score for the Healthy People domain}
#' \item{healthy_lives_domain_score}{Score for the Healthy Lives domain}
#' \item{healthy_places_domain_score}{Score for the Healthy Places domain}
#' ...
#' }
#' @source \url{https://www.ons.gov.uk/}
"england_health_index_ics"

#' England Health Index (ONS) - subdomains
#'
#' A dataset containing subdomain health index scores for the English Integrated
#' Care Boards from 2015-2021.
#'
#' @format A data frame with 4,116 rows and 5 variables:
#' \describe{
#' \item{icb22_code}{2022 Integrated Care Board code}
#' \item{icb22_name}{2022 Integrated Care Board name}
#' \item{year}{Year}
#' \item{sub_domain}{The name of the subdomain}
#' \item{value}{The value of the indicator}
#' ...
#' }
#' @source \url{https://www.ons.gov.uk/}
"england_health_index_ics_indicators"

#' England Health Index (ONS) - underlying indicators
#'
#' A dataset containing underlying indicators for the ONS Health Index for
#' English Integrated Care Boards from 2015-2021.
#'
#' @format A data frame with 16,464 rows and 5 variables:
#' \describe{
#' \item{icb22_code}{2022 Integrated Care Board code}
#' \item{icb22_name}{2022 Integrated Care Board name}
#' \item{year}{Year}
#' \item{indicator}{The name of the indicator}
#' \item{value}{The value of the indicator}
#' ...
#' }
#' @source \url{https://www.ons.gov.uk/}
"england_health_index_ics_indicators"

#' Legal Partnership Status, England, 2021
#'
#' A dataset containing legal partnership status data at LTLA level
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
92 changes: 92 additions & 0 deletions data-raw/england-health-index-ics.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# ---- Load libs ----
library(tidyverse)
library(readxl)
library(httr2)

# ---- Load internal sysdata.rda file with URL's ----
pkgload::load_all(".")

# ---- Download data ----
query_url <-
query_urls |>
filter(id == "england_health_index_ics") |>
pull(query)

download <- tempfile(fileext = ".xlsx")

request(query_url) |>
req_perform(download)

# ---- Read sheets ----
overall_scores_raw <- read_excel(
download,
sheet = "Table_2_Index_scores",
range = "A3:I45"
)

sheet_names <- paste0("Table_", seq(3, 9), "_", seq(2021, 2015), "_Index")
index_names <- paste0("index_", seq(2021, 2015))

indices <- map(
.x = set_names(sheet_names, index_names),
.f = \(x) read_excel(download, sheet = x, range = "A5:BW47")
)

# ---- Clean data ----
overall_scores <- overall_scores_raw |>
rename(icb22_code = `Area Code`, icb22_name = `Area Name`) |>
pivot_longer(
cols = `2015`:`2021`, names_to = "year", values_to = "overall_score"
) |>
mutate(year = as.integer(year))

domain_scores <- map2(
.x = indices,
.y = seq(2021, 2015),
.f = \(x, y) {
x |>
rename(icb22_code = `Area Code`, icb22_name = `Area Name`) |>
select(starts_with("icb22_"), ends_with("Domain")) |>
janitor::clean_names() |>
mutate(year = y)
}
) |>
list_rbind()

england_health_index_ics <- left_join(overall_scores, domain_scores)

england_health_index_ics_subdomains <- map2(
.x = indices,
.y = seq(2021, 2015),
.f = \(x, y) {
x |>
rename(icb22_code = `Area Code`, icb22_name = `Area Name`) |>
select(starts_with("icb22_"), matches("\\[(Pe|Pl|L)\\]$")) |>
rename_with(~ str_remove(., " \\[.*\\]$")) |>
janitor::clean_names() |>
pivot_longer(cols = !starts_with("icb22_"), names_to = "sub_domain") |>
mutate(year = y) |>
relocate(year, .after = "icb22_name")
}
) |>
list_rbind()

england_health_index_ics_indicators <- map2(
.x = indices,
.y = seq(2021, 2015),
.f = \(x, y) {
x |>
rename(icb22_code = `Area Code`, icb22_name = `Area Name`) |>
select(!c(matches("\\[(Pe|Pl|L)\\]$"), matches("Domain$"))) |>
rename_with(~ str_remove(., " \\[.*\\]$")) |>
janitor::clean_names() |>
pivot_longer(cols = !starts_with("icb22_"), names_to = "indicator") |>
mutate(year = y) |>
relocate(year, .after = "icb22_name")
}
) |>
list_rbind()

usethis::use_data(england_health_index_ics, overwrite = TRUE)
usethis::use_data(england_health_index_ics_subdomains, overwrite = TRUE)
usethis::use_data(england_health_index_ics_indicators, overwrite = TRUE)
1 change: 1 addition & 0 deletions data-raw/query-urls.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ query_urls <-
"Disability", "england_disability_2021", "2021", "OGLv3", "https://www.nomisweb.co.uk/output/census/2021/census2021-ts038.zip", "https://www.nomisweb.co.uk/sources/census_2021_bulk",
"Health Index", "england_health_index_2021", "June 2021", "OGLv3", "https://www.ons.gov.uk/file?uri=/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexscoresengland/current/healthindexscoresengland.xlsx", "https://www.ons.gov.uk/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexscoresengland",
"Health Index underlying indicators", "england_health_index_2021_indicators", "June 2021", "OGLv3", "https://www.ons.gov.uk/file?uri=/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexunderlyingdataengland/current/healthindexunderlyingdataenglandcanscreenfix.xlsx", "https://www.ons.gov.uk/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexunderlyingdataengland",
"Health Index ICS", "england_health_index_ics", "2015-2021", "OGLv3", "https://www.ons.gov.uk/file?uri=/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexscoresintegratedcaresystemsengland/current/healthindexscoresintegratedcaresystemsenglandcanscreeningfix.xlsx", "https://www.ons.gov.uk/peoplepopulationandcommunity/healthandsocialcare/healthandwellbeing/datasets/healthindexscoresintegratedcaresystemsengland",
"Homelessness", "england_homelessness", "October to December 2023", "", "https://assets.publishing.service.gov.uk/media/662f6eccce557c60ed19ad15/Detailed_LA_202312.ods", "https://www.gov.uk/government/statistical-data-sets/live-tables-on-homelessness",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_april_22", "April 2022", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2022/08/Daily-discharge-sitrep-monthly-data-webfile-April2022-v2.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_may_22", "May 2022", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2022/08/Daily-discharge-sitrep-monthly-data-webfile-May2022-v2.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
Expand Down
Binary file added data/england_health_index_ics.rda
Binary file not shown.
Binary file added data/england_health_index_ics_indicators.rda
Binary file not shown.
Binary file added data/england_health_index_ics_subdomains.rda
Binary file not shown.
30 changes: 30 additions & 0 deletions man/england_health_index_ics.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions man/england_health_index_ics_indicators.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/england_health_index_subdomains.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3201c0b

Please sign in to comment.