Skip to contents

Introduction

The following examples illustrate how to integrate new custom randomization methods and control how subjects are assigned to designated arms into East Horizon or East using R functions in the context of a two-arm trial.

Once CyneRgy is installed, you can load this example in RStudio with the following commands:

CyneRgy::RunExample( "RandomizeSubjects" )

Running the command above will load the RStudio project in RStudio.

RStudio Project File: RandomizeSubjects.Rproj

In the R directory of this example you will find the following R files:

  1. RandomizationSubjectsUsingUniformDistribution.R - Contains a function named RandomizationSubjectsUsingUniformDistribution to demonstrate the R code necessary for Example 1 as described below.

  2. RandomizationSubjectsUsingSampleFunctionInR.R - Contains a function named RandomizationSubjectsUsingSampleFunctionInR to demonstrate the R code necessary for Example 2 as described below.

  3. BlockRandomizationSubjectsUsingRPackage.R - Contains a function named BlockRandomizationSubjectsUsingRPackage to demonstrate the R code necessary for Example 3 as described below.

  4. LoadrandomizeR.R - This file is used to install the randomizeR package for execution of Block Randomization in R.

Example 1 - Randomize Subjects Usings Uniform Distribution

The R function RandomizationSubjectsUsingUniformDistribution randomly assigns subjects to one of two arms using a uniform distribution.

This function does not use any user-defined parameters, but uses parameters specified in East Horizon. Refer to the table below for more information.

Name of the parameter in East Horizon Where to find the parameter in East Horizon Name of the variable in the R script
Allocation Ratio Design Card AllocRatioAllocRatio

Steps:

  1. Generate a random number uu from a Uniform(0,1)Uniform(0,1) distribution.
  2. Define pp as the allocation fraction for the control arm, with 1p1 - p as the allocation fraction for the treatment arm.
  3. If upu \leq p, assign the subject to the control arm; otherwise, assign them to the treatment arm.
  4. Ensure that the total sample size equals the sum of subjects in the control and treatment arms.

The figure below illustrates where this example fits within the R integration points of Cytel products, accompanied by a flowchart outlining the general steps performed by the R code.

Example 2 - Randomize Subjects Using Sample Function

The R function RandomizationSubjectsUsingSampleFunctionInR uses the sample() function in R to randomly assign patients to the control and treatment arms.

This function does not use any user-defined parameters, but uses parameters specified in East Horizon. Refer to the table below for more information.

Name of the parameter in East Horizon Where to find the parameter in East Horizon Name of the variable in the R script
Allocation Ratio Design Card AllocRatioAllocRatio

Steps:

  1. Let pp be the allocation fraction for the control arm, with 1p1 - p as the allocation fraction for the treatment arm.
  2. Compute the expected sample sizes (rounded) for both arms using the allocation fraction and total sample size.
  3. Randomly assign subject indices to the control and treatment arms using the sample() function in R.
  4. Create a vector of zeros with size equal to the total number of subjects (NumSubNumSub), then replace the zeros with ones for indices corresponding to the treatment arm.

The figure below illustrates where this example fits within the R integration points of Cytel products, accompanied by a flowchart outlining the general steps performed by the R code.

Example 3 - Randomize Subjects Using randomizeR Package

The function BlockRandomizationSubjectsUsingRPackage.R uses the randomizeR::pbrPar() function from the randomizeR package to perform block randomization.

In small-sample studies, imbalances between groups can be minimized by using restricted randomization. This approach ensures that treatment groups are allocated in the desired proportions while maintaining randomness.

The permuted block randomization technique divides study participants into blocks, within which subjects are randomly assigned to treatment groups. This method ensures that the desired allocation proportions are exactly maintained within each block while keeping the order of assignments random.

Refer to the table below for the definitions of the user-defined parameters used in this example.

User parameter Definition
BlockSize1 Size of the first block for the randomization process.
BlockSize2 Size of the second block for the randomization process.
Block sizes for additional blocks follow the same format, incrementing the block number (e.g., BlockSize3, BlockSize4, etc.).

This function also uses parameters specified in East Horizon. Refer to the tables below for more information.

Name of the parameter in East Horizon Where to find the parameter in East Horizon Name of the variable in the R script
Allocation Ratio Design Card AllocRatioAllocRatio

The figure below illustrates where this example fits within the R integration points of Cytel products, accompanied by a flowchart outlining the general steps performed by the R code.