Skip to content

Commit b1c6876

Browse files
authored
Merge pull request #8 from pythonhealthdatascience/dev
Dev
2 parents 7de0975 + 8cf18b1 commit b1c6876

28 files changed

+882
-163
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ vignettes/*.pdf
3939
# R Environment Variables
4040
.Renviron
4141

42-
# pkgdown site
43-
docs/
44-
4542
# translation temp files
4643
po/*~
4744

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ abstract: >-
2020
Reproducible analytical pipeline (RAP) for R discrete-event simulation (DES)
2121
implementing the Stroke Capacity Planning Model from Monks et al. 2016.
2222
version: 0.1.0
23-
date-released: '2025-06-30'
23+
date-released: '2025-07-11'

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@
22
# Stroke capacity planning model: R DES RAP 0.1.0
33

44
🌱 First release of the R stroke model.
5+
6+
## New features
7+
8+
* Implementation of the stroke model in R as a package (`R/`).
9+
* Reproduction of paper results (`rmarkdown/analysis.Rmd`).
10+
* Other RMarkdown files to generate results for tests, demonstrate logging, and how parameters can be loaded from a csv (`rmarkdown/`).
11+
* Back, functional and unit tests (`tests/`).
12+
* Other features include continuous integration (tests and linting), checklists, R environment, and other metadata.

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: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,45 @@ renv::snapshot()
5656

5757
The simulation code is in the `R/` folder as a local package. There are files executing the model and analysing the results in `rmarkdown/`.
5858

59-
To run the model with base parameters once or with replications:
59+
**Install the local package:**
6060

6161
```{.r}
62-
# TODO
62+
devtools::install() # Needed if running in parallel
63+
devtools::load_all() # Sufficient if running sequentially
64+
65+
library(simulation)
66+
```
67+
68+
**Run a single simulation:**
69+
70+
```{.r}
71+
param <- create_parameters(number_of_runs = 1L)
72+
single_results <- runner(param = param)
6373
```
6474

65-
Example altering the model parameters:
75+
**Run multiple replications:**
6676

6777
```{.r}
68-
# TODO
78+
param <- create_parameters(number_of_runs = 5L)
79+
single_results <- runner(param = param)
80+
```
81+
82+
**Run all analyses (from command line):**
83+
84+
```{.r}
85+
bash run_rmarkdown.sh
86+
```
87+
88+
**Run tests:**
89+
90+
```{.r}
91+
devtools::test()
92+
```
93+
94+
**Lint code:**
95+
96+
```{.r}
97+
lintr::lint_dir()
6998
```
7099

71100
### Generating the results from the article
@@ -87,23 +116,27 @@ To generate these, simply execute `rmarkdown/analysis.Rmd`.
87116

88117
Original:
89118

119+
![](docs/article/fig1.png)
120+
90121
From this repository:
91122

92-
**TODO**
123+
![](outputs/figure1_asu.png)
93124

94125
**Figure 3**
95126

96127
Original:
97128

129+
![](docs/article/fig3.png)
130+
98131
From this repository:
99132

100-
**TODO**
133+
![](outputs/figure3_asu.png)
101134

102135
<br>
103136

104137
## Run time and machine specification
105138

106-
The run time for this analysis (`notebooks/analysis.Rm`) is **TODO** seconds. This was on an Intel Core i7-12700H, 32GB RAM, Ubuntu 24.04.1.
139+
The run time for this analysis (`notebooks/analysis.Rmd`) is **1m 38s** seconds. This was on an Intel Core i7-12700H, 32GB RAM, Ubuntu 24.04.1.
107140

108141
The other notebooks generate results for tests and illustrate other functionality (e.g. importing parameters from csv, running with logs), and these just take a second or two.
109142

548 KB
Binary file not shown.

docs/article/fig1.png

24.4 KB
Loading

docs/article/fig2.png

58.5 KB
Loading

0 commit comments

Comments
 (0)