{"id":30117333,"url":"https://github.com/pythonhealthdatascience/rdesrap_mms","last_synced_at":"2025-08-10T10:41:36.299Z","repository":{"id":271853834,"uuid":"899059771","full_name":"pythonhealthdatascience/rdesrap_mms","owner":"pythonhealthdatascience","description":"Reproducible analytical pipeline (RAP) for R discrete-event simulation (DES) implementing an M/M/s queueing model.","archived":false,"fork":false,"pushed_at":"2025-07-30T10:59:14.000Z","size":74871,"stargazers_count":2,"open_issues_count":9,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-30T12:52:37.562Z","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,"zenodo":null}},"created_at":"2024-12-05T14:49:05.000Z","updated_at":"2025-06-16T12:36:50.000Z","dependencies_parsed_at":"2025-01-10T10:43:20.347Z","dependency_job_id":"f0f46a1e-f01a-4d46-9c85-a3e6b10e60b6","html_url":"https://github.com/pythonhealthdatascience/rdesrap_mms","commit_stats":null,"previous_names":["pythonhealthdatascience/rap_template_r_des","pythonhealthdatascience/rdesrap_mms"],"tags_count":4,"template":true,"template_full_name":null,"purl":"pkg:github/pythonhealthdatascience/rdesrap_mms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonhealthdatascience%2Frdesrap_mms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonhealthdatascience%2Frdesrap_mms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonhealthdatascience%2Frdesrap_mms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonhealthdatascience%2Frdesrap_mms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pythonhealthdatascience","download_url":"https://codeload.github.com/pythonhealthdatascience/rdesrap_mms/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythonhealthdatascience%2Frdesrap_mms/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269712875,"owners_count":24463216,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-08-10T10:41:35.395Z","updated_at":"2025-08-10T10:41:36.261Z","avatar_url":"https://github.com/pythonhealthdatascience.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# Simple M/M/s queuing model: R DES RAP\n\n\u003c!-- badges: start --\u003e\n![R 4.4.1](https://img.shields.io/badge/-R_4.4.1-276DC2?\u0026logo=r\u0026logoColor=white)\n![MIT Licence](https://img.shields.io/badge/Licence-MIT-green.svg?\u0026labelColor=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/rdesrap_mms/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/pythonhealthdatascience/rdesrap_mms/actions/workflows/R-CMD-check.yaml)\n[![Lint](https://github.com/pythonhealthdatascience/rdesrap_mms/actions/workflows/lint.yaml/badge.svg)](https://github.com/pythonhealthdatascience/rdesrap_mms/actions/workflows/lint.yaml)\n[![ORCID](https://img.shields.io/badge/ORCID_Amy_Heather-0000--0002--6596--3479-A6CE39?\u0026logo=orcid\u0026logoColor=white)](https://orcid.org/0000-0002-6596-3479)\n[![Codecov test coverage](https://codecov.io/gh/pythonhealthdatascience/rdesrap_mms/graph/badge.svg)](https://app.codecov.io/gh/pythonhealthdatascience/rdesrap_mms)\n\u003c!-- badges: end --\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n## Repository overview\n\nThis repository provides a reproducible analytical pipeline (RAP) for a simple **M/M/s queuing model** implemented in R using simmer. The model simulates patients arriving, waiting to see a nurse, being served, and leaving. All code is structured as a local R package.\n\nAn M/M/s queueing model is a classic mathematical model for systems where:\n\n* Arrivals happen at random, following a Poisson process - and the time between arrivals follows an exponential distribution (the first \"M\", which stands for \"Markovian\" as it is memoryless - arrivals are independent).\n* Service times are exponential (second \"M\").\n* There are s parallel servers (e.g. nurses) sharing a single queue.\n\nThis type of model is widely used for studying waiting lines in healthcare, call centers, and other service systems. It helps answer questions like: How long will people wait? How many servers are needed to keep waits short? The only required inputs are the average arrival rate, average service time, and the number of servers.\n\n\u003cbr\u003e\n\n## Installation\n\nClone the repository:\n\n```{.r}\ngit clone https://github.com/pythonhealthdatascience/rdesrap_mms.git\ncd rdesrap_mms\n```\n\nSet up the R environment using `renv` (recommended):\n\n```{.r}\nrenv::init()\nrenv::restore()\n```\n\nIf you encounter issues restoring the exact environment, you can install dependencies from `DESCRIPTION` and generate your own lock file:\n\n```{.r}\nrenv::init()\nrenv::install()\nrenv::snapshot()\n```\n\n### System dependencies\n\nSome packages (e.g. `igraph`) may require system libraries. For example, for Ubuntu:\n\n```{.bash}\nsudo apt install build-essential gfortran\nsudo apt install libglpk-dev libxml2-dev\n```\n\n\u003cbr\u003e\n\n## How to run\n\nThe simulation code is in the `R/` folder as a local package. Example analyses and model runs are in `rmarkdown/`.\n\n**Install the local package:**\n\n```{.r}\ndevtools::install()\nlibrary(simulation)\n```\n\n**Run a single simulation:**\n\n```{.r}\nparams \u003c- parameters(patient_inter = 2L, mean_n_consult_time = 4L, number_of_nurses = 2L)\nresult \u003c- model(run_number = 1L, param = params)\n```\n\n**Run multiple replications:**\n\n```{.r}\nparams \u003c- parameters(patient_inter = 2L, mean_n_consult_time = 4L, number_of_nurses = 2L, number_of_runs = 10L)\nresults \u003c- runner(param = params)\n```\n\n**Run all example analyses (from command line):**\n\n```{.bash}\nbash run_rmarkdown.sh\n```\n\n**Run tests:**\n\n```{.r}\ndevtools::test()\n```\n\n**Compute test coverage:**\n\n```{.r}\ndevtools::test_coverage()\n```\n\n**Lint code:**\n\n```{.r}\nlintr::lint_package()\nlintr::lint_dir(\"rmarkdown\")\n```\n\n\u003cbr\u003e\n\n## ❓ How does the model work\n\nThe model is built around three main functions, designed for flexibility and easy scenario analysis.\n\n**1. parameters()**. This function creates a list of all inputs needed for the simulation - such as arrival rate, service rate, and number of nurses. You can quickly change parameters for a scenario by calling, for example:\n\n```{.r}\nparams \u003c- parameters(patient_inter = 10L)\n```\n\nAny values you don't specify will use the defaults set in `R/parameters.R`. To permanently change a default, edit the values directly in the `parameters()` function inside `R/parameters.R`.\n\n**2. model()**. This function runs a single simulation using the parameters you provide. Example:\n\n```{.r}\nresult \u003c- model(params)\n```\n\n**3. runner()**. For robust results, you’ll usually want to run the simulation multiple times (replications). Example:\n\n```{.r}\nresults \u003c- runner(params)\n```\n\nYou can set the number of replications in your parameters:\n\n```{.r}\nparams \u003c- parameters(number_of_runs = 20)\n```\n\nTo summarise, we create or modify a parameter set with `parameters()`, run a single simulation with `model()`, or many with `runner()`, and analyse the results (e.g. in the provided RMarkdown files). This diagram provides an overview of the functions:\n\n![Model structure diagram](images/model_structure.png)\n\n\u003cbr\u003e\n\n## Reproducing results\n\nTo generate the figures and tables from the paper (`mock_paper.md`), execute:\n\n* **Figure 1-4**: `rmarkdown/analysis.Rmd`\n* **Figure A.1-A.2:** `rmarkdown/input_modelling.Rmd`\n* **Figure B.1:** `rmarkdown/choosing_warmup.Rmd`\n* **Figure C.1-C.3:** `rmarkdown/choosing_replications.Rmd`\n\n\u003cbr\u003e\n\n## Input data\n\n**Patient-level data** for our system is provided in the file: `inputs/NHS_synthetic.csv`.\n\n**Data dictionary** (explaining each field) is available in: `inputs/NHS_synthetic_dictionary.csv`.\n\nThis dataset is **synthetic** and was generated in the [pydesrap_mms](https://github.com/pythonhealthdatascience/pydesrap_mms) repository based on the the structure of some fields from the [Emergency Care Data Set (ECDS)](https://digital.nhs.uk/data-and-information/data-collections-and-data-sets/data-sets/emergency-care-data-set-ecds). The data generation process involved:\n\n* **Arrivals:** Sampled from a Poisson distribution (average 15 patients per hour).\n* **Wait times:** Sampled from an exponential distribution (average wait time: 5 minutes).\n* **Service times:** Sampled from an exponential distribution (average service time: 10 minutes).\n* **Time period:** Data covers one full year (1st January - 31st December 2025).\n\nThis dataset is released under the MIT licence. If you use this data, please cite the original repository: [pydesrap_mms](https://github.com/pythonhealthdatascience/pydesrap_mms).\n\nThe code for input modelling is in: `rmarkdown/input_modelling.Rmd`. Model parameters are determined in this file and then stored in: `R/parameters.R`. Description for each parameter can be found in the class docstring within this file.\n\n\u003cbr\u003e\n\n## GitHub actions\n\nGitHub actions in `.github/workflows/` automate testing and code checks.\n\n* **R-CMD-check.yaml** runs `devtools::check()` on Ubuntu, Windows, and Mac after each push to main, ensuring the package build and tests pass across platforms.\n* **lint.yaml** checks code style in R scripts and RMarkdown files to maintain code quality.\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├── inputs/                     # Model inputs\n├── inst/                       # Files to include in installed package (e.g. CITATION)\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├── mock_paper.md               # Mock paper using some of the figures\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├── rdesrap_mms.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└── run_rmarkdown.sh            # Bash script to run knit all .Rmd from the command line\n```\n\n\u003cbr\u003e\n\n## Run time and machine specification\n\nRun times from our analyses (on Intel Core i7-12700H, 32GB RAM, Ubuntu 24.04.1):\n\n* `analysis.Rmd`: 2m 12s\n* `choosing_cores.Rmd`: 2m 12s\n* `choosing_replications.Rmd`: 1m 35s\n* `choosing_warmup.Rmd`: 3s\n* `generate_exp_results.Rmd`: 2s\n* `input_modelling.Rmd`: 13s\n\nThere are also two notebooks illustrating logging functionality (`logs.Rmd`) and about the impact of using `set_attributes()` and `get_attributes` (`using_set_attributes.Rmd`).\n\n\u003cbr\u003e\n\n## Citation\n\nIf you use this repository, please cite either the GitHub repository or Zenodo:\n\n\u003e Heather, A. (2025). Simple M/M/s queuing model: R DES RAP. GitHub. https://github.com/pythonhealthdatascience/rdesrap_mms.\n\u003e\n\u003e Heather, A. (2025). Simple M/M/s queuing model: R DES RAP. Zenodo. https://doi.org/10.5281/zenodo.14980863.\n\n**Contributors:**\n\n**Amy Heather** - developed the repository.\n\n* [![ORCID](https://img.shields.io/badge/ORCID-0000--0002--6596--3479-A6CE39?style=for-the-badge\u0026logo=orcid\u0026logoColor=white)](https://orcid.org/0000-0002-6596-3479)\n* [![GitHub](https://img.shields.io/badge/GitHub-amyheather-181717?style=for-the-badge\u0026logo=github\u0026logoColor=white)](https://github.com/amyheather)\n\n**Tom Monks** - peer review of the repository.\n\n* [![ORCID](https://img.shields.io/badge/ORCID-0000--0003--2631--4481-A6CE39?style=for-the-badge\u0026logo=orcid\u0026logoColor=white)](https://orcid.org/0000-0003-2631-4481)\n* [![GitHub](https://img.shields.io/badge/GitHub-TomMonks-181717?style=for-the-badge\u0026logo=github\u0026logoColor=white)](https://github.com/TomMonks)\n\n\u003cbr\u003e\n\n## Licence\n\nMIT Licence. See `LICENSE.md` for details.\n\n\u003cbr\u003e\n\n## Acknowledgements\n\nThis repository was developed with thanks to a few others sources. These are acknowledged throughout in the relevant scipts, and also summarised here:\n\n| Source | Find out more about how it was used... |\n| - | - |\n| Ucar I, Smeets B (2023). simmer.plot: Plotting Methods for 'simmer'. https://r-simmer.org. https://github.com/r-simmer/simmer.plot. | `R/get_run_results.R` |\n| Tom Monks (2021) sim-tools: fundamental tools to support the simulation process in python (https://github.com/TomMonks/sim-tools) (MIT Licence).\u003cbr\u003e Who themselves cite Hoad, Robinson, \u0026 Davies (2010). Automated selection of the number of replications for a discrete-event simulation (https://www.jstor.org/stable/40926090), and Knuth. D \"The Art of Computer Programming\" Vol 2. 2nd ed. Page 216. | `R/choose_replications.R` |\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythonhealthdatascience%2Frdesrap_mms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpythonhealthdatascience%2Frdesrap_mms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythonhealthdatascience%2Frdesrap_mms/lists"}