Skip to content

Commit a70289e

Browse files
authored
Merge pull request #65 from pythonhealthdatascience/dev
Dev
2 parents 7d77c55 + 784839e commit a70289e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+134123
-646
lines changed

DESCRIPTION

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ Imports:
2929
ggplot2,
3030
tibble,
3131
gridExtra,
32-
R6
32+
R6,
33+
fitdistrplus,
34+
lubridate,
35+
plotly
3336
Suggests:
3437
testthat (>= 3.0.0),
3538
patrick,

R/choose_replications.R

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ ReplicationsAlgorithm <- R6Class("ReplicationsAlgorithm", list( # nolint: object
223223

224224
#' @field desired_precision The target half width precision for the algorithm
225225
#' (i.e. percentage deviation of the confidence interval from the mean,
226-
#' expressed as a proportion, e.g. 0.05 = 5\%).
226+
#' expressed as a proportion, e.g. 0.1 = 10\%). Choice is fairly arbitrary.
227227
desired_precision = NA,
228228

229229
#' @field initial_replications Number of initial replications to perform.
@@ -257,15 +257,17 @@ ReplicationsAlgorithm <- R6Class("ReplicationsAlgorithm", list( # nolint: object
257257
#' @param initial_replications Number of initial replications to perform.
258258
#' @param look_ahead Minimum additional replications to look ahead.
259259
#' @param replication_budget Maximum allowed replications.
260+
#' @param verbose Boolean, whether to print messages about parameters.
260261
initialize = function(
261262
param,
262263
metrics = c("mean_waiting_time_nurse",
263264
"mean_serve_time_nurse",
264265
"utilisation_nurse"),
265-
desired_precision = 0.05,
266+
desired_precision = 0.1,
266267
initial_replications = 3L,
267268
look_ahead = 5L,
268-
replication_budget = 1000L
269+
replication_budget = 1000L,
270+
verbose = TRUE
269271
) {
270272
self$param <- param
271273
self$metrics <- metrics
@@ -277,6 +279,12 @@ ReplicationsAlgorithm <- R6Class("ReplicationsAlgorithm", list( # nolint: object
277279
# Initially set reps to the number of initial replications
278280
self$reps <- initial_replications
279281

282+
# Print the parameters
283+
if (isTRUE(verbose)) {
284+
print("Model parameters:") # nolint: print_linter
285+
print(self$param)
286+
}
287+
280288
# Check validity of provided parameters
281289
self$valid_inputs()
282290
},
@@ -495,16 +503,20 @@ ReplicationsAlgorithm <- R6Class("ReplicationsAlgorithm", list( # nolint: object
495503
#' @param replications Number of times to run the model.
496504
#' @param desired_precision Desired mean deviation from confidence interval.
497505
#' @param metric Name of performance metric to assess.
506+
#' @param verbose Boolean, whether to print messages about parameters.
498507
#'
499508
#' @importFrom utils tail
500509
#'
501510
#' @return Dataframe with results from each replication.
502511
#' @export
503512

504513
confidence_interval_method <- function(replications, desired_precision,
505-
metric) {
514+
metric, verbose = TRUE) {
506515
# Run model for specified number of replications
507516
param <- parameters(number_of_runs = replications)
517+
if (isTRUE(verbose)) {
518+
print(param)
519+
}
508520
results <- runner(param, use_future_seeding = FALSE)[["run_results"]]
509521

510522
# Initialise list to store the results

R/scenarios.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
#' different values to run in scenarios
55
#' @param base_list List of parameters to use as base for scenarios, which can
66
#' be partial (as will input to parameters() function).
7+
#' @param verbose Boolean, whether to print messages about scenarios as run.
78
#'
89
#' @return Tibble with results from each replication for each scenario.
910
#' @export
1011

11-
run_scenarios <- function(scenarios, base_list) {
12+
run_scenarios <- function(scenarios, base_list, verbose = TRUE) {
1213
# Generate all permutations of the scenarios
1314
all_scenarios <- expand.grid(scenarios)
1415

1516
# Preview the number of scenarios
16-
message(sprintf("There are %d scenarios. Running:", nrow(all_scenarios)))
17+
if (isTRUE(verbose)) {
18+
message(sprintf("There are %d scenarios.", nrow(all_scenarios)))
19+
message("Base parameters:")
20+
print(base_list)
21+
}
1722

1823
results <- list()
1924

@@ -27,7 +32,11 @@ run_scenarios <- function(scenarios, base_list) {
2732
formatted_scenario <- toString(
2833
paste0(names(scenario_to_run), " = ", scenario_to_run)
2934
)
30-
message("Scenario: ", formatted_scenario)
35+
36+
# Print the scenario currently running
37+
if (isTRUE(verbose)) {
38+
message("Scenario: ", formatted_scenario)
39+
}
3140

3241
# Create parameter list with scenario-specific values
3342
s_args <- c(scenario_to_run, list(scenario_name = index))

README.md

Lines changed: 134 additions & 248 deletions
Large diffs are not rendered by default.

docs/heather_2025.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ As part of the project STARS (Sharing Tools and Artefacts for Reproducible Simul
88
| - | - | - |
99
| **Set-up** |
1010
| Share code with an open licence (⭐) || `LICENSE` and `LICENSE.md` |
11-
| Link publication to a specific version of the code | N/A | No publication. |
11+
| Link publication to a specific version of the code | N/A | The mock paper images directly from the latest GitHub, so is not stated as being linked to a specific version of the code, like a typical publication. |
1212
| List dependencies and versions || `renv.lock` |
1313
| **Running the model** |
1414
| Provide code for all scenarios and sensitivity analyses (⭐) || Within `analysis.Rmd` |

docs/nhs_rap.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ RAP fundamentals offering resilience against future change.
1515
| Data produced by code in an open-source language (e.g., Python, R, SQL). || R |
1616
| Code is version controlled (see [Git basics](https://nhsdigital.github.io/rap-community-of-practice/training_resources/git/introduction-to-git/) and [using Git collaboratively](https://nhsdigital.github.io/rap-community-of-practice/training_resources/git/using-git-collaboratively/) guides). || [GitHub](https://github.com/pythonhealthdatascience/rap_template_r_des) |
1717
| Repository includes a README.md file (or equivalent) that clearly details steps a user must follow to reproduce the code (use [NHS Open Source Policy section on Readmes](https://github.com/nhsx/open-source-policy/blob/main/open-source-policy.md#b-readmes) as a guide). || - |
18-
| Code has been [peer reviewed](https://nhsdigital.github.io/rap-community-of-practice/implementing_RAP/workflow/code-review/). | | TODO |
19-
| Code is [published in the open](https://nhsdigital.github.io/rap-community-of-practice/implementing_RAP/publishing_code/how-to-publish-your-code-in-the-open/) and linked to & from accompanying publication (if relevant). | ✅ & N/A | Shared openly. No publication. |
18+
| Code has been [peer reviewed](https://nhsdigital.github.io/rap-community-of-practice/implementing_RAP/workflow/code-review/). | | Peer reviewed by Tom Monks |
19+
| Code is [published in the open](https://nhsdigital.github.io/rap-community-of-practice/implementing_RAP/publishing_code/how-to-publish-your-code-in-the-open/) and linked to & from accompanying publication (if relevant). | ✅ & N/A | Shared openly. No publication, but mock publication included in repository. |
2020

2121
## 🥈 Silver
2222

0 commit comments

Comments
 (0)