Package 'reskit'

Title: Nice selection box of goodies for hobnobbing with NHP model results
Description: 'Wafer' goodbye to crumbly code, and dunk a sturdy reskit function in your data cuppa instead. We've clustered the cream of our results code here - it's a cracker!
Authors: Fran Barton [aut, cre] (ORCID: <https://orcid.org/0000-0002-5650-1176>), Matt Dray [ctb], Rhian Davies [ctb]
Maintainer: Fran Barton <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0
Built: 2026-05-20 20:37:41 UTC
Source: https://github.com/The-Strategy-Unit/nhp_reskit

Help Index


Add change and change_pct columns to a prepared results table

Description

Add change and change_pct columns to a prepared results table

Usage

add_change_cols(tbl)

Arguments

tbl

A tibble of appropriately prepared results

Value

A tibble


Prepare data from the step_counts results table for display as charts

Description

Prepare data from the step_counts results table for display as charts

Usage

compile_change_factor_data(
  results,
  measure,
  activity_type = c("ip", "op", "aae"),
  pods = NULL,
  sites = NULL,
  pod_lookup = get_principal_pods(),
  tpma_lookup = get_tpma_label_lookup(),
  include_baseline = TRUE
)

Arguments

results

A named list containing NHP results tables

measure

The measure to focus on for the output table. Valid values depend on which activity_type is selected

activity_type

string. One of "ip", "op", "aae". "ip" is the default.

pods

character vector. PoD labels to filter data to. The default value of NULL means no PoDs will be filtered out

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

tpma_lookup

A tibble, or a function that returns a tibble, containing a column named strategy (used as a key for joining to the step_counts table) and a column named tpma_label that provides friendly labels for all TPMAs/strategies

include_baseline

Boolean. Whether to include baseline data

Value

A prepared tibble of step count changes for each included TPMA


Prepare data from the sex+age_group or sex+tretspef_grouped table

Description

Prepare data from the sex+age_group or sex+tretspef_grouped table

Usage

compile_detailed_activity_data(
  results,
  measure,
  pod_lookup = get_detailed_pods(),
  tretspef_lookup = get_tretspef_lookup(),
  activity_type = c("ip", "op", "aae"),
  aggregation = c("age_group", "tretspef_grouped"),
  pods = NULL,
  sites = NULL
)

Arguments

results

A named list containing NHP results tables

measure

The measure to focus on for the output table. Valid values depend on which activity_type is selected

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

tretspef_lookup

A tibble, or a function that returns a tibble, containing a code column (used as a key for joining to the tretspef table) and a tretspef column that provides friendly labels for specialties

activity_type

string. One of "ip", "op", "aae". "ip" is the default.

aggregation

string. One of "age_group" or "tretspef_grouped"

pods

character vector. PoD labels to filter data to. The default value of NULL means no PoDs will be filtered out

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data


Compile data to support the "activity distribution summary" tables

Description

Compile data to support the "activity distribution summary" tables

Usage

compile_distribution_plot_data(
  results,
  measure,
  activity_type = c("ip", "op", "aae"),
  pods = NULL,
  pod_lookup = get_detailed_pods(),
  sites = NULL
)

Arguments

results

A named list containing NHP results tables

measure

The measure to focus on for the output table. Valid values depend on which activity_type is selected

activity_type

string. One of "ip", "op", "aae". "ip" is the default.

pods

character vector. PoD labels to filter data to. The default value of NULL means no PoDs will be filtered out

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

Value

A tibble


Compile data to support the "activity distribution summary" tables

Description

Compile data to support the "activity distribution summary" tables

Usage

compile_distribution_summary_data(
  results,
  value_type = c("median", "principal"),
  pod_lookup = get_detailed_pods(),
  sites = NULL
)

Arguments

results

A named list containing NHP results tables

value_type

string Either "median" or "principal"

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

Value

A tibble


Prepare data from step_counts results table for display as charts

Description

Prepare data from step_counts results table for display as charts

Usage

compile_indiv_change_factor_data(
  results,
  measure,
  activity_type = c("ip", "op", "aae"),
  pods = NULL,
  sites = NULL,
  pod_lookup = get_principal_pods(),
  tpma_lookup = get_tpma_label_lookup(),
  sort_by = c("value", "tpma_label")
)

Arguments

results

A named list containing NHP results tables

measure

The measure to focus on for the output table. Valid values depend on which activity_type is selected

activity_type

string. One of "ip", "op", "aae". "ip" is the default.

pods

character vector. PoD labels to filter data to. The default value of NULL means no PoDs will be filtered out

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

tpma_lookup

A tibble, or a function that returns a tibble, containing a column named strategy (used as a key for joining to the step_counts table) and a column named tpma_label that provides friendly labels for all TPMAs/strategies

sort_by

string, one of "value" or "tpma_label". The former sorts the output table by the value of the change, the latter alphabetically by the TPMA label

Value

A prepared tibble of projected negative changes in activity, by TPMA


Prepare data from tretspef+los_group results for displaying as summary table

Description

Prepare data from tretspef+los_group results for displaying as summary table

Usage

compile_principal_los_data(
  results,
  measure,
  pod_lookup = get_principal_pods(),
  sites = NULL
)

Arguments

results

A named list containing NHP results tables

measure

Either "admissions" or "beddays". The measure to focus on for the output table

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

Value

A filtered and sorted tibble of principal projections of results, by point of delivery and grouped length of stay


Prepare data from default results table for displaying as summary table

Description

Prepare data from default results table for displaying as summary table

Usage

compile_principal_pod_data(
  results,
  pod_lookup = get_principal_pods(),
  sites = NULL
)

Arguments

results

A named list containing NHP results tables

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

Value

A filtered and sorted tibble of principal projections of results, by activity type and point of delivery (PoD)


Prepare a site-level summary of detailed activity results by PoD and LoS

Description

Intended to be used to create a table to be exported to .csv/.xlsx

Usage

export_detailed_activity_data(
  results,
  pod_lookup = get_detailed_pods(),
  tretspef_lookup = get_tretspef_lookup(),
  aggregation = c("age_group", "tretspef_grouped"),
  sites = NULL
)

Arguments

results

A named list containing NHP results tables

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

tretspef_lookup

A tibble, or a function that returns a tibble, containing a code column (used as a key for joining to the tretspef table) and a tretspef column that provides friendly labels for specialties

aggregation

string. One of "age_group" or "tretspef_grouped"

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

Value

A tibble


Prepare a site-level summary of activity distribution summary data

Description

Intended to be used to create a table to be exported to .csv/.xlsx

Usage

export_distribution_summary_data(
  results,
  pod_lookup = get_detailed_pods(),
  sites = NULL
)

Arguments

results

A named list containing NHP results tables

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

Value

A tibble


Prepare a site-level summary table of change_factor results

Description

Intended to be used to create a table to be exported to .csv/.xlsx

Usage

export_principal_cf_data(
  results,
  sites = NULL,
  pod_lookup = get_principal_pods(),
  tpma_lookup = get_tpma_label_lookup()
)

Arguments

results

A named list containing NHP results tables

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

tpma_lookup

A tibble, or a function that returns a tibble, containing a column named strategy (used as a key for joining to the step_counts table) and a column named tpma_label that provides friendly labels for all TPMAs/strategies

Value

A tibble


Prepare a site-level summary of main projection results by PoD and LoS

Description

Intended to be used to create a table to be exported to .csv/.xlsx

Usage

export_principal_los_data(
  results,
  pod_lookup = get_principal_pods(),
  sites = NULL
)

Arguments

results

A named list containing NHP results tables

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

Value

A tibble


Prepare a site-level summary of main projection results

Description

Intended to be used to create a table to be exported to .csv/.xlsx

Usage

export_principal_pod_data(
  results,
  pod_lookup = get_principal_pods(),
  sites = NULL
)

Arguments

results

A named list containing NHP results tables

pod_lookup

A tibble, or a function that returns a tibble, containing columns named activity_type_label, pod and pod_label. This provides friendly labels for POD variables in the data. pod is the key column used for joining to data tables.

sites

Either NULL (the default) or a vector of site codes to filter to. NULL means don't filter; include all sites present in the data

Value

A tibble


Prepare a lookup table with activity type labels and PoD labels for each PoD

Description

This function condenses all A&E activity to a single category - compare get_detailed_pods() which keeps all A&E categories

Usage

get_detailed_pods(use_local = FALSE)

get_principal_pods(use_local = FALSE)

Arguments

use_local

logical. Whether to use a local file (internal to the reskit package) or attempt to pull the lookup file from GitHub. Default is FALSE, meaning it will use the GitHub route. If you want to always use a local file (for example, for fully offline working), you can set the reskit.local.lookups option to TRUE using options(reskit.local.lookups = TRUE) or withr::with_options()

Value

A tibble

A tibble


Return a path to a specific results directory

Description

Provides some logic and checks to assist the user in locating a valid directory from which to read in NHP results data

Usage

get_results_dir_path(
  container,
  path,
  version,
  scheme,
  scenario = NULL,
  dttm_stamp = NULL
)

Arguments

container

An Azure container.

path

string. The path to the directory within the container, where the desired results data is stored

version

string. The NHP model version in the format "v3.6", or "dev"

scheme

string. The code/name of the NHP scheme. May be "national" etc

scenario

string. If NULL, the default, and only a single scenario is available within the particular combination of version and scheme, this single path will be followed. However if multiple scenarios are available, an error will be thrown. The user may avert this by simply supplying an existent scenario name

dttm_stamp

string. If NULL (the default) and only a single model run directory is available within the particular combination of version scheme and scenario, this path will be returned. If NULL, and multiple model runs are found, an error will be thrown. Alternatively, the date-time stamp of the desired model run can be supplied. This is expected to be in the format 'YYYYMMDD_HHMMSS', and must of course match a subdirectory of the selected 'scenario' directory, else an error will be thrown. A third alternative is to supply the string "max", which will return the path to the most recent model run, where multiple runs are found

Value

A path to an Azure blob storage directory, as a string


Get a lookup of TPMA labels

Description

Currently reads from a fixed location within the package.

Usage

get_tpma_label_lookup()

Value

A 2-column tibble, with columns strategy and tpma_label


Get a lookup of tretspef codes to descriptions

Description

Currently reads from a fixed location within the package.

Usage

get_tretspef_lookup()

Value

A 2-column tibble with columns code and tretspef


From any results table, get list of all site codes for this scheme

Description

The "default" table is recommended

Usage

get_trust_sites(res_tbl, col = "sitetret")

Arguments

res_tbl

A tibble from the results list

col

string The name of the column containing site codes. sitetret by default

Value

A character vector


Generate a "beeswarm" chart showing the distribution of model run values

Description

Generate a "beeswarm" chart showing the distribution of model run values

Usage

make_beeswarm_distrib_plot(distrib_plot_data, show_zero = FALSE)

Arguments

distrib_plot_data

data frame. As produced by compile_distribution_plot_data

show_zero

Boolean. Whether to extend the chart to show a zero value, for context.


Generate a cumulative distribution function (ecdf) chart of model run values

Description

Generate a cumulative distribution function (ecdf) chart of model run values

Usage

make_cumulative_distrib_plot(distrib_plot_data, show_zero = FALSE)

Arguments

distrib_plot_data

data frame. As produced by compile_distribution_plot_data

show_zero

Boolean. Whether to extend the chart to show a zero value, for context.


Create a gt table with data from compile_detailed_activity_data()

Description

Create a gt table with data from compile_detailed_activity_data()

Usage

make_detailed_activity_table(detailed_activity_data, final_year)

Arguments

detailed_activity_data

A suitable tibble

final_year

string. The horizon year eg "2042/43"

Value

A gt table


Create a gt table with data from compile_distribution_summary_data()

Description

Create a gt table with data from compile_distribution_summary_data()

Usage

make_distribution_summary_table(distr_summary_data)

Arguments

distr_summary_data

A suitable tibble

Value

A gt table


Generate bar charts by change factor at individual TPMA level

Description

Generate bar charts by change factor at individual TPMA level

Usage

make_individual_cf_plot(indiv_change_factor_data)

Arguments

indiv_change_factor_data

data frame. As produced by compile_indiv_change_factor_data


Generate overall change factor ("waterfall") chart

Description

Generate overall change factor ("waterfall") chart

Usage

make_overall_cf_plot(principal_change_factor_data)

Arguments

principal_change_factor_data

data frame. As produced by compile_change_factor_data


Create a gt table with data from compile_principal_los_data

Description

Create a gt table with data from compile_principal_los_data

Usage

make_principal_los_table(principal_los_data)

Arguments

principal_los_data

A suitable tibble

Value

A gt table


Create a gt table with data from compile_principal_pod_data

Description

Create a gt table with data from compile_principal_pod_data

Usage

make_principal_pod_table(principal_pod_data)

Arguments

principal_pod_data

A suitable tibble

Value

A gt table


Read a selection of (or all) parquet files in an Azure directory

Description

Read a selection of (or all) parquet files in an Azure directory

Usage

read_results_parquet_files(container, path, tables = NULL)

Arguments

container

An Azure container.

path

string. Path to an Azure directory of results data. Potentially produced by get_results_dir_path

tables

character vector. NULL, the default, results in all available parquet files in the path folder being read in. If you wish only to read in a subset of the files, specify their names here, without the ".parquet" file extension

Value

A named list of tibbles

Examples

## Not run: 
  data <- azkit::get_container("data_container") |>
    read_results_parquet_files("data/dev/national/test", "acuity")

  data_list <- azkit::get_container("data_container") |>
    get_results_dir_path("files", version = "v4.0", scheme = "national") |>
    read_results_parquet_files()

## End(Not run)

Wrangle tables from old-style results to match format of new-style results

Description

Wrangle tables from old-style results to match format of new-style results

Usage

shim_results(results)

Arguments

results

List of old style NHP results tables

Value

List of NHP results tables in the "new" format