## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  message = FALSE,
  comment = "#>"
)

## -----------------------------------------------------------------------------
library(iod25)
library(dplyr)

## -----------------------------------------------------------------------------
glimpse(domains)

## -----------------------------------------------------------------------------
glimpse(imd)

## -----------------------------------------------------------------------------
glimpse(supplementary)

## -----------------------------------------------------------------------------
bind_rows(domains, imd, supplementary) |>
  glimpse()

## -----------------------------------------------------------------------------
glimpse(subdomains)

## -----------------------------------------------------------------------------
glimpse(population)

## -----------------------------------------------------------------------------
# IMD requires the total population as a denominator
total_pop <- filter(population, population_group == "Total")

imd |>
  left_join(
    total_pop,
    by = join_by(lsoa_code, lsoa_name, lad_code, lad_name)
  ) |>
  summarise(
    score = weighted.mean(score, population),
    .by = lad_name
  ) |>
  arrange(desc(score))

## -----------------------------------------------------------------------------
citation("iod25")

