Skip to content

Commit 3dff1f3

Browse files
committed
fix(results): remove arrivals with start time -1 (have confirmed for all that this means the time to next arrival was sampled for that patient, but it meant their arrival time came after the simulation end)
1 parent 7c28976 commit 3dff1f3

4 files changed

Lines changed: 83 additions & 26 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export(create_rehab_trajectory)
1313
export(model)
1414
export(sample_routing)
1515
export(transform_to_lnorm)
16+
importFrom(dplyr,filter)
1617
importFrom(simmer,add_generator)
1718
importFrom(simmer,branch)
1819
importFrom(simmer,get_attribute)

R/model.R

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#' may not wish to do if being set elsewhere - such as done in \code{runner()}).
77
#' Default is TRUE.
88
#'
9+
#' @importFrom dplyr filter
910
#' @importFrom simmer get_mon_arrivals get_mon_resources simmer wrap
1011
#' @importFrom utils capture.output
1112
#'
@@ -27,6 +28,7 @@ model <- function(run_number, param, set_seed = TRUE) {
2728
param[["rehab_los_lnorm"]] <- transform_to_lnorm(param[["rehab_los"]])
2829

2930
# Create simmer environment - set verbose to FALSE as using custom logs
31+
# (but can change to TRUE if want to see default simmer logs as well)
3032
env <- simmer("simulation", verbose = FALSE)
3133

3234
# Add ASU and rehab direct admission patient generators
@@ -41,14 +43,12 @@ model <- function(run_number, param, set_seed = TRUE) {
4143
}
4244

4345
# Add patient generator using the created trajectory
44-
sim_log <- capture.output(
45-
env <- add_patient_generator( # nolint
46-
env = env,
47-
trajectory = traj,
48-
unit = unit,
49-
patient_type = patient_type,
50-
param = param
51-
)
46+
env <- add_patient_generator(
47+
env = env,
48+
trajectory = traj,
49+
unit = unit,
50+
patient_type = patient_type,
51+
param = param
5252
)
5353
}
5454
}
@@ -75,12 +75,11 @@ model <- function(run_number, param, set_seed = TRUE) {
7575
}
7676
}
7777

78-
# Extract the monitored arrivals and resources information from the simmer
79-
# environment object
80-
result <- list(
81-
arrivals = get_mon_arrivals(env, per_resource = TRUE, ongoing = TRUE),
82-
resources = get_mon_resources(env)
83-
)
78+
# Extract the monitored arrivals info from the simmer environment object.
79+
# Remove patients with start time of -1, as they are patients whose arrival
80+
# was sampled but falls after the end of the smiulation.
81+
result <- get_mon_arrivals(env, ongoing = TRUE) |>
82+
filter(.data[["start_time"]] != -1L)
8483

8584
return(result)
8685
}

rmarkdown/analysis.Rmd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ output:
1111
```{r}
1212
# Load the package from the local directory
1313
devtools::load_all()
14+
```
1415

16+
```{r}
17+
# nolint start: undesirable_function_linter
1518
# Load the package
19+
library(dplyr)
1620
library(simulation)
21+
# nolint end
1722
```
1823

19-
2024
```{r}
2125
param <- create_parameters(log_to_console = TRUE)
22-
model(run_number = 1L, param = param, set_seed = TRUE)
26+
result <- model(run_number = 1L, param = param, set_seed = TRUE)
27+
arrange(result, start_time)
2328
```

rmarkdown/analysis.md

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
analysis
22
================
33
Amy Heather
4-
2025-07-01
4+
2025-07-02
55

66
``` r
77
# Load the package from the local directory
@@ -11,13 +11,30 @@ devtools::load_all()
1111
## ℹ Loading simulation
1212

1313
``` r
14+
# nolint start: undesirable_function_linter
1415
# Load the package
16+
library(dplyr)
17+
```
18+
19+
##
20+
## Attaching package: 'dplyr'
21+
22+
## The following objects are masked from 'package:stats':
23+
##
24+
## filter, lag
25+
26+
## The following objects are masked from 'package:base':
27+
##
28+
## intersect, setdiff, setequal, union
29+
30+
``` r
1531
library(simulation)
32+
# nolint end
1633
```
1734

1835
``` r
1936
param <- create_parameters(log_to_console = TRUE)
20-
model(run_number = 1L, param = param, set_seed = TRUE)
37+
result <- model(run_number = 1L, param = param, set_seed = TRUE)
2138
```
2239

2340
## [1] "Parameters:"
@@ -174,11 +191,46 @@ model(run_number = 1L, param = param, set_seed = TRUE)
174191
## [152] "19.8821: asu_stroke19: 🎯 Planned ASU -> 3 (other)"
175192
## [153] "19.8821: asu_stroke19: ⏳ ASU length of stay: 1.819"
176193

177-
## $arrivals
178-
## [1] name start_time end_time activity_time resource
179-
## <0 rows> (or 0-length row.names)
180-
##
181-
## $resources
182-
## [1] resource time server queue capacity queue_size system
183-
## [8] limit
184-
## <0 rows> (or 0-length row.names)
194+
``` r
195+
arrange(result, start_time)
196+
```
197+
198+
## name start_time end_time activity_time finished replication
199+
## 1 asu_other0 0.4473448 2.676165 2.2288198 TRUE 1
200+
## 2 asu_neuro0 0.5245442 4.171772 3.6472278 TRUE 1
201+
## 3 asu_stroke0 0.9062182 1.422308 0.5160899 TRUE 1
202+
## 4 asu_stroke1 1.1893125 5.509324 4.3200113 TRUE 1
203+
## 5 asu_other1 1.2902898 6.502389 5.2120987 TRUE 1
204+
## 6 asu_stroke2 1.9750085 12.640820 10.6658111 TRUE 1
205+
## 7 asu_stroke3 2.6540471 7.370079 4.7160317 TRUE 1
206+
## 8 asu_other2 2.7220399 6.960086 4.2380463 TRUE 1
207+
## 9 asu_neuro1 3.2678517 3.867813 0.5999612 TRUE 1
208+
## 10 asu_other3 5.9118414 9.356139 3.4442981 TRUE 1
209+
## 11 asu_other4 6.5630745 9.901922 3.3388479 TRUE 1
210+
## 12 asu_neuro2 6.7174941 NA NA FALSE 1
211+
## 13 asu_stroke4 7.4047666 11.548437 4.1436706 TRUE 1
212+
## 14 asu_stroke5 7.7291507 10.492783 2.7636327 TRUE 1
213+
## 15 asu_other5 8.9680111 9.644429 0.6764179 TRUE 1
214+
## 16 asu_stroke6 9.2809003 10.249020 0.9681194 TRUE 1
215+
## 17 rehab_stroke0 9.5062960 NA NA FALSE 1
216+
## 18 asu_stroke7 9.9287833 18.114076 8.1852931 TRUE 1
217+
## 19 asu_stroke8 10.0363922 NA NA FALSE 1
218+
## 20 asu_stroke9 10.3331093 10.844631 0.5115214 TRUE 1
219+
## 21 asu_neuro3 10.6050662 14.143857 3.5387909 TRUE 1
220+
## 22 asu_tia0 10.9892778 12.129621 1.1403433 TRUE 1
221+
## 23 asu_neuro4 13.5331919 NA NA FALSE 1
222+
## 24 asu_stroke10 13.6095765 16.845102 3.2355256 TRUE 1
223+
## 25 asu_neuro5 13.7205915 15.051997 1.3314053 TRUE 1
224+
## 26 asu_stroke11 13.8532754 NA NA FALSE 1
225+
## 27 asu_other6 13.8727452 15.859368 1.9866225 TRUE 1
226+
## 28 asu_stroke12 13.9904583 15.084152 1.0936941 TRUE 1
227+
## 29 rehab_stroke1 14.0813875 NA NA FALSE 1
228+
## 30 asu_stroke13 15.8908936 18.801468 2.9105743 TRUE 1
229+
## 31 asu_neuro6 16.6529204 NA NA FALSE 1
230+
## 32 asu_stroke14 17.1432238 NA NA FALSE 1
231+
## 33 asu_stroke15 18.1849052 NA NA FALSE 1
232+
## 34 asu_stroke16 18.3422720 NA NA FALSE 1
233+
## 35 asu_stroke17 18.8504573 NA NA FALSE 1
234+
## 36 asu_other7 19.7390660 NA NA FALSE 1
235+
## 37 asu_stroke18 19.8417499 NA NA FALSE 1
236+
## 38 asu_stroke19 19.8820623 NA NA FALSE 1

0 commit comments

Comments
 (0)