Skip to content

Commit 25d1159

Browse files
authored
Merge pull request #103 from pythonhealthdatascience/dev
Dev
2 parents 45f6b59 + 48dd1f0 commit 25d1159

Some content is hidden

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

48 files changed

+536
-420
lines changed

.Rbuildignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@
1313
^rmarkdown$
1414
^CITATION\.cff$
1515
^run_rmarkdown\.sh$
16-
^inputs$
1716
^mock_paper\.md$

CITATION.cff

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ authors:
1414
1515
affiliation: University of Exeter
1616
orcid: 'https://orcid.org/0000-0002-6596-3479'
17+
- given-names: Tom
18+
family-names: Monks
19+
20+
affiliation: University of Exeter Medical School
21+
orcid: http://orcid.org/0000-0003-2631-4481
1722
repository-code: >-
1823
https://github.com/pythonhealthdatascience/rdesrap_mms
1924
abstract: >-
2025
Reproducible analytical pipeline (RAP) for R discrete-event simulation (DES)
2126
implementing a simple M/M/s queueing model.
22-
version: 0.4.0
23-
date-released: '2025-06-04'
27+
version: 0.5.0
28+
date-released: '2025-11-07'

DESCRIPTION

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
Package: simulation
22
Type: Package
33
Title: Simulation
4-
Version: 0.4.0
4+
Version: 0.5.0
55
Authors@R: c(
66
person(
77
"Amy", "Heather",
88
email = "[email protected]",
99
role = c("aut", "cre")
10+
),
11+
person(
12+
"Tom", "Monks",
13+
email = "[email protected]",
14+
role = c("ctb")
1015
)
1116
)
1217
URL: https://github.com/pythonhealthdatascience/rdesrap_mms
@@ -19,7 +24,6 @@ RoxygenNote: 7.3.2
1924
Imports:
2025
simmer,
2126
dplyr,
22-
purrr,
2327
rlang,
2428
tidyr,
2529
tidyselect,

NAMESPACE

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,40 @@ export(valid_inputs)
2424
importFrom(R6,R6Class)
2525
importFrom(dplyr,across)
2626
importFrom(dplyr,arrange)
27-
importFrom(dplyr,bind_cols)
2827
importFrom(dplyr,bind_rows)
2928
importFrom(dplyr,desc)
3029
importFrom(dplyr,filter)
31-
importFrom(dplyr,full_join)
3230
importFrom(dplyr,group_by)
3331
importFrom(dplyr,lead)
3432
importFrom(dplyr,left_join)
3533
importFrom(dplyr,mutate)
3634
importFrom(dplyr,n)
3735
importFrom(dplyr,n_distinct)
36+
importFrom(dplyr,pull)
3837
importFrom(dplyr,rename)
38+
importFrom(dplyr,row_number)
3939
importFrom(dplyr,select)
4040
importFrom(dplyr,slice)
41+
importFrom(dplyr,slice_head)
4142
importFrom(dplyr,summarise)
4243
importFrom(dplyr,transmute)
4344
importFrom(dplyr,ungroup)
45+
importFrom(future,availableCores)
4446
importFrom(future,multisession)
4547
importFrom(future,plan)
4648
importFrom(future,sequential)
4749
importFrom(future.apply,future_lapply)
50+
importFrom(ggplot2,aes)
4851
importFrom(ggplot2,aes_string)
4952
importFrom(ggplot2,annotate)
5053
importFrom(ggplot2,geom_line)
54+
importFrom(ggplot2,geom_ribbon)
5155
importFrom(ggplot2,geom_vline)
5256
importFrom(ggplot2,ggplot)
5357
importFrom(ggplot2,ggsave)
5458
importFrom(ggplot2,labs)
5559
importFrom(ggplot2,theme_minimal)
5660
importFrom(gridExtra,marrangeGrob)
57-
importFrom(purrr,reduce)
5861
importFrom(rlang,.data)
5962
importFrom(simmer,add_generator)
6063
importFrom(simmer,add_resource)
@@ -73,7 +76,9 @@ importFrom(simmer,timeout)
7376
importFrom(simmer,trajectory)
7477
importFrom(simmer,wrap)
7578
importFrom(stats,rexp)
79+
importFrom(stats,sd)
7680
importFrom(stats,setNames)
81+
importFrom(stats,t.test)
7782
importFrom(tibble,tibble)
7883
importFrom(tidyr,drop_na)
7984
importFrom(tidyr,pivot_wider)

NEWS.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
1-
# Simple M/M/s queuing model: R DES RAP (unreleased)
1+
# Simple M/M/s queuing model: R DES RAP v0.5.0
22

