Skip to content

Commit

Permalink
Merge pull request #33 from humaniverse/census-2021
Browse files Browse the repository at this point in the history
Census 2021
  • Loading branch information
jennajt authored May 23, 2024
2 parents 5a02f0a + 9f060a0 commit 5263e8a
Show file tree
Hide file tree
Showing 18 changed files with 401 additions and 0 deletions.
94 changes: 94 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ NULL
#' @source \url{https://www.england.nhs.uk/}
"england_critical_general_acute_beds"

#' Disability by LTLA for England, 2021
#'
#' A dataset containing LTLA data on numbers disabled under the Equality Act.
#'
#' @format A data frame with 662 rows and 5 variables:
#' \describe{
#' \item{ltla21_code}{LTLA code}
#' \item{total_residents}{Total residents in the local authority}
#' \item{disability_level}{Disabled or Not disabled under the Equality Act}
#' \item{n}{number of people}
#' \item{prop}{proportion of people}

#' ...
#' }
#' @source \url{https://www.nomisweb.co.uk/sources/census_2021_bulk}
"england_disability_21"

#' Hospital ICB Discharge Data - Criteria to Reside
#'
#' A dataset containing NHS Integrated Care Board discharge data on how many
Expand Down Expand Up @@ -220,6 +237,37 @@ NULL
#' @source \url{https://www.ons.gov.uk/}
"england_health_index_indicators"

#' Legal Partnership Status, England, 2021
#'
#' A dataset containing legal partnership status data at LTLA level
#'
#' @format A data frame with 5,627 rows and 5 variables:
#' \describe{
#' \item{ltla21_code}{LTLA code}
#' \item{total_population}{Population in the LTLA}
#' \item{legal_partnership}{Type of legal partnership}
#' \item{n}{Number of people}
#' \item{prop}{Percentage}
#' }
#' @source \url{https://www.nomisweb.co.uk/sources/census_2021_bulk}
"england_legal_partnership_21"

#' Sexual orientation, England, 2021
#'
#' A dataset containing sexual orientation data at LTLA level
#'
#' @format A data frame with 1,655 rows and 5 variables:
#' \describe{
#' \item{ltla21_code}{LTLA code}
#' \item{total_residents}{Residents in the LTLA}
#' \item{sexual_orientation}{Sexual orientation}
#' \item{n}{Number of people}
#' \item{prop}{Percentage}
#' }
#' @source \url{https://www.nomisweb.co.uk/sources/census_2021_bulk}
"england_sexual_orientation_21"


#' Psychological Therapies - IAPT
#'
#' A dataset containing NHS Sub Integrated Care Board (formerly CCGs) data.
Expand Down Expand Up @@ -472,6 +520,23 @@ NULL
#' @source \url{https://www.opendata.nhs.scot/}
"scotland_rtt_hb"


#' Disability by LTLA for Wales, 2021
#'
#' A dataset containing LTLA data on numbers disabled under the Equality Act.
#'
#' @format A data frame:
#' \describe{
#' \item{ltla21_code}{LTLA code}
#' \item{total_residents}{Total residents in the local authority}
#' \item{disability_level}{Disabled or Not disabled under the Equality Act}
#' \item{n}{number of people}
#' \item{prop}{proportion of people}

#' ...
#' }
#' @source \url{https://www.nomisweb.co.uk/sources/census_2021_bulk}
"wales_disability_21"
#' Homelessness in Scotland
#'
#' A dataset containing statistics on households assessed as homeless and
Expand Down Expand Up @@ -565,6 +630,35 @@ NULL
#' @source \url{https://statswales.gov.wales/}
"wales_hospitals_critical_general_acute_beds"

#' Legal Partnership Status, Wales, 2021
#'
#' A dataset containing legal partnership status data at LTLA level
#'
#' @format A data frame:
#' \describe{
#' \item{ltla21_code}{LTLA code}
#' \item{total_population}{Population in the LTLA}
#' \item{legal_partnership}{Type of legal partnership}
#' \item{n}{Number of people}
#' \item{prop}{Percentage}
#' }
#' @source \url{https://www.nomisweb.co.uk/sources/census_2021_bulk}
"wales_legal_partnership_21"

