
2-Arm - Randomization of Subjects
Shubham Lahoti
January 16, 2025
PatientRandomization.Rmd
Introduction
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:
RandomizationSubjectsUsingUniformDistribution.R - Contains a function named RandomizationSubjectsUsingUniformDistribution to demonstrate the R code necessary for Example 1 as described below.
RandomizationSubjectsUsingSampleFunctionInR.R - Contains a function named RandomizationSubjectsUsingSampleFunctionInR to demonstrate the R code necessary for Example 2 as described below.
BlockRandomizationSubjectsUsingRPackage.R - Contains a function named BlockRandomizationSubjectsUsingRPackage to demonstrate the R code necessary for Example 3 as described below.
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 named “RandomizationSubjectsUsingUniformDistribution” in the file randomly allots the subjects to either of two arms using Uniform Distribution.
Steps:
- We generate a random number from Uniform(0, 1). Save it as u.
- Let p = Allocation fraction on control arm and 1 - p = Allocation fraction on treatment arm.
- If u <= p then allot the subject to the control arm else allot the subject to treatment arm.
- Make sure that Total sample size = Sample size on control + Sample size on treatment arm.
Example 2 - Randomize Subjects Using Sample Function
The R function named “RandomizationSubjectsUsingSampleFunctionInR” in the file makes use of Sample() function in R to randomly allot the patients on control and treatment arm.
Steps:
- Let p = Allocation fraction on control arm and 1 - p = Allocation fraction on treatment arm.
- Compute Expected Sample size (rounded) for control and treatment arms using Allocation Fraction and Total sample size.
- Randomly allot the indices to the control and treatment arms using the sample() function available in R.
- Create a vector of zeroes of size = NumSub (Number of subjects) and then replace the zeroes by 1 for the Indices that correspond to treatment.
Example 3 - Randomize Subjects Using randomizeR Package
The function named “BlockRandomizationSubjectsUsingRPackage.R” in the file makes use of pbrPar() function from the “randomizeR” library to perform the Block randomization.
Description:
Imbalances between groups can be minimized in small sample–size studies by restricting the randomization procedure. Restricted randomization means applying randomization in a manner that helps ensure the desired proportions of treatment groups, beyond random chance, within defined groups of patients.
The permuted block technique randomizes patients into groups within a set of study participants, called a block. Treatment assignments within blocks are determined so that they are random in order but that the desired allocation proportions are achieved exactly within each block.