3-
TBC.
3+
This update adds new performance measures and tests, improves the GitHub actions, implements some fixes and documentation improvements, among other changes.
4+
5+
## New features
6+
7+
* Add choice of operating system when manually trigger R-CMD-check GitHub action.
8+
* Add check in model validation for non-null file path when `log_to_file = TRUE`.
9+
* Calculate test coverage.
10+
* Environment - add `covr` and `queueing` and `DT` and switched to "all" snapshot type.
11+
* Add `seed_offset` and ran sensitivity analysis on seed in `choosing_replications.Rmd`.
12+
* Add test comparing against analytical queueing theory model from `queueing` package.
13+
* Add mean time in system to performance measures.
14+
* Add `CODE_OF_CONDUCT.md`.
15+
16+
## Bug fixes
17+
18+
* Skip parallel processing test on Mac GitHub action.
19+
* Fix deviation calculation so it doesn't get stuck for NA/0.
20+
* Corrected choice of warm-up to run model for longer.
21+
* Fixed/expanded back tests.
22+
23+
## Other changes
24+
25+
* Replaced `rap_template_r_des` with `rdesrap_mms`.
26+
* Changed all magrittr's `%>%` to be base R's `>|` (as per tidyverse style guide).
27+
* Improved `README.md` and `CONTRIBUTING.md`.
28+
* Simplify package loading.
29+
* Reorganised tests.
30+
* Update parameters to match python version of model.
31+
* Adjusted `analysis.Rmd` bin widths to be more consistent with python version of analysis.
32+
* Other minor corrections and amendments (e.g., linting, docstrings, tests).
433

534
# R DES RAP Template 0.4.0
635

R/choose_replications.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ ReplicationsAlgorithm <- R6Class("ReplicationsAlgorithm", list( # nolint: object
514514
#' @param metric Name of performance metric to assess.
515515
#' @param verbose Boolean, whether to print messages about parameters.
516516
#'
517+
#' @importFrom dplyr filter pull select slice_head
518+
#' @importFrom stats sd t.test
517519
#' @importFrom utils tail
518520
#'
519521
#' @return Dataframe with results from each replication.
@@ -607,6 +609,10 @@ confidence_interval_method <- function(replications, desired_precision,
607609
#' @param file_path Path and filename to save the plot to.
608610
#' @param min_rep The number of replications required to meet the desired
609611
#' precision.
612+
#'
613+
#' @importFrom ggplot2 aes geom_line geom_ribbon geom_vline ggplot ggsave labs
614+
#' @importFrom ggplot2 theme_minimal
615+
#' @importFrom rlang .data
610616

611617
plot_replication_ci <- function(
612618
conf_ints, yaxis_title, file_path = NULL, min_rep = NULL

R/choose_warmup.R

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@
55
#' @param result Named list with `arrivals` containing output from
66
#' `get_mon_arrivals()` and `resources` containing output from
77
#' `get_mon_resources()` (`per_resource = TRUE` and `ongoing = TRUE`).
8+
#' @param simulation_end_time Time at end of simulation run.
89
#' @param file_path Path to save figure to.
910
#' @param warm_up Location on X axis to plot vertical red line indicating the
1011
#' chosen warm-up period. Defaults to NULL, which will not plot a line.
1112
#'
12-
#' @importFrom dplyr rename
13-
#' @importFrom ggplot2 ggplot geom_line aes_string labs theme_minimal geom_vline
14-
#' @importFrom ggplot2 annotate ggsave
13+
#' @importFrom dplyr arrange group_by mutate rename select ungroup
14+
#' @importFrom ggplot2 aes_string annotate geom_line geom_vline ggsave labs
15+
#' @importFrom ggplot2 theme_minimal ggplot
1516
#' @importFrom gridExtra marrangeGrob
17+
#' @importFrom rlang .data
18+
#' @importFrom tidyselect all_of
1619
#'
1720
#' @export
1821

19-
time_series_inspection <- function(result, file_path, warm_up = NULL) {
22+
time_series_inspection <- function(
23+
result, simulation_end_time, file_path, warm_up = NULL
24+
) {
2025

2126
plot_list <- list()
2227

@@ -29,24 +34,28 @@ time_series_inspection <- function(result, file_path, warm_up = NULL) {
2934
# Wait time of each patient at each time point
3035
metrics[[1L]] <- result[["arrivals"]] |>
3136
rename(time = .data[["serve_start"]]) |>
32-
select(.data[["replication"]],
33-
.data[["time"]],
34-
.data[["wait_time"]])
35-
36-
# Service length of each patient at each time point
37-
metrics[[2L]] <- result[["arrivals"]] |>
38-
rename(time = .data[["serve_start"]]) |>
39-
select(.data[["replication"]],
40-
.data[["time"]],
41-
.data[["serve_length"]])
37+
dplyr::select(all_of(c("replication", "time", "wait_time")))
4238

4339
# Utilisation at each time point
44-
metrics[[3L]] <- calc_utilisation(result[["resources"]],
40+
metrics[[2L]] <- calc_utilisation(result[["resources"]],
41+
simulation_end_time = simulation_end_time,
4542
groups = c("resource", "replication"),
4643
summarise = FALSE) |>
47-
select(.data[["replication"]],
48-
.data[["time"]],
49-
.data[["utilisation"]])
44+
dplyr::select(all_of(c("replication", "time", "utilisation")))
45+
46+
# Queue length at each timepoint
47+
metrics[[3L]] <- result[["arrivals"]] |>
48+
rename(time = .data[["start_time"]]) |>
49+
dplyr::select(all_of(c("replication", "time", "queue_on_arrival")))
50+
51+
# Time in system at each timepoint
52+
metrics[[4L]] <- result[["arrivals"]] |>
53+
rename(time = .data[["start_time"]]) |>
54+
dplyr::select(all_of(c("replication", "time", "time_in_system")))
55+
56+
# Patients in system at each timepoint
57+
metrics[[5L]] <- rename(result[["patients_in_service"]],
58+
patients_in_system = .data[["count"]])
5059

5160
# Loop through all the dataframes in df_list
5261
for (i in seq_along(metrics)) {

0 commit comments

Comments
 (0)