#' Sexual orientation, Wales, 2021
#'
#' A dataset containing sexual orientation data at LTLA level
#'
#' @format A data frame:
#' \describe{
#' \item{ltla21_code}{LTLA code}
#' \item{total_residents}{Residents in the LTLA}
#' \item{sexual_orientation}{Sexual orientation}
#' \item{n}{Number of people}
#' \item{prop}{Percentage}
#' }
#' @source \url{https://www.nomisweb.co.uk/sources/census_2021_bulk}
"wales_sexual_orientation_21"
#' Homelessness in Wales
#'
#' A dataset containing statistics on households assessed as homeless and
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
47 changes: 47 additions & 0 deletions data-raw/england-wales-disability-ltla.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ---- Load libs ----
library(tidyverse)
library(geographr)
library(devtools)
library(httr2)

# ---- Load internal sysdata.rda file with URLs ----
load_all(".")

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

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

request(query_url) |>
req_perform(download)

unzip(download, exdir = tempdir())

list.files(tempdir())

raw <- read_csv(file.path(tempdir(), "census2021-ts038-ltla.csv"))

names(raw) <- str_remove(names(raw), "Disability: ")

# ---- Detailed ethnic categories ----
disability_21 <-
raw |>
select(
ltla21_code = `geography code`,
total_residents = `Total: All usual residents`, !contains(":"), -date, -geography
) |>
pivot_longer(cols = -c(ltla21_code, total_residents), names_to = "disability_level", values_to = "n") |>
mutate(prop = n / total_residents)

england_disability_21 <- disability_21 |>
filter(str_detect(ltla21_code, "^E"))

wales_disability_21 <- disability_21 |>
filter(str_detect(ltla21_code, "^W"))

# ---- Save output to data/ folder ----
usethis::use_data(england_disability_21, overwrite = TRUE)
usethis::use_data(wales_disability_21, overwrite = TRUE)
50 changes: 50 additions & 0 deletions data-raw/england-wales-legal-partnership-ltla.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ---- Load libs ----
library(tidyverse)
library(geographr)
library(devtools)
library(httr2)

# ---- Load internal sysdata.rda file with URLs ----
load_all(".")

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

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

request(query_url) |>
req_perform(download)

unzip(download, exdir = tempdir())

list.files(tempdir())

raw <- read_csv(file.path(tempdir(), "census2021-ts002-ltla.csv"))

names(raw) <- str_remove(names(raw), "Marital and civil partnership status: ")

# ---- Detailed ethnic categories ----
legal_partnership_21 <-
raw |>
select(-date, -geography) |>
rename(
ltla21_code = `geography code`,
total_population = `Total; measures: Value`
) |>
pivot_longer(cols = -c(ltla21_code, total_population), names_to = "legal_partnership", values_to = "n") |>
mutate(prop = n / total_population) |>
mutate(prop = format(prop, scientific = FALSE))

england_legal_partnership_21 <- legal_partnership_21 |>
filter(str_detect(ltla21_code, "^E"))

wales_legal_partnership_21 <- legal_partnership_21 |>
filter(str_detect(ltla21_code, "^W"))

# ---- Save output to data/ folder ----
usethis::use_data(england_legal_partnership_21, overwrite = TRUE)
usethis::use_data(wales_legal_partnership_21, overwrite = TRUE)

49 changes: 49 additions & 0 deletions data-raw/england-wales-sexual-orientation-ltla.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# ---- Load libs ----
library(tidyverse)
library(geographr)
library(devtools)
library(httr2)

# ---- Load internal sysdata.rda file with URLs ----
load_all(".")

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

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

request(query_url) |>
req_perform(download)

unzip(download, exdir = tempdir())

list.files(tempdir())

raw <- read_csv(file.path(tempdir(), "census2021-ts077-ltla.csv"))

names(raw) <- str_remove(names(raw), "Sexual orientation: ")

# ---- Detailed ethnic categories ----
sexual_orientation_21 <-
raw |>
select(-date, -geography) |>
rename(
ltla21_code = `geography code`,
total_residents = `Total: All usual residents aged 16 years and over`
) |>
pivot_longer(cols = -c(ltla21_code, total_residents), names_to = "sexual_orientation", values_to = "n") |>
mutate(prop = n / total_residents) |>
mutate(prop = format(prop, scientific = FALSE))

