rdesrap_mms

Reproducible analytical pipeline (RAP) for R discrete-event simulation (DES) implementing an M/M/s queueing model.

https://github.com/pythonhealthdatascience/rdesrap_mms

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 5 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    1 of 1 committers (100.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.0%) to scientific vocabulary

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
Last synced: 4 months ago · JSON representation ·

Repository

Reproducible analytical pipeline (RAP) for R discrete-event simulation (DES) implementing an M/M/s queueing model.

Basic Info
  • Host: GitHub
  • Owner: pythonhealthdatascience
  • License: other
  • Language: R
  • Default Branch: main
  • Homepage:
  • Size: 75 MB
Statistics
  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • Open Issues: 7
  • Releases: 4
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
Created about 1 year ago · Last pushed 5 months ago
Metadata Files
Readme Changelog Contributing License Citation

README.md

# Simple M/M/s queuing model: R DES RAP ![R 4.4.1](https://img.shields.io/badge/-R_4.4.1-276DC2?&logo=r&logoColor=white) ![MIT Licence](https://img.shields.io/badge/Licence-MIT-green.svg?&labelColor=gray) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14980863.svg)](https://doi.org/10.5281/zenodo.14980863) [![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) [![Lint](https://github.com/pythonhealthdatascience/rdesrap_mms/actions/workflows/lint.yaml/badge.svg)](https://github.com/pythonhealthdatascience/rdesrap_mms/actions/workflows/lint.yaml) [![ORCID](https://img.shields.io/badge/ORCID_Amy_Heather-0000--0002--6596--3479-A6CE39?&logo=orcid&logoColor=white)](https://orcid.org/0000-0002-6596-3479) [![Codecov test coverage](https://codecov.io/gh/pythonhealthdatascience/rdesrap_mms/graph/badge.svg)](https://app.codecov.io/gh/pythonhealthdatascience/rdesrap_mms)


Repository overview

This 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.

An M/M/s queueing model is a classic mathematical model for systems where:

  • 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).
  • Service times are exponential (second "M").
  • There are s parallel servers (e.g. nurses) sharing a single queue.

This 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.


Installation

Clone the repository:

{.r} git clone https://github.com/pythonhealthdatascience/rdesrap_mms.git cd rdesrap_mms

Set up the R environment using renv (recommended):

{.r} renv::init() renv::restore()

If you encounter issues restoring the exact environment, you can install dependencies from DESCRIPTION and generate your own lock file:

{.r} renv::init() renv::install() renv::snapshot()

System dependencies

Some packages (e.g. igraph) may require system libraries. For example, for Ubuntu:

{.bash} sudo apt install build-essential gfortran sudo apt install libglpk-dev libxml2-dev


How to run

The simulation code is in the R/ folder as a local package. Example analyses and model runs are in rmarkdown/.

Install the local package:

{.r} devtools::install() library(simulation)

Run a single simulation:

{.r} params <- parameters(patient_inter = 2L, mean_n_consult_time = 4L, number_of_nurses = 2L) result <- model(run_number = 1L, param = params)

Run multiple replications:

{.r} params <- parameters(patient_inter = 2L, mean_n_consult_time = 4L, number_of_nurses = 2L, number_of_runs = 10L) results <- runner(param = params)

Run all example analyses (from command line):

{.bash} bash run_rmarkdown.sh


How does the model work

The model is built around three main functions, designed for flexibility and easy scenario analysis.

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:

{.r} params <- parameters(patient_inter = 10L)

Any 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.

2. model(). This function runs a single simulation using the parameters you provide. Example:

{.r} result <- model(params)

3. runner(). For robust results, youll usually want to run the simulation multiple times (replications). Example:

{.r} results <- runner(params)

You can set the number of replications in your parameters:

{.r} params <- parameters(number_of_runs = 20)

To 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:

Model structure diagram


Reproducing results

To generate the figures and tables from the paper (mock_paper.md), execute:

  • Figure 1-4: rmarkdown/analysis.Rmd
  • Figure A.1-A.2: rmarkdown/input_modelling.Rmd
  • Figure B.1: rmarkdown/choosing_warmup.Rmd
  • Figure C.1-C.3: rmarkdown/choosing_replications.Rmd


Input data

Patient-level data for our system is provided in the file: inputs/NHS_synthetic.csv.

Data dictionary (explaining each field) is available in: inputs/NHS_synthetic_dictionary.csv.

This dataset is synthetic and was generated in the pydesrap_mms repository based on the the structure of some fields from the Emergency Care Data Set (ECDS). The data generation process involved:

  • Arrivals: Sampled from a Poisson distribution (average 15 patients per hour).
  • Wait times: Sampled from an exponential distribution (average wait time: 5 minutes).
  • Service times: Sampled from an exponential distribution (average service time: 10 minutes).
  • Time period: Data covers one full year (1st January - 31st December 2025).

