simChef: High-quality data science simulations inR

James Duncan, Tiffany M. Tang, Corrine F. Elliott, Philippe Boileau, Bin YuThe Journal of Open Source Software 2024

Abstract

simChef is an R package that empowers data science practitioners to rapidly plan, carry out, and summarize statistical simulation studies in a flexible, efficient, and low-code manner. Drawing substantially from the Predictability, Computability, and Stability (PCS) framework, simChef emphasizes the scientific best practices encompassed by PCS by removing many of the administrative burdens of simulation design through: (1) an intuitive tidy grammar of data science simulations; (2) powerful abstractions for distributed simulation processing backed by future; and (3) automated generation of interactive R Markdown simulation documentation, situating results next to the workflows needed to reproduce them. Taken together, simChef's capabilities overcome many of the design, computational, and reproducibility hurdles inherent in nearly every data science simulation study.

Introduction

In data science, simulations serve as essential "statistical sandboxes," allowing researchers to stress-test new methods, benchmark existing algorithms, and explore theoretical boundaries where analytical solutions are unavailable. However, building high-quality simulations is notoriously tedious. Researchers often face significant "administrative overhead," including writing boilerplate code for data generation, managing complex parameter sweeps, and manually aggregating results into reports. This process is error-prone and frequently results in "one-off" codebases that are difficult to reuse or reproduce. simChef aims to standardize this scaffolding, ensuring that simulations are as rigorous as the research they support.

The simChef Framework

The core of simChef is built on the PCS framework (Predictability, Computability, and Stability), which emphasizes scientific best practices. It organizes a simulation into five modular R6 classes, providing a robust object-oriented foundation:

  1. DGP (Data-Generating Process): Functions that create synthetic data.
  2. Method: The models or algorithms being tested.
  3. Evaluator: Metrics (such as RMSE or accuracy) used to judge performance.
  4. Visualizer: Functions that transform results into plots or tables.
  5. Experiment: The central orchestrator that manages how DGPs and Methods interact across different parameters.
The simChef workflow: an integrated approach to fitting, evaluating, and visualizing experiments.

The package utilizes a "tidy" grammar—similar to the popular tidyverse—allowing users to pipe commands together (e.g., exper %>% add_method() %>% add_vary_across()). It handles complex experimental designs by automatically calculating the Cartesian product of all varied parameters. For computation, it integrates with the future package, making it trivial to scale from a single laptop to a high-performance computing cluster.

Key Features and Innovations

  • Documentation as a First-Class Citizen: One of the most innovative features is the render_docs() function. It generates an interactive R Markdown document that places source code, parameter settings, and visualizations side-by-side. This ensures the "how" and "why" of a simulation are never separated from the "what."
  • Smart Caching: Simulation runs are computationally expensive. simChef includes built-in caching; if a user adds a single new method to an existing experiment, the package is smart enough to only run the new combinations, appending them to previous results rather than re-computing everything from scratch.
  • Separation of Concerns: By forcing a strict separation between data generation, method fitting, and evaluation, simChef makes code highly reusable. A DGP created for one study can be easily dropped into an entirely different experiment.

Results and Scalability

The paper highlights the efficiency and scalability of the simChef workflow. The authors demonstrate that a complex experiment with 108 DGP-method-parameter combinations, each replicated 100 times (totaling 10,800 replicates), can be defined and executed in just a few dozen lines of intuitive code. By changing a single line (future::plan), the simulation can be distributed across dozens of workers, significantly reducing the "wall-clock" time for large-scale benchmarks. This automated documentation pipeline bridges the gap between raw simulation code and a shareable scientific report, addressing a major pain point in open science.

Conclusion and Future Directions

While simChef excels at the "Computability" aspect of the PCS framework, the authors acknowledge that more work is needed to automate the "Predictability" and "Stability" components. Future versions of the package aim to include built-in tools for automated stability summaries, helping users see how sensitive their results are to small changes in data or parameters. Additionally, the team plans to expand the visualizer library to provide more "out-of-the-box" diagnostic plots for common simulation types and improve integration with real-world "ground truth" datasets to validate synthetic DGPs.

Summary updated

BibTeX
@article{duncan2024simchef,
  author = {James Duncan and Tiffany M. Tang and Corrine F. Elliott and Philippe Boileau and Bin Yu},
  title = {{simChef: High-quality data science simulations inR}},
  journal = {The Journal of Open Source Software},
  year = {2024},
  doi = {10.21105/joss.06156},
}
Figure