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.2.0
Built: 2026-09-25 14:40:01 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 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 the step_counts table to use for waterfall chart

Description

Prepare data from the step_counts table to use for waterfall chart

Usage

compile_grouped_impact_data(
  results,
  measure,
  activity_type = c("ip", "op", "aae"),
  pods = NULL,
  sites = NULL,
  pod_lookup = get_detailed_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 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 data from step_counts table to use for TPMA impact chart

Description

Prepare data from step_counts table to use for TPMA impact chart

Usage

compile_tpma_impact_data(
  results,
  measure,
  activity_type = c("ip", "op", "aae"),
  pods = NULL,
  sites = NULL,
  pod_lookup = get_detailed_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 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_impact_data(
  results,
  sites = NULL,
  pod_lookup = get_detailed_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()

get_principal_pods()

Value

A tibble

A tibble


Prepare a lookup table for all current TPMAs

Description

Prepare a lookup table for all current TPMAs

Usage

get_tpma_label_lookup()

Value

A 4-column tibble, with columns strategy, activity_type, change_factor and tpma_label


Get a lookup of tretspef codes to descriptions

Description

Get a lookup of tretspef codes to descriptions

Usage

get_tretspef_lookup()

Value

A 2-column tibble with columns code and tretspef


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 overall change factor ("waterfall") chart

Description

Generate overall change factor ("waterfall") chart

Usage

make_grouped_impact_plot(grouped_impact_data)

Arguments

grouped_impact_data

tibble, as produced by compile_grouped_impact_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


Generate bar charts by change factor at individual TPMA level

Description

Generate bar charts by change factor at individual TPMA level

Usage

make_tpma_impact_plot(tpma_impact_data)

Arguments

tpma_impact_data

tibble, as produced by compile_tpma_impact_data


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 model results data. Potentially pulled from a field in a table of model runs metadata

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") |>
    read_results_parquet_files(path = "files/v4.0/national")

## 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