Skip to contents

The randomize_dynamic function implements the dynamic randomization algorithm using the minimization method proposed by Pocock (Pocock and Simon, 1975). It requires defining basic study parameters: the number of arms (K), number of covariates (C), patient allocation ratios (\(a_k\)) (where k = 1,2,…., K), weights for the covariates (\(w_i\)) (where i = 1,2,…., C), and the maximum probability (p) of assigning a patient to the group with the smallest total unbalance multiplied by the respective weights (\(G_k\)). As the total unbalance for the first patient is the same regardless of the assigned arm, this patient is randomly allocated to a given arm. Subsequent patients are randomized based on the calculation of the unbalance depending on the selected method: "range", "var" (variance), or "sd" (standard deviation). In the case of two arms, the "range" method is equivalent to the "sd" method.

Usage

randomize_minimisation_pocock(
  arms,
  current_state,
  weights,
  ratio,
  method = "var",
  p = 0.85
)

Arguments

arms

character()
Arm names.

current_state

tibble()
table of covariates and current arm assignments in column arm, last row contains the new patient with empty string for arm

weights

numeric()
vector of positive weights, equal in length to number of covariates, numbered after covariates, defaults to equal weights

ratio

integer()
Vector of positive integers (0 is allowed), equal in length to number of arms, named after arms, defaults to equal weight

method

character()
Function used to compute within-arm variability, must be one of: sd, var, range, defaults to var

p

numeric()
single value, proportion of randomness (0, 1) in the randomization vs determinism, defaults to 85% deterministic

Value

character()

name of the arm assigned to the patient

Details

Initially, the algorithm creates a matrix of results comparing a newly randomized patient with the current balance of patients based on the defined covariates. In the next step, for each arm and specified covariate, various scenarios of patient allocation are calculated. The existing results (n) are updated with the new patient, and then, considering the ratio coefficients, the results are divided by the specific allocation ratio. Depending on the method, the total unbalance is then calculated, taking into account the weights, and the number of covariates using one of three methods (“sd”, “range”, “var”). Based on the number of defined arms, the minimum value of (\(G_k\)) (defined as the weighted sum of the level-based imbalance) selects the arm to which the patient will be assigned with a predefined probability (p). The probability that a patient will be assigned to any other arm will then be equal (1-p)/(K-1) for each of the remaining arms.

Note

This function's implementation is a refactored adaptation of the codebase from the 'Minirand' package.

References

Pocock, S. J., & Simon, R. (1975). Minimization: A new method of assigning patients to treatment and control groups in clinical trials.

Minirand Package: Man Jin, Adam Polis, Jonathan Hartzel. (https://CRAN.R-project.org/package=Minirand)

Examples

n_at_the_moment <- 10
arms <- c("control", "active low", "active high")
sex <- sample(c("F", "M"),
  n_at_the_moment + 1,
  replace = TRUE,
  prob = c(0.4, 0.6)
)
diabetes <-
  sample(c("diabetes", "no diabetes"),
    n_at_the_moment + 1,
    replace = TRUE,
    prob = c(0.2, 0.8)
  )
arm <-
  sample(arms,
    n_at_the_moment,
    replace = TRUE,
    prob = c(0.4, 0.4, 0.2)
  ) |>
  c("")
covar_df <- tibble::tibble(sex, diabetes, arm)
covar_df
#> # A tibble: 11 × 3
#>    sex   diabetes    arm          
#>    <chr> <chr>       <chr>        
#>  1 M     no diabetes "control"    
#>  2 F     no diabetes "active low" 
#>  3 F     no diabetes "active high"
#>  4 M     no diabetes "control"    
#>  5 M     no diabetes "active low" 
#>  6 M     no diabetes "control"    
#>  7 M     no diabetes "control"    
#>  8 M     no diabetes "control"    
#>  9 F     diabetes    "active low" 
#> 10 F     no diabetes "active low" 
#> 11 F     no diabetes ""           

randomize_minimisation_pocock(arms = arms, current_state = covar_df)
#> [1] "active high"
randomize_minimisation_pocock(
  arms = arms, current_state = covar_df,
  ratio = c(
    "control" = 1,
    "active low" = 2,
    "active high" = 2
  ),
  weights = c(
    "sex" = 0.5,
    "diabetes" = 1
  )
)
#> [1] "active high"