{"id":24360607,"url":"https://github.com/pythonhealthdatascience/rap_template_r_des","last_synced_at":"2025-03-12T08:43:48.456Z","repository":{"id":271853834,"uuid":"899059771","full_name":"pythonhealthdatascience/rap_template_r_des","owner":"pythonhealthdatascience","description":"Template reproducible analytical pipeline (RAP) for simple R discrete-event simulation (DES) model.","archived":false,"fork":false,"pushed_at":"2025-03-11T11:10:06.000Z","size":67591,"stargazers_count":1,"open_issues_count":13,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T11:24:36.550Z","etag":null,"topics":["discrete-event-simulation","healthcare","healthcare-analysis","r","reproducible-analysis","reproducible-analytical-pipeline","reproducible-analytical-pipelines","reproducible-research","reproducible-science","simmer","simulation","simulation-framework","simulation-model","simulation-modeling","simulation-modelling","template"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pythonhealthdatascience.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-05T14:49:05.000Z","updated_at":"2025-03-11T11:08:53.000Z","dependencies_parsed_at":"2025-01-10T10:43:20.347Z","dependency_job_id":"f0f46a1e-f01a-4d46-9c85-a3e6b10e60b6","html_url":"https://github.com/pythonhealthdatascience/rap_template_r_des","commit_stats":null,"previous_names":["pythonhealthdatascience/rap_template_r_des"],"tags_count":2,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonhealthdatascience%2Frap_template_r_des","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonhealthdatascience%2Frap_template_r_des/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonhealthdatascience%2Frap_template_r_des/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonhealthdatascience%2Frap_template_r_des/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pythonhealthdatascience","download_url":"https://codeload.github.com/pythonhealthdatascience/rap_template_r_des/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243188204,"owners_count":20250452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discrete-event-simulation","healthcare","healthcare-analysis","r","reproducible-analysis","reproducible-analytical-pipeline","reproducible-analytical-pipelines","reproducible-research","reproducible-science","simmer","simulation","simulation-framework","simulation-model","simulation-modeling","simulation-modelling","template"],"created_at":"2025-01-18T21:31:58.119Z","updated_at":"2025-03-12T08:43:48.441Z","avatar_url":"https://github.com/pythonhealthdatascience.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# R DES RAP Template\n\n\u003c!-- badges: start --\u003e\n![R 4.4.1](https://img.shields.io/badge/-R_4.4.1-276DC2?logo=r\u0026logoColor=white) \u003c!--TODO Specify R version --\u003e\n![MIT Licence](https://img.shields.io/badge/Licence-MIT-green.svg?labelColor=gray)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14980863.svg)](https://doi.org/10.5281/zenodo.14980863)\n[![R-CMD-check](https://github.com/pythonhealthdatascience/rap_template_r_des/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pythonhealthdatascience/rap_template_r_des/actions/workflows/R-CMD-check.yaml)\n[![Lint](https://github.com/pythonhealthdatascience/rap_template_r_des/actions/workflows/lint.yaml/badge.svg)](https://github.com/pythonhealthdatascience/rap_template_r_des/actions/workflows/lint.yaml)\n[![ORCID: Heather](https://img.shields.io/badge/ORCID_Amy_Heather-0000--0002--6596--3479-brightgreen)](https://orcid.org/0000-0002-6596-3479)\n\u003c!-- badges: end --\u003e\n\nA template for creating **discrete-event simulation (DES)** models in R within a **reproducible analytical pipeline (RAP)**.\u003cbr\u003e\u003cbr\u003e\nClick on \u003ckbd\u003eUse this template\u003c/kbd\u003e to initialise new repository.\u003cbr\u003e\nA `README` template is provided at the **end of this file**.\n\n\u003c/div\u003e\n\n\u003cbr\u003e\n\nTable of contents:\n\n* [📌 Introduction](#-introduction)\n* [🧐 What are we modelling?](#-what-are-we-modelling)\n* [🛠️ Using this template](#️-using-this-template)\n* [❓ How does the model work?](#-how-does-the-model-work)\n* [📂 Repository structure](#-repository-structure)\n* [⏰ Run time and machine specification](#-run-time-and-machine-specification)\n* [📝 Citation](#-citation)\n* [📜 Licence](#-licence)\n* [💰 Funding](#-funding)\n* [📄 Template README for your project](#-template-readme-for-your-project)\n\n\u003cbr\u003e\n\n## 📌 Introduction\n\nThis repository provides a template for building discrete-event simulation (DES) models in R.\n\n😊 **Simple:** Easy-to-follow code structure using [simmer](https://r-simmer.org/). Implements a simple M/M/s queueing model in which patients arrive, wait to see a nurse, have a consultation with the nurse and then leave.\n\n♻️ **Reproducible:** This template is designed to function as a RAP. It adheres to reproducibility recommendations from:\n\n* [\"Levels of RAP\" framework](https://nhsdigital.github.io/rap-community-of-practice/introduction_to_RAP/levels_of_RAP/) from the NHS RAP Community of Practice (as documented in `nhs_rap.md`).\n* Recommendations from [Heather et al. 2025](TODO:ADDLINK) \"*On the reproducibility of discrete-event simulation studies in health research: a computational investigation using open models*\" (as documented in `heather_2025.md`).\n\n✨ **Design practices:** Functions are documented with `roxygen2` docstrings and `lintr` is used to lint `.R` and `.Rmd` files.\n\n🧱 **Package structure:** The simulation code (`R/`) is structured as a little local R package. It is installed in our environment using `devtools::install()` and then `library(simulation)`. This means it can easily be used anywhere else in the directory - here, in `rmarkdown/` and `tests/` - without needing any additional code (e.g. no need to run `source()` with paths to the files).\n\n\u003cdetails markdown=\"1\"\u003e\n\u003csummary\u003e\u003cb\u003eMore information about the package structure\u003c/b\u003e\u003c/summary\u003e\n\n\u003cbr\u003e\n\n**Rationale:** As explained above, the package structure is helpful for sourcing the simulation code anywhere in the folder. Other benefits of this structure include:\n\n* Encourages well-organised repository following **standardised** established R package structure, which ensures that the model and analysis code are kept seperate.\n* Useful \"built-in\" features like **tests**, documentation of functions using **Roxygen**, documentation of data, and **package checks** (e.g. checking all imports are declared).\n* If your analysis has a short run time, the `.Rmd` files could be stored in a `vignettes/` folder which will mean they **re-run with every package build/check**, and so any new run issues will be identified. However, in this project, the analysis was instead stored in `rmarkdown/` as the file paths to save outputs cause errors in `vignettes/` (as they will differ between your runs of the notebook, and runs during the package build process).\n* Meet packaging **requirement** on the NHS \"Levels of RAP\" framework.\n\nFor more information on the rationale behind structuring research as an R package, check out:\n\n* [\"Open, Reproducible, and Distributable Research With R Packages\"](https://dante-sttr.gitlab.io/r-open-science/) from the DANTE Project - for example, this page on [vignettes](https://dante-sttr.gitlab.io/r-open-science/reports-manuscripts.html).\n* [\"Sharing and organizing research products as R packages\"](https://doi.org/10.3758/s13428-020-01436-x) from Vuorre and Crump 2020\n\n**Commands:** Helpful commands when working with the package include:\n\n* `devtools::document()` to reproduce documentation in `man/` after changes to the docstrings.\n* `devtools::check()` to build and check the package follows best practices.\n* `devtools::install()` to load the latest version of the package into your environment.\n* `devtools::test()` to run the tests in `tests/`.\n\n\u003c/details\u003e\n\n## 🧐 What are we modelling?\n\nA **simulation** is a computer model that mimics a real-world system. It allows us to test different scenarios and see how the system behaves. One of the most common simulation types in healthcare is **DES**.\n\nIn DES models, time progresses only when **specific events** happen (e.g., a patient arriving or finishing treatment). Unlike a continuous system where time flows smoothly, DES jumps forward in steps between events. For example, when people (or tasks) arrive, wait for service, get served, and then leave.\n\n![Simple DES Animation](images/simple_des.gif)\n*Simple model animation created using web app developed by Sammi Rosser (2024) available at https://github.com/hsma-programme/Teaching_DES_Concepts_Streamlit and shared under an MIT Licence.*\n\nOne simple example of a DES model is the **M/M/s queueing model**, which is implemented in this template. In a DES model, we use well-known **statistical distributions** to describe the behaviour of real-world processes. In an M/M/s model we use:\n\n* **Poisson distribution** to model patient arrivals - and so, equivalently, use an **exponential distribution** to model the inter-arrival times (time from one arrival to the next)\n* **Exponential distribution** to model server times.\n\nThese can be referred to as Markovian assumptions (hence \"M/M\"), and \"s\" refers to the number of parallel servers available.\n\nFor this M/M/s model, you only need three inputs:\n\n1. **Average arrival rate**: How often people typically arrive (e.g. patient arriving to clinic).\n2. **Average service duration**: How long it takes to serve one person (e.g. doctor consultation time).\n3. **Number of servers**: How many service points are available (e.g. number of doctors).\n\nThis model could be applied to a range of contexts, including:\n\n| Queue | Server/Resource |\n| - | - |\n| Patients in a waiting room | Doctor's consultation\n| Patients waiting for an ICU bed | Available ICU beds |\n| Prescriptions waiting to be processed | Pharmacists preparing and dispensing medications |\n\nFor further information on M/M/s models, see:\n\n* Ganesh, A. (2012). Simple queueing models. University of Bristol. https://people.maths.bris.ac.uk/~maajg/teaching/iqn/queues.pdf.\n* Green, L. (2011). Queueing theory and modeling. In *Handbook of Healthcare Delivery Systems*. Taylor \u0026 Francis. https://business.columbia.edu/faculty/research/queueing-theory-and-modeling.\n\n\u003cbr\u003e\n\n## 🛠️ Using this template\n\n### Step 1: Create a new repository\n\n1. Click on \u003ckbd\u003eUse this template\u003c/kbd\u003e.\n2. Provide a name and description for your new project repository.\n3. Clone the repository locally: \n\n```\ngit clone https://github.com/username/repo\ncd repo\n```\n\n### Step 2: Set-up the development environment\n\n\u003c!-- TODO: Test and consider options here, as not happy with this. Given I struggled with backdating R and packages, I think it would be appropriate here to divide this into two things:\n(a) The exact environment we used (which we would encourage for RAP)\n(b) Considerations re-running later, if not possible to rebuild that exact environment (e.g. which R, which packages, are compatible, maintenance, DESCRIPTION, etc). --\u003e\n\nLoad the R environment described in the `renv.lock` file (though note this won't fetch the version of R used - you would need to switch to that manually first):\n\n```\nrenv::init()\nrenv::restore()\n```\n\nIf facing issues with restoring this environment, an alternative is to set up a fresh environment based on the `DESCRIPTION`, but note that this may then install more recent package versions.\n\n```\nrenv::init()\nrenv::install()\nrenv::snapshot()\n```\n\nThere may also be system dependencies. The exact requirements will depend on your operating system, whether you have used R before, and what packages you have used. For example, when developing the template, we had to install the following for `igraph` (as explained [in their documentation](https://r.igraph.org/articles/installation-troubleshooting.html)):\n\n```\nsudo apt install build-essential gfortran\nsudo apt install libglpk-dev libxml2-dev\n```\n\n### Step 3: Explore and modify\n\n🔎 Choose your desired licence (e.g. \u003chttps://choosealicense.com/\u003e). If keeping an MIT licence, just modify the copyright holder in `LICENSE` and `LICENSE.md`.\n\n🔎 Review the example DES implementation in `R/` and `rmarkdown/`. Modify and extend the code as needed for your specific use case.\n\n🔎 Check you still fulfil the criteria in `docs/nhs_rap.md` and `docs/heather_2025.md`.\n\n🔎 Adapt the template `README` provided at the end of this file.\n\n🔎 Create your own `CITATION.cff` file using [cff-init](https://citation-file-format.github.io/cff-initializer-javascript/#/).\n\n🔎 Update `DESCRIPTION` and entries in the current `NEWS.md` with your own details, versions, and create GitHub releases.\n\n🔎 Archive your repository (e.g. [Zenodo](https://zenodo.org/)).\n\n🔎 Complete the Strengthening The Reporting of Empirical Simulation Studies (STRESS) checklist (`stress_des.md`) and use this to support writing publication/report, and attach as an appendice to report.\n\n📔 **RMarkdown**\n\nSeveral Rmarkdown files are provided which give examples running the models, choosing parameters, and explaining how things work. If you wish to knit all rmarkdown files from the command line, you can use the provided bash script by running:\n\n```\nbash run_rmarkdown.sh\n```\n\n🔎 **Tests**\n\nTo run tests:\n\n```\ndevtools::test()\n```\n\nThe repository contains a GitHub action `R-CMD-check.yaml` which will automatically run tests with new commits to GitHub, as part of the `devtools::check()` operation. This is continuous integration, helping to catch bugs early and keep the code stable. It will run the tests on three operating systems: Ubuntu, Windows and Mac.\n\n🔎 **Linting**\n\nYou can lint the `.R` and `.Rmd` files by running:\n\n```\nlintr::lint_package()\nlintr::lint_dir(\"rmarkdown\")\n```\n\nThe `lint_package()` function will run on files typically included in a package (i.e. `R/`, `tests/`). This will not include `rmarkdown/` as it is not typical/excluded from our package build, and so we can lint that by specifying the directory for `lint_dir()`.\n\n\u003cbr\u003e\n\n## ❓ How does the model work?\n\nTBC \u003c!-- TODO: Write this section --\u003e\n\n\u003cbr\u003e\n\n## 📂 Repository structure\n\n```\nrepo/\n├── .github/workflows/          # GitHub actions\n├── docs/                       # Documentation\n├── images/                     # Image files and GIFs\n├── man/                        # Function documentation generated by roxygen\n├── outputs/                    # Folder to save any outputs from model\n├── R/                          # Local package containing code for the DES model\n├── renv/                       # Instructions for creation of R environment\n├── rmarkdown/                  # .Rmd files to run DES model and analyse results\n├── tests/                      # Unit and back testing of the DES model\n├── .gitignore                  # Untracked files\n├── .lintr                      # Lintr settings\n├── .Rbuildignore               # Files and directories to exclude when building the package\n├── .Rprofile                   # R session configuration file\n├── CITATION.cff                # How to cite the repository\n├── CONTRIBUTING.md             # Contribution instructions\n├── DESCRIPTION                 # Metadata for the R package, including dependencies\n├── LICENSE                     # Licence file for the R package\n├── LICENSE.md                  # MIT licence for the repository\n├── NAMESPACE                   # Defines the exported functions and objects for the R package\n├── NEWS.md                     # Describes changes between releases (equivalent to a changelog for R packages)\n├── rap_template_r_des.Rproject # Project settings\n├── README.md                   # This file! Describes the repository\n└── renv.lock                   # Lists R version and all packages in the R environment\n```\n\n\u003cbr\u003e\n\n## ⏰ Run time and machine specification\n\nThe overall run time will vary depending on how the template model is used. A few example implementations are provided in `rmarkdown/` and the run times for these were:\n\n* `analysis.Rmd`: 1m 56s\n* `choosing_cores.Rmd`: 2m 13s\n* `choosing_replications.Rmd`: 13s\n* `generate_exp_results.Rmd`: 1s\n* `logs.Rmd`: 0s\n\n\u003c!--TODO: Check these are up to date --\u003e\n\nThese times were obtained on an Intel Core i7-12700H with 32GB RAM running Ubuntu 24.04.1 Linux.\n\n\u003cbr\u003e\n\n## 📝 Citation\n\nIf you use this template, please cite the archived repository:\n\n\u003e Heather, A. (2025). R DES Rap Template. Zenodo. https://doi.org/10.5281/zenodo.14980863.\n\nYou can also cite the GitHub repository:\n\n\u003e Heather, A. (2025). R DES Rap Template. GitHub. https://github.com/pythonhealthdatascience/rap_template_r_des.\n\nResearcher details:\n\n| Contributor | ORCID | GitHub |\n| --- | --- | --- |\n| Amy Heather | [![ORCID: Heather](https://img.shields.io/badge/ORCID-0000--0002--6596--3479-brightgreen)](https://orcid.org/0000-0002-6596-3479) | https://github.com/amyheather |\n\n\u003cbr\u003e\n\n## 📜 Licence\n\nThis template is licensed under the MIT License.\n\n```\nMIT License\n\nCopyright (c) 2025 STARS Project Team\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n\u003cbr\u003e\n\n## 💰 Funding\n\nThis project was developed as part of the project STARS: Sharing Tools and Artefacts for Reproducible Simulations. It is supported by the Medical Research Council [grant number [MR/Z503915/1](https://gtr.ukri.org/projects?ref=MR%2FZ503915%2F1)].\n\n\u003cbr\u003e\n\n## 📄 Template README for your project\n\nDelete everything from this line and above, and use the following structure as the starting point for your project README:\n___\n\n\u003cbr\u003e\n\u003cbr\u003e\n\u003cbr\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n# Your Project Name\n\n![python](https://img.shields.io/badge/-Python_Version-blue?logo=python\u0026logoColor=white)\n![licence](https://img.shields.io/badge/Licence-Name-green.svg?labelColor=gray)\n\n\u003c/div\u003e\n\n## Description\n\nProvide a concise description of your project.\n\n\u003cbr\u003e\n\n## Installation\n\nProvide instructions for installing dependencies and setting up the environment.\n\n\u003cbr\u003e\n\n## How to run\n\nProvide step-by-step instructions and examples.\n\nClearly indicate which files will create each figure in the paper. Hypothetical example:\n\n* To generate **Figures 1 and 2**, execute `base_case.Rmd`\n* To generate **Table 1** and **Figures 3 to 5**, execute `scenario_analysis.Rmd`\n\n\u003cbr\u003e\n\n## Run time and machine specification\n\nState the run time, and give the specification of the machine used (which achieved that run time).\n\n**Example:** Intel Core i7-12700H with 32GB RAM running Ubuntu 24.04.1 Linux. \n\nTo find this information:\n\n* **Linux:** Run `neofetch` on the terminal and record your CPU, memory and operating system.\n* **Windows:** Open \"Task Manager\" (Ctrl + Shift + Esc), go to the \"Performance\" tab, then select \"CPU\" and \"Memory\" for relevant information.\n* **Mac:** Click the \"Apple Menu\", select \"About This Mac\", then window will display the details.\n\n\u003cbr\u003e\n\n## Citation\n\nExplain how to cite your project and include correct attribution for this template.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythonhealthdatascience%2Frap_template_r_des","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpythonhealthdatascience%2Frap_template_r_des","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythonhealthdatascience%2Frap_template_r_des/lists"}