Skip to contents

A DesignSeqOneByOne implementing permuted-block randomization with randomly varying block size: subjects are assigned from a queue of pre-shuffled treatment labels (a "block"), refilled with a fresh sampled block whenever it empties. Each new block's size is itself drawn uniformly at random from block_sizes (rather than being fixed), and each block internally contains exactly round(block_size * prob_T) treated and block_size - round(block_size * prob_T) control labels in random order. Randomizing the block size (rather than using a single fixed block length, as in classical permuted-block designs) is a standard clinical-trials safeguard against selection bias: with a fixed, known block size, unblinded staff could predict the last assignment(s) in a block from the ones already observed, whereas an unpredictable block size makes this much harder while still guaranteeing near-perfect treatment/control balance throughout enrollment (balance is exact at every block boundary and never worse than one full block's imbalance in between). If strata_cols is supplied, a separate independent sequence of blocks is maintained per stratum (one queue per distinct combination of strata_cols values), so balance holds within each stratum, not just overall.

Block-size / prob_T compatibility. Every entry of block_sizes must yield an integer number of treated subjects when multiplied by prob_T (checked at construction: abs(bs * prob_T - round(bs * prob_T)) <= 1e-10 for every bs); a block size that would require a fractional number of treated subjects is rejected.

Per-stratum queues. private$strata_states is a hashed environment mapping each stratum key (or the literal key "overall" when strata_cols is NULL) to the vector of not-yet-used assignments remaining in that stratum's current block; assign_wt() pops the next assignment from the relevant queue, refilling it with a freshly drawn block (random size, randomly ordered) whenever it is empty.

Bootstrap. draw_bootstrap_indices() resamples within strata (via stratified_bootstrap_indices_cpp()) when strata_cols is supplied, or performs a plain i.i.d. nonparametric bootstrap over subjects otherwise.

References

Efron, B. (1971). "Forcing a sequential experiment to be balanced." Biometrika, 58(3), 403-417, doi:10.1093/biomet/58.3.403 , for sequential balanced-block randomization background. See also block randomisation for orientation on permuted-block designs and the selection-bias rationale for varying block size.

Super classes

Design -> DesignSeqOneByOne -> DesignSeqOneByOneRandomBlockSize

Methods

+ inherited public methods from DesignSeqOneByOne
+ inherited public methods from Design


DesignSeqOneByOneRandomBlockSize$new()

Initialize a sequential permuted-block experimental design with randomly varying block size (see class documentation for the exact block-refill rule and its selection-bias rationale).

Usage

DesignSeqOneByOneRandomBlockSize$new(
  strata_cols = NULL,
  block_sizes = c(4, 6, 8),
  response_type,
  prob_T = 0.5,
  include_is_missing_as_a_new_feature = TRUE,
  n = NULL,
  verbose = FALSE,
  missingness_method = "impute",
  design_formula = ~.,
  seed = NULL
)

Arguments

strata_cols

A character vector of column names to use for stratification. If NULL, simple blocking is used.

block_sizes

A vector of positive integers representing the possible block sizes to choose from. Each must be a multiple of the inverse of prob_T to ensure integer treatment/control counts.

response_type

The data type of response values which must be one of the following: "continuous", "incidence", "proportion", "count", "survival", "ordinal".

prob_T

The probability of the treatment assignment. This defaults to 0.5.

include_is_missing_as_a_new_feature

If missing data is present in a variable, should we include another dummy variable for its missingness? Default is TRUE.

n

The sample size (if fixed). Default is NULL for not fixed.

verbose

A flag indicating whether messages should be displayed. Default is FALSE.

missingness_method

How to handle missing values in covariates.

design_formula

A formula object.

seed

Integer seed for reproducibility.

Returns

A new `DesignSeqOneByOneRandomBlockSize` object


DesignSeqOneByOneRandomBlockSize$assign_wt()

Pop the next treatment assignment from the current subject's stratum block queue (see class documentation), refilling that queue with a freshly drawn random-size, randomly-ordered block first if it is empty.

Usage

DesignSeqOneByOneRandomBlockSize$assign_wt()

Returns

The treatment assignment (0 or 1) for the next subject.


DesignSeqOneByOneRandomBlockSize$clone()

The objects of this class are cloneable with this method.

Usage

DesignSeqOneByOneRandomBlockSize$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

seq_des = DesignSeqOneByOneRandomBlockSize$new(n = 6, response_type = 'continuous')
seq_des$add_one_subject_to_experiment_and_assign(data.frame(x1 = rnorm(1)))
#> [1] 0