england_sexual_orientation_21 <- sexual_orientation_21 |>
filter(str_detect(ltla21_code, "^E"))

wales_sexual_orientation_21 <- sexual_orientation_21 |>
filter(str_detect(ltla21_code, "^W"))

# ---- Save output to data/ folder ----
usethis::use_data(england_sexual_orientation_21, overwrite = TRUE)
usethis::use_data(wales_sexual_orientation_21, overwrite = TRUE)
3 changes: 3 additions & 0 deletions data-raw/query-urls.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ query_urls <-
"Critical care and General & Acute Beds – Urgent and Emergency Care Daily Situation Reports", "nhs_critical_general_acute_beds_october_23", "October 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/11/202310-October-2023-sitrep-data-FINAL.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports-2023-24/",
"Critical care and General & Acute Beds – Urgent and Emergency Care Daily Situation Reports", "nhs_critical_general_acute_beds_november_23", "November 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/12/202311-November-2023-sitrep-data-FINAL.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports-2023-24/",
"Critical care and General & Acute Beds – Urgent and Emergency Care Daily Situation Reports", "nhs_critical_general_acute_beds_december_23", "December 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/01/202312-December-2023-sitrep-data-FINAL.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/bed-availability-and-occupancy/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports/critical-care-and-general-acute-beds-urgent-and-emergency-care-daily-situation-reports-2023-24/",
"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",
"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",
Expand All @@ -84,7 +85,9 @@ query_urls <-
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_october_23", "October 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/11/Daily-discharge-sitrep-monthly-data-webfile-October2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_november_23", "November 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2023/12/Daily-discharge-sitrep-monthly-data-webfile-November2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Hospital discharge (criteria to reside)", "nhs_hospital_discharge_data_december_23", "December 2023", "OGLv3", "https://www.england.nhs.uk/statistics/wp-content/uploads/sites/2/2024/01/Daily-discharge-sitrep-monthly-data-webfile-December2023.xlsx", "https://www.england.nhs.uk/statistics/statistical-work-areas/discharge-delays-acute-data/",
"Legal partnership status", "legal_partnership_status_2021", "2021", "OGLv3", "https://www.nomisweb.co.uk/output/census/2021/census2021-ts002.zip", "https://www.nomisweb.co.uk/sources/census_2021_bulk",
"Psychological Therapies (IAPT)", "nhs_iapt_22_23", "January 2022-23", "OGLv3", "https://files.digital.nhs.uk/89/B4C209/iapt_time_series_Jan_22_Jan_23_key_measures.zip", "https://digital.nhs.uk/data-and-information/publications/statistical/psychological-therapies-report-on-the-use-of-iapt-services",
"Sexual orientation", "sexual_orientation_2021", "2021", "OGLv3", "https://www.nomisweb.co.uk/output/census/2021/census2021-ts077.zip", "https://www.nomisweb.co.uk/sources/census_2021_bulk",

# Northern Ireland
"Bed availability", "ni_beds_pre22", "2013 - 2022", "OGLv3", "https://www.health-ni.gov.uk/sites/default/files/publications/health/hs-inpatient-hts-tables-21-22.csv", "https://www.health-ni.gov.uk/publications/hospital-statistics-inpatient-and-day-case-activity-202122",
Expand Down
Binary file added data/england_disability_21.rda
Binary file not shown.
Binary file added data/england_legal_partnership_21.rda
Binary file not shown.
Binary file added data/england_sexual_orientation_21.rda
Binary file not shown.
Binary file added data/wales_disability_21.rda
Binary file not shown.
Binary file added data/wales_legal_partnership_21.rda
Binary file not shown.
Binary file added data/wales_sexual_orientation_21.rda
Binary file not shown.
27 changes: 27 additions & 0 deletions man/england_disability_21.Rd

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

26 changes: 26 additions & 0 deletions man/england_legal_partnership_21.Rd

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

26 changes: 26 additions & 0 deletions man/england_sexual_orientation_21.Rd

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

27 changes: 27 additions & 0 deletions man/wales_disability_21.Rd

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

Loading

0 comments on commit 5263e8a

Please sign in to comment.