This dataset is released under the MIT licence. If you use this data, please cite the original repository: pydesrap_mms.

The 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.


GitHub actions

GitHub actions in .github/workflows/ automate testing and code checks.

  • 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.
  • lint.yaml checks code style in R scripts and RMarkdown files to maintain code quality.


Repository structure

repo/ .github/workflows/ # GitHub actions docs/ # Documentation images/ # Image files and GIFs inputs/ # Model inputs inst/ # Files to include in installed package (e.g. CITATION) man/ # Function documentation generated by roxygen outputs/ # Folder to save any outputs from model R/ # Local package containing code for the DES model renv/ # Instructions for creation of R environment rmarkdown/ # .Rmd files to run DES model and analyse results tests/ # Unit and back testing of the DES model .gitignore # Untracked files .lintr # Lintr settings .Rbuildignore # Files and directories to exclude when building the package .Rprofile # R session configuration file CITATION.cff # How to cite the repository CONTRIBUTING.md # Contribution instructions DESCRIPTION # Metadata for the R package, including dependencies LICENSE # Licence file for the R package LICENSE.md # MIT licence for the repository mock_paper.md # Mock paper using some of the figures NAMESPACE # Defines the exported functions and objects for the R package NEWS.md # Describes changes between releases (equivalent to a changelog for R packages) rdesrap_mms.Rproject # Project settings README.md # This file! Describes the repository renv.lock # Lists R version and all packages in the R environment run_rmarkdown.sh # Bash script to run knit all .Rmd from the command line


Run time and machine specification

Run times from our analyses (on Intel Core i7-12700H, 32GB RAM, Ubuntu 24.04.1):

  • analysis.Rmd: 5m 21s
  • choosing_cores.Rmd: 0m 51s
  • choosing_replications.Rmd: 2m 2s
  • choosing_warmup.Rmd: 16s
  • generate_exp_results.Rmd: 13s
  • input_modelling.Rmd: 8s

There are also two notebooks illustrating logging functionality (logs.Rmd) and about the impact of using set_attributes() and get_attributes (using_set_attributes.Rmd).


Community

Curious about contributing? Check out the contributing guidelines to learn how you can help. Every bit of help counts, and your contribution - no matter how minor - is highly valued.


Citation

If you use this repository, please cite either the GitHub repository or Zenodo:

Heather, A. (2025). Simple M/M/s queuing model: R DES RAP. GitHub. https://github.com/pythonhealthdatascience/rdesrap_mms.

Heather, A. (2025). Simple M/M/s queuing model: R DES RAP. Zenodo. https://doi.org/10.5281/zenodo.14980863.

Contributors:

Amy Heather - developed the repository.

  • ORCID
  • GitHub

Tom Monks - peer review of the repository.

  • ORCID
  • GitHub


Licence

MIT Licence. See LICENSE.md for details.


Acknowledgements

This repository was developed with thanks to a few others sources. These are acknowledged throughout in the relevant scipts, and also summarised here:

| Source | Find out more about how it was used... | | - | - | | 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 | | Tom Monks (2021) sim-tools: fundamental tools to support the simulation process in python (https://github.com/TomMonks/sim-tools) (MIT Licence).
Who themselves cite Hoad, Robinson, & 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 |


Funding

This 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].

Owner

  • Name: pythonhealthdatascience
  • Login: pythonhealthdatascience
  • Kind: organization

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: >-
  Simple M/M/s queuing model: R DES RAP
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Amy
    family-names: Heather
    email: a.heather2@exeter.ac.uk
    affiliation: University of Exeter
    orcid: 'https://orcid.org/0000-0002-6596-3479'
repository-code: >-
  https://github.com/pythonhealthdatascience/rdesrap_mms
abstract: >-
  Reproducible analytical pipeline (RAP) for R discrete-event simulation (DES)
  implementing a simple M/M/s queueing model.
version: 0.4.0
date-released: '2025-06-04'

GitHub Events

Total
  • Issues event: 25
  • Delete event: 1
  • Issue comment event: 15
  • Push event: 11
  • Pull request event: 2
  • Create event: 3
Last Year
  • Issues event: 25
  • Delete event: 1
  • Issue comment event: 15
  • Push event: 11
  • Pull request event: 2
  • Create event: 3

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 205
  • Total Committers: 1
  • Avg Commits per committer: 205.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 205
  • Committers: 1
  • Avg Commits per committer: 205.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
amyheather a****2@e****k 205
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 5 months ago