Learn R Programming

TrialSimulator

⚕ No for loop in clinical trial simulation ⚕

TrialSimulator is a system for declaratively implementing clinical trial simulations, inspired by the modular grammar of trial design. You provide the components—arms, endpoint-generation rules, milestones, and analysis methods—specify how they are combined under fixed or adaptive designs, and TrialSimulator takes care of the details, allowing you to focus on the design while it handles the mechanics.

TrialSimulator provides a suite of helper functions to support the full trial life cycle.

  • For data generation, it offers utilities to sample endpoints from common distributions.
  • For adaptation, it includes execution functions that modify trial settings in place.
  • For analysis, it implements methods such as regression models, group sequential tests, graphical multiple testing procedures, combination tests, and closed tests. These tools are entirely optional, but they make it simple to construct and evaluate complex trial designs without sacrificing flexibility.

Shiny App

An online version of this app is hosted on shinyapps.io.

Validation

The validation documents for this R package are hosted here and are continuously updated.

Installation

Release

You can install the current release version from CRAN with:

install.packages("TrialSimulator")

Development

You can install the development version from GitHub with:

if (!require("remotes")) {
  install.packages("remotes")
}
remotes::install_github(
  "zhangh12/TrialSimulator", 
  build_manual = TRUE, 
  build_vignettes = TRUE, 
  force = TRUE
)

Getting Started

TrialSimulator is designed with a modular architecture, allowing users to systematically construct and simulate clinical trials in a structured and flexible manner. The simulation process is broken down into three key steps:

  1. Defining Endpoints: Specify the treatment endpoints that will be evaluated throughout the trial.
  2. Specifying Milestone: Establish the conditions under which specific milestones (e.g., interim analysis, futility assessment, or stopping rules) will be triggered.
  3. Defining Actions for Milestones: Determine the appropriate actions to be taken once a milestone is triggered, such as adjusting enrollment, terminating treatment arms, or conducting statistical analysis.

To efficiently utilize TrialSimulator for clinical trial simulations, we recommend reading the following vignettes in order:

Copy Link

Version

Install

install.packages('TrialSimulator')

Monthly Downloads

207

Version

1.10.1

License

MIT + file LICENSE

Maintainer

Han Zhang

Last Published

February 15th, 2026

Functions in TrialSimulator (1.10.1)

Milestones

Class of Milestones
Listeners

Class of Listener
GraphicalTesting

Class of GraphicalTesting
Arms

Class of Arm
GroupSequentialTest

Class of GroupSequentialTest
CorrelatedPfsAndOs3

Generate Correlated PFS and OS
DynamicRNGFunction

A wrapper of random number generator.
Controllers

Class of Controller
Endpoints

Class of Endpoint
CorrelatedPfsAndOs4

Generate Correlated PFS, OS and Objective Response
add_arms

Adding One or More Arms to a Trial
StaggeredRecruiter

Generate Enrollment Time from Piecewise Constant Uniform Distribution
calendarTime

Triggering Condition by Calendar Time
endpoint

Define Endpoints
controller

Define a Controller
doNothing

An Action Function that Does Nothing
PiecewiseConstantExponentialRNG

Generate Time-to-Event Endpoint from Piecewise Constant Exponential Distribution
enrollment

Triggering Condition by Number of Randomized Patients
arm

Define an Arm
Trials

Class of Trial
milestone

Define a Milestone
fitFarringtonManning

Farrington-Manning test for rate difference
fitLogistic

Fit logistic regression model
fitCoxph

Fit Cox Proportional Hazard Ratio model
fitLinear

Fit linear regression model
getFixedDesignOutput

Get simulation output in the vignette fixedDesign.Rmd
getAdaptiveDesignOutput

Get simulation output in the vignette adaptiveDesign.Rmd
fitLogrank

Carry out log rank test
listener

Define a Listener
eventNumber

Triggering Condition by Number of Events or Non-missing Observations of an Endpoint
set_duration

Extending Duration of a Trial
resize

Resizing a Trial
plot.milestone_time_summary

Plot Triggering Time of Milestones in Simulated Trials
summarizeDataFrame

Summarize A Data Frame
rconst

Generate Constant Variable
solveThreeStateModel

Solve Parameters in a Three-State Ill-Death Model
solveMixtureExponentialDistribution

Solve Parameters in a Mixture Exponential Distribution
plot.three_state_model

Plot result of three-state ill-death model
summarizeMilestoneTime

Summary of Milestone Time from Simulated Trials
trial

Define a Trial
remove_arms

Removing One or More Arms From a Trial
update_generator

Updating Data Generators of One or More Endpoints in an Arm
update_sample_ratio

Updating Sampling Ratios of Existing Arms in a Trial
weibullDropout

Calculate Parameters of Weibull Distribution as a Dropout Method