Skip to content

Commit d6d6ba5

Browse files
committed
refactor(load+strokenoesd): remove redundant library(simulation) when using load_all(), and change stroke_noesd to stroke_no_esd to match python
1 parent 177f2fa commit d6d6ba5

14 files changed

+201
-153
lines changed

R/create_asu_trajectory.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ create_asu_trajectory <- function(env, patient_type, param) {
5555
los_params <- switch(
5656
dest,
5757
esd = param[["asu_los_lnorm"]][["stroke_esd"]],
58-
rehab = param[["asu_los_lnorm"]][["stroke_noesd"]],
58+
rehab = param[["asu_los_lnorm"]][["stroke_no_esd"]],
5959
other = param[["asu_los_lnorm"]][["stroke_mortality"]],
6060
stop("Stroke post-asu destination '", dest, "' invalid",
6161
call. = FALSE)

R/create_rehab_trajectory.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ create_rehab_trajectory <- function(env, patient_type, param) {
5555
los_params <- switch(
5656
dest,
5757
esd = param[["rehab_los_lnorm"]][["stroke_esd"]],
58-
other = param[["rehab_los_lnorm"]][["stroke_noesd"]],
58+
other = param[["rehab_los_lnorm"]][["stroke_no_esd"]],
5959
stop("Stroke post-rehab destination '", dest, "' invalid",
6060
call. = FALSE)
6161
)

R/parameters.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ create_rehab_arrivals <- function(
4040
#'
4141
#' Mean and standard deviation (SD) of LOS in days in the ASU.
4242
#'
43-
#' @param stroke_noesd_mean Numeric. Mean LOS for stroke patients without early
43+
#' @param stroke_no_esd_mean Numeric. Mean LOS for stroke patients without early
4444
#' supported discharged (ESD).
45-
#' @param stroke_noesd_sd Numeric. SD LOS for stroke patients without ESD.
45+
#' @param stroke_no_esd_sd Numeric. SD LOS for stroke patients without ESD.
4646
#' @param stroke_esd_mean Numeric. Mean LOS for stroke patients with ESD.
4747
#' @param stroke_esd_sd Numeric. SD LOS for stroke patients with ESD.
4848
#' @param stroke_mortality_mean Numeric. Mean LOS for stroke patients who pass
@@ -61,15 +61,15 @@ create_rehab_arrivals <- function(
6161
#' @export
6262

6363
create_asu_los <- function(
64-
stroke_noesd_mean = 7.4, stroke_noesd_sd = 8.61,
64+
stroke_no_esd_mean = 7.4, stroke_no_esd_sd = 8.61,
6565
stroke_esd_mean = 4.6, stroke_esd_sd = 4.8,
6666
stroke_mortality_mean = 7.0, stroke_mortality_sd = 8.7,
6767
tia_mean = 1.8, tia_sd = 2.3,
6868
neuro_mean = 4.0, neuro_sd = 5.0,
6969
other_mean = 3.8, other_sd = 5.2
7070
) {
7171
list(
72-
stroke_noesd = list(mean = stroke_noesd_mean, sd = stroke_noesd_sd),
72+
stroke_no_esd = list(mean = stroke_no_esd_mean, sd = stroke_no_esd_sd),
7373
stroke_esd = list(mean = stroke_esd_mean, sd = stroke_esd_sd),
7474
stroke_mortality = list(mean = stroke_mortality_mean,
7575
sd = stroke_mortality_sd),
@@ -81,9 +81,9 @@ create_asu_los <- function(
8181

8282
#' Rehabilitation unit length of stay (LOS) distributions (days).
8383
#'
84-
#' @param stroke_noesd_mean Numeric. Mean LOS for stroke patients without early
84+
#' @param stroke_no_esd_mean Numeric. Mean LOS for stroke patients without early
8585
#' supported discharged (ESD).
86-
#' @param stroke_noesd_sd Numeric. SD LOS for stroke patients without ESD.
86+
#' @param stroke_no_esd_sd Numeric. SD LOS for stroke patients without ESD.
8787
#' @param stroke_esd_mean Numeric. Mean LOS for stroke patients with ESD.
8888
#' @param stroke_esd_sd Numeric. SD LOS for stroke patients with ESD.
8989
#' @param tia_mean Numeric. Mean LOS for transient ischemic attack (TIA)
@@ -98,14 +98,14 @@ create_asu_los <- function(
9898
#' @export
9999

100100
create_rehab_los <- function(
101-
stroke_noesd_mean = 28.4, stroke_noesd_sd = 27.2,
101+
stroke_no_esd_mean = 28.4, stroke_no_esd_sd = 27.2,
102102
stroke_esd_mean = 30.3, stroke_esd_sd = 23.1,
103103
tia_mean = 18.7, tia_sd = 23.5,
104104
neuro_mean = 27.6, neuro_sd = 28.4,
105105
other_mean = 16.1, other_sd = 14.1
106106
) {
107107
list(
108-
stroke_noesd = list(mean = stroke_noesd_mean, sd = stroke_noesd_sd),
108+
stroke_no_esd = list(mean = stroke_no_esd_mean, sd = stroke_no_esd_sd),
109109
stroke_esd = list(mean = stroke_esd_mean, sd = stroke_esd_sd),
110110
tia = list(mean = tia_mean, sd = tia_sd),
111111
neuro = list(mean = neuro_mean, sd = neuro_sd),

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ The simulation code is in the `R/` folder as a local package. There are files ex
5959
**Install the local package:**
6060

6161
```{.r}
62-
devtools::install()
62+
devtools::install() # Needed if running in parallel
63+
devtools::load_all() # Sufficient if running sequentially
64+
6365
library(simulation)
6466
```
6567

inputs/data_dictionary.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Data dictionary for `parameters.csv`
2+
3+
| Column | Data type | Description | Possible values |
4+
| - | - | - | - |
5+
| unit | str | Hospital unit | `asu`: Acute Stroke Unit<br>`rehab`: Rehabilitation Unit (post-acute recovery care) |
6+
| parameter | str | Type of operational metric | `iat`: Inter-arrival time (time between patient admissions)<br>`los`: Length of stay (duration from admission to discharge)<br>`routing`: Transition probability between care pathways |
7+
| type | str | Patient classification or care transition path | **For `iat`/`los`:**<br>`stroke`: Stroke patients<br>`stroke_esd`: Stroke patients transferred to Early Supported Discharge<br>`stroke_no_esd`: Stroke patients not transferred to Early Supported Discharge<br>`tia`: Transient Ischemic Attack patients<br>`neuro`: Complex neurological patients<br>`other`: Other patient types<br><br>**For `routing`:**<br>`[diagnosis]_rehab`: Probability of transferring to rehabilitation unit<br>`[diagnosis]_esd`: Probability of Early Supported Discharge<br>`[diagnosis]_other`: Probability of other discharge pathways |
8+
| mean | float | **For `iat`:** Mean days between admissions<br>**For `los`:** Mean days in unit<br>**For `routing`:** Probability (0-1 scale) | - |
9+
| sd | float | Standard deviation of the mean | - |

inputs/parameters.csv

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
unit,parameter,type,mean,sd
2+
asu,iat,stroke,1.2,NA
3+
asu,iat,tia,9.3,NA
4+
asu,iat,neuro,3.6,NA
5+
asu,iat,other,3.2,NA
6+
rehab,iat,stroke,21.8,NA
7+
rehab,iat,neuro,31.7,NA
8+
rehab,iat,other,28.6,NA
9+
asu,los,stroke_no_esd,7.4,8.61
10+
asu,los,stroke_esd,4.6,4.8
11+
asu,los,tia,1.8,2.3
12+
asu,los,neuro,4,5
13+
asu,los,other,3.8,5.2
14+
rehab,los,stroke_no_esd,28.4,27.2
15+
rehab,los,stroke_esd,30.3,2un3.1
16+
rehab,los,tia,18.7,23.5
17+
rehab,los,neuro,27.6,28.4
18+
rehab,los,other,16.1,14.1
19+
asu,routing,stroke_rehab,0.24,NA
20+
asu,routing,stroke_esd,0.13,NA
21+
asu,routing,stroke_other,0.63,NA
22+
asu,routing,tia_rehab,0.01,NA
23+
asu,routing,tia_esd,0.01,NA
24+
asu,routing,tia_other,0.98,NA
25+
asu,routing,neuro_rehab,0.11,NA
26+
asu,routing,neuro_esd,0.05,NA
27+
asu,routing,neuro_other,0.84,NA
28+
asu,routing,other_rehab,0.05,NA
29+
asu,routing,other_esd,0.1,NA
30+
asu,routing,other_other,0.85,NA
31+
rehab,routing,stroke_esd,0.4,NA
32+
rehab,routing,stroke_other,0.6,NA
33+
rehab,routing,tia_esd,0,NA
34+
rehab,routing,tia_other,1,NA
35+
rehab,routing,neuro_esd,0.09,NA
36+
rehab,routing,neuro_other,0.91,NA
37+
rehab,routing,other_esd,0.13,NA
38+
rehab,routing,other_other,0.88,NA

man/create_asu_los.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/create_rehab_los.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

outputs/log_example.log

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Parameters:
22
asu_arrivals=list(stroke = 1.2, tia = 9.3, neuro = 3.6, other = 3.2);
33
rehab_arrivals=list(stroke = 3, neuro = 31.7, other = 28.6);
4-
asu_los=list(stroke_noesd = list(mean = 7.4, sd = 8.61), stroke_esd = list(mean = 4.6, sd = 4.8), stroke_mortality = list(mean = 7, sd = 8.7), tia = list(mean = 1.8, sd = 2.3), neuro = list(mean = 4, sd = 5), other = list(mean = 3.8, sd = 5.2));
5-
rehab_los=list(stroke_noesd = list(mean = 28.4, sd = 27.2), stroke_esd = list(mean = 30.3, sd = 23.1), tia = list(mean = 18.7, sd = 23.5), neuro = list(mean = 27.6, sd = 28.4), other = list(mean = 16.1, sd = 14.1));
4+
asu_los=list(stroke_no_esd = list(mean = 7.4, sd = 8.61), stroke_esd = list(mean = 4.6, sd = 4.8), stroke_mortality = list(mean = 7, sd = 8.7), tia = list(mean = 1.8, sd = 2.3), neuro = list(mean = 4, sd = 5), other = list(mean = 3.8, sd = 5.2));
5+
rehab_los=list(stroke_no_esd = list(mean = 28.4, sd = 27.2), stroke_esd = list(mean = 30.3, sd = 23.1), tia = list(mean = 18.7, sd = 23.5), neuro = list(mean = 27.6, sd = 28.4), other = list(mean = 16.1, sd = 14.1));
66
asu_routing=list(stroke = list(rehab = 0.24, esd = 0.13, other = 0.63), tia = list(rehab = 0.01, esd = 0.01, other = 0.98), neuro = list(rehab = 0.11, esd = 0.05, other = 0.84), other = list(rehab = 0.05, esd = 0.1, other = 0.85));
77
rehab_routing=list(stroke = list(esd = 0.4, other = 0.6), tia = list(esd = 0, other = 1), neuro = list(esd = 0.09, other = 0.91), other = list(esd = 0.13, other = 0.88));
88
warm_up_period=3;
@@ -14,8 +14,8 @@ asu_arrivals=list(stroke = 1.2, tia = 9.3, neuro = 3.6, other = 3.2);
1414
log_to_file=TRUE;
1515
file_path=../outputs/log_example.log;
1616
verbose=TRUE;
17-
asu_los_lnorm=list(stroke_noesd = list(meanlog = 1.57347219029677, sdlog = 0.925211121759084), stroke_esd = list(meanlog = 1.15775021244827, sdlog = 0.858261138636461), stroke_mortality = list(meanlog = 1.47890496960638, sdlog = 0.966442113578391), tia = list(meanlog = 0.103778649052444, sdlog = 0.983878057331979), neuro = list(meanlog = 0.915802688887627, sdlog = 0.970042960112864), other = list(meanlog = 0.807396441784017, sdlog = 1.02723378541433));
18-
rehab_los_lnorm=list(stroke_noesd = list(meanlog = 3.02093582638726, sdlog = 0.806787851643665), stroke_esd = list(meanlog = 3.18205014379696, sdlog = 0.676901128257839), tia = list(meanlog = 2.45477304821951, sdlog = 0.973396605337238), neuro = list(meanlog = 2.95675141458562, sdlog = 0.849781569743057), other = list(meanlog = 2.49418211833932, sdlog = 0.754502688730926))
17+
asu_los_lnorm=list(stroke_no_esd = list(meanlog = 1.57347219029677, sdlog = 0.925211121759084), stroke_esd = list(meanlog = 1.15775021244827, sdlog = 0.858261138636461), stroke_mortality = list(meanlog = 1.47890496960638, sdlog = 0.966442113578391), tia = list(meanlog = 0.103778649052444, sdlog = 0.983878057331979), neuro = list(meanlog = 0.915802688887627, sdlog = 0.970042960112864), other = list(meanlog = 0.807396441784017, sdlog = 1.02723378541433));
18+
rehab_los_lnorm=list(stroke_no_esd = list(meanlog = 3.02093582638726, sdlog = 0.806787851643665), stroke_esd = list(meanlog = 3.18205014379696, sdlog = 0.676901128257839), tia = list(meanlog = 2.45477304821951, sdlog = 0.973396605337238), neuro = list(meanlog = 2.95675141458562, sdlog = 0.849781569743057), other = list(meanlog = 2.49418211833932, sdlog = 0.754502688730926))
1919
Log:
2020
0.865903: asu_other0: 🚶 Arrived at ASU
2121
0.865903: asu_other0: 🎯 Planned ASU -> 3 (other)

rmarkdown/analysis.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ devtools::install(upgrade = "never")
7070
## checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information
7171
## ─ checking for LF line-endings in source and make files and shell scripts
7272
## ─ checking for empty or unneeded directories
73+
## Removed empty directory ‘simulation/tests/testthat/_snaps’
7374
## Omitted ‘LazyData’ from DESCRIPTION
7475
## ─ building ‘simulation_0.1.0.tar.gz’
7576
##
7677
## Running /opt/R/4.4.1/lib/R/bin/R CMD INSTALL \
77-
## /tmp/RtmpH3Tbtm/simulation_0.1.0.tar.gz --install-tests
78+
## /tmp/Rtmpz9aafi/simulation_0.1.0.tar.gz --install-tests
7879
## * installing to library ‘/home/amy/.cache/R/renv/library/rdesrap_stroke-34041c45/linux-ubuntu-noble/R-4.4/x86_64-pc-linux-gnu’
7980
## * installing *source* package ‘simulation’ ...
8081
## ** using staged installation
@@ -1048,4 +1049,4 @@ seconds <- as.integer(runtime %% 60L)
10481049
cat(sprintf("Notebook run time: %dm %ds", minutes, seconds))
10491050
```
10501051

1051-
## Notebook run time: 1m 38s
1052+
## Notebook run time: 2m 33s

0 commit comments

Comments
 (0)