Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 37 function renaming #81

Merged
merged 10 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: NHSRwaitinglist
Title: R-package to implement a waiting list management approach
Version: 0.0.0.9000
Version: 0.0.0.9001
Authors@R: c(
person("Neil", "Walton", ,"[email protected]", c("cre", "aut"), comment = c(ORCID ="0000-0002-5241-9765")),
person("Jacqueline", "Grout", ,"[email protected]", "aut"),
Expand Down
12 changes: 6 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Generated by roxygen2: do not edit by hand

export(average_wait)
export(calc_queue_load)
export(calc_relief_capacity)
export(calc_target_capacity)
export(calc_target_mean_wait)
export(calc_target_queue_size)
export(calc_waiting_list_pressure)
export(create_bulk_synthetic_data)
export(create_waiting_list)
export(queue_load)
export(relief_capacity)
export(target_capacity)
export(target_queue_size)
export(waiting_list_pressure)
export(wl_insert)
export(wl_join)
export(wl_queue_size)
Expand Down
52 changes: 26 additions & 26 deletions R/queue_load.R → R/calc_queue_load.R
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#' @title Calculate Queue Load
#'
#' @description Calculates the queue load. The queue load is the number of
#' arrivals that occur for every patient leaving the queue (given that the
#' waiting list did not empty). It could also be described as the rate of
#' service at the queue. The queue load is calculated by dividing the demand
#' by the capacity: queue_load = demand / capacity.
#'
#' @param demand Numeric value of rate of demand in same units as target wait -
#' e.g. if target wait is weeks, then demand in units of patients/week.
#' @param capacity Numeric value of the number of patients that can be served
#' (removals) from the waiting list each week.
#'
#' @return Numeric value of load which is the ratio between demand and capacity.
#'
#' @export
#'
#' @examples
#' # If 30 patients are added to the waiting list each week (demand) and 27
#' # removed (capacity) this results in a queue load of 1.11 (30/27).
#' queue_load(30, 27)
queue_load <- function(demand, capacity) {
check_class(demand, capacity)
load <- demand / capacity
return(load)
}
#' @title Calculate Queue Load
#'
#' @description Calculates the queue load. The queue load is the number of
#' arrivals that occur for every patient leaving the queue (given that the
#' waiting list did not empty). It could also be described as the rate of
#' service at the queue. The queue load is calculated by dividing the demand
#' by the capacity: queue_load = demand / capacity.
#'
#' @param demand Numeric value of rate of demand in same units as target wait -
#' e.g. if target wait is weeks, then demand in units of patients/week.
#' @param capacity Numeric value of the number of patients that can be served
#' (removals) from the waiting list each week.
#'
#' @return Numeric value of load which is the ratio between demand and capacity.
#'
#' @export
#'
#' @examples
#' # If 30 patients are added to the waiting list each week (demand) and 27
#' # removed (capacity) this results in a queue load of 1.11 (30/27).
#' calc_queue_load(30, 27)
calc_queue_load <- function(demand, capacity) {
check_class(demand, capacity)
load <- demand / capacity
return(load)
}
4 changes: 2 additions & 2 deletions R/relief_capacity.R → R/calc_relief_capacity.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#'
#' # Relief Capacity = 30 + (1200 - 390)/26 = 61.15 patients per week.
#'
#' relief_capacity(30, 1200, 390, 26)
#' calc_relief_capacity(30, 1200, 390, 26)
#'
relief_capacity <- function(
calc_relief_capacity <- function(
demand,
queue_size,
target_queue_size,
Expand Down
4 changes: 2 additions & 2 deletions R/target_capacity.R → R/calc_target_capacity.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
#' target_wait <- 52 # weeks
#'
#' # number of operations per week to have mean wait of 52/4
#' target_capacity(demand, target_wait)
#' calc_target_capacity(demand, target_wait)
#'
#' # TODO: Include a couple of standard deviations for errors in the mean demand
target_capacity <- function(
calc_target_capacity <- function(
demand,
target_wait,
factor = 4,
Expand Down
60 changes: 30 additions & 30 deletions R/average_wait.R → R/calc_target_mean_wait.R
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#' @title Average Waiting Time
#'
#' @description This calculates the target mean wait given the two inputs of
#' target_wait and a numerical value for factor. The average wait is actually
#' the target mean wait and is calculated as follows: target_wait / factor. If
#' we want to have a chance between 1.8%-0.2% of making a waiting time target,
#' then the average patient should have a waiting time between a quarter and a
#' sixth of the target. Therefore: The mean wait should sit somewhere between
#' target_wait/factor=6 < Average Waiting Time < target_wait/factor=4.
#'
#' @param target_wait Numeric value of the number of weeks that has been set as
#' the target within which the patient should be seen.
#' @param factor Numeric factor used in average wait calculation - to get a
#' quarter of the target use factor=4 and one sixth of the target use factor =
#' 6 etc. Defaults to 4.
#'
#' @return Numeric value of target mean waiting time to achieve a given target
#' wait.
#'
#' @export
#'
#' @examples
#' # If the target wait is 52 weeks then the target mean wait with a factor of 4
#' # would be 13 weeks and with a factor of 6 it would be 8.67 weeks.
#' average_wait(52, 4)
average_wait <- function(target_wait, factor = 4) {
check_class(target_wait, factor)
target_mean_wait <- target_wait / factor
return(target_mean_wait)
}
#' @title Average Waiting Time
#'
#' @description This calculates the target mean wait given the two inputs of
#' target_wait and a numerical value for factor. The average wait is actually
#' the target mean wait and is calculated as follows: target_wait / factor. If
#' we want to have a chance between 1.8%-0.2% of making a waiting time target,
#' then the average patient should have a waiting time between a quarter and a
#' sixth of the target. Therefore: The mean wait should sit somewhere between
#' target_wait/factor=6 < Average Waiting Time < target_wait/factor=4.
#'
#' @param target_wait Numeric value of the number of weeks that has been set as
#' the target within which the patient should be seen.
#' @param factor Numeric factor used in average wait calculation - to get a
#' quarter of the target use factor=4 and one sixth of the target use factor =
#' 6 etc. Defaults to 4.
#'
#' @return Numeric value of target mean waiting time to achieve a given target
#' wait.
#'
#' @export
#'
#' @examples
#' # If the target wait is 52 weeks then the target mean wait with a factor of 4
#' # would be 13 weeks and with a factor of 6 it would be 8.67 weeks.
#' calc_target_mean_wait(52, 4)
calc_target_mean_wait <- function(target_wait, factor = 4) {
check_class(target_wait, factor)
target_mean_wait <- target_wait / factor
return(target_mean_wait)
}
50 changes: 25 additions & 25 deletions R/waiting_list_pressure.R → R/calc_waiting_list_pressure.R
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#' @title Calculate Waiting List Pressure
#'
#' @description For a waiting list with target waiting time, the pressure on the
#' waiting list is twice the mean delay divided by the waiting list target.
#' The pressure of any given waiting list should be less than 1. If the
#' pressure is greater than 1 then the waiting list is most likely going to
#' miss its target. The waiting list pressure is calculated as follows:
#' pressure = 2 * mean_wait / target_wait.
#'
#' @param mean_wait Numeric value of target mean waiting time to achieve a given
#' target wait.
#' @param target_wait Numeric value of the number of weeks that has been set as
#' the target within which the patient should be seen.
#'
#' @return Numeric value of wait_pressure which is the waiting list pressure.
#'
#' @export
#'
#' @examples
#' waiting_list_pressure(63, 52)
waiting_list_pressure <- function(mean_wait, target_wait) {
check_class(mean_wait, target_wait)
wait_pressure <- 2 * mean_wait / target_wait
return(wait_pressure)
}
#' @title Calculate Waiting List Pressure
#'
#' @description For a waiting list with target waiting time, the pressure on the
#' waiting list is twice the mean delay divided by the waiting list target.
#' The pressure of any given waiting list should be less than 1. If the
#' pressure is greater than 1 then the waiting list is most likely going to
#' miss its target. The waiting list pressure is calculated as follows:
#' pressure = 2 * mean_wait / target_wait.
#'
#' @param mean_wait Numeric value of target mean waiting time to achieve a given
#' target wait.
#' @param target_wait Numeric value of the number of weeks that has been set as
#' the target within which the patient should be seen.
#'
#' @return Numeric value of wait_pressure which is the waiting list pressure.
#'
#' @export
#'
#' @examples
#' calc_waiting_list_pressure(63, 52)
calc_waiting_list_pressure <- function(mean_wait, target_wait) {
check_class(mean_wait, target_wait)
wait_pressure <- 2 * mean_wait / target_wait
return(wait_pressure)
}
8 changes: 4 additions & 4 deletions R/target_queue_size.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#' # If demand is 30 patients per week and the target wait is 52 weeks, then the
#' # Target queue size = 30 * 52/4 = 390 patients.
#'
#' target_queue_size(30, 52, 4)
#' calc_target_queue_size(30, 52, 4)
#'
target_queue_size <- function(demand, target_wait, factor = 4) {
calc_target_queue_size <- function(demand, target_wait, factor = 4) {
check_class(demand, target_wait, factor)
mean_wait <- average_wait(target_wait, factor)
target_queue_length <- demand * mean_wait
target_mean_wait <- calc_target_mean_wait(target_wait, factor)
target_queue_length <- demand * target_mean_wait
return(target_queue_length)
}
20 changes: 10 additions & 10 deletions R/wl_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ wl_stats <- function(waiting_list,

# load
q_load <-
queue_load(referral_stats$demand.weekly, removal_stats$capacity.weekly)
calc_queue_load(referral_stats$demand.weekly, removal_stats$capacity.weekly)

# load too big
q_load_too_big <- (q_load >= 1.)
Expand All @@ -107,7 +107,7 @@ wl_stats <- function(waiting_list,
q_size <- utils::tail(queue_sizes, n = 1)[, 2]

# target queue size
q_target <- target_queue_size(referral_stats$demand.weekly, target_wait)
q_target <- calc_target_queue_size(referral_stats$demand.weekly, target_wait)

# queue too big
q_too_big <- (q_size > 2 * q_target)
Expand All @@ -122,12 +122,12 @@ wl_stats <- function(waiting_list,

# target capacity
if (!q_too_big) {
target_cap <- target_capacity(
referral_stats$demand.weekly,
target_wait,
4,
referral_stats$demand.cov,
removal_stats$capacity.cov)
target_cap <- calc_target_capacity(
referral_stats$demand.weekly,
target_wait,
4,
referral_stats$demand.cov,
removal_stats$capacity.cov)
# target_cap_weekly <- target_cap_daily * 7
} else {
target_cap <- NA
Expand All @@ -136,13 +136,13 @@ wl_stats <- function(waiting_list,
# relief capacity
if (q_too_big) {
relief_cap <-
relief_capacity(referral_stats$demand.weekly, q_size, q_target)
calc_relief_capacity(referral_stats$demand.weekly, q_size, q_target)
} else {
relief_cap <- NA
}

# pressure
# pressure <- waiting_list_pressure(mean_wait, target_wait)
# pressure <- calc_waiting_list_pressure(mean_wait, target_wait)
# TODO: talk to Neil about using *2 (in this function),
# or *4 in the formula below

Expand Down
60 changes: 30 additions & 30 deletions man/queue_load.Rd → man/calc_queue_load.Rd
100755 → 100644

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

15 changes: 10 additions & 5 deletions man/relief_capacity.Rd → man/calc_relief_capacity.Rd
100755 → 100644

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

10 changes: 5 additions & 5 deletions man/target_capacity.Rd → man/calc_target_capacity.Rd

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

Loading
Loading