
A Stratified Permuted-Block Sequential Design (SPBR) with Fixed Block Size
Source:R/design_seq_one_by_one_spbr.R
DesignSeqOneByOneSPBR.RdA DesignSeqOneByOne implementing classical
stratified permuted-block randomization: subjects are assigned from a per-stratum
queue of pre-shuffled treatment labels (a "block" of block_size labels,
containing exactly round(block_size * prob_T) treated and the remainder
control, in random order), refilled with a fresh randomly-ordered block of the
same fixed size whenever a stratum's queue empties. This is the
fixed-block-size, mandatory-stratification counterpart of
DesignSeqOneByOneRandomBlockSize
(which varies block size across draws and makes stratification optional): here,
strata_cols is required, and a single fixed block_size is used for
every stratum and every block, guaranteeing exact treatment/control balance within
each stratum at every block boundary.
Block-size / prob_T compatibility. block_size must yield an
integer number of treated subjects: the constructor errors unless
abs(block_size * prob_T - round(block_size * prob_T)) <= 1e-10.
Per-stratum queues. As in
DesignSeqOneByOneRandomBlockSize,
private$strata_states is a hashed environment mapping each stratum key
(concatenated strata_cols values, "NA" for missing) to the vector of
not-yet-used assignments remaining in that stratum's current block;
assign_wt() pops the next assignment, refilling with a fresh block when
empty. draw_bootstrap_indices() resamples within strata by default
(bootstrap_type = "within_blocks" or NULL) or resamples whole strata
otherwise.
References
Zelen, M. (1974). "The randomization and stratification of patients to
clinical trials." Journal of Chronic Diseases, 27(7-8), 365-375,
doi:10.1016/0021-9681(74)90015-0
, for stratified permuted-block randomization.
See also block
randomisation for orientation, and
DesignSeqOneByOneRandomBlockSize
for the randomly-varying-block-size variant.
Super classes
Design -> DesignSeqOneByOne -> DesignSeqOneByOneSPBR
Methods
+ inherited public methods from DesignSeqOneByOne
+ inherited public methods from Design
Design$add_all_subject_responses()Design$add_one_subject_response()Design$any_censoring()Design$applicable_inference_class_names()Design$assert_all_responses_recorded()Design$assert_all_subjects_arrived()Design$assert_even_allocation()Design$assert_fixed_sample()Design$capabilities()Design$check_experiment_completed()Design$draw_ws_according_to_design()Design$duplicate()Design$get_X()Design$get_X_imp()Design$get_X_raw()Design$get_design_formula()Design$get_edi_version_created()Design$get_effective_dead()Design$get_effective_time()Design$get_missingness_method()Design$get_n()Design$get_ordinal_levels()Design$get_original_ordinal_levels()Design$get_prob_T()Design$get_response_type()Design$get_response_type_original()Design$get_t()Design$get_w()Design$get_y()Design$get_y_L()Design$get_y_R()Design$get_y_original()Design$has_general_censoring()Design$incompatible_inference_classes_due_to_design_structure()Design$is_a_bernoulli_capable()Design$is_a_cluster_capable()Design$is_a_kk_matching_capable()Design$is_blocking_design()Design$is_fixed_sample_size()Design$is_matching_design()Design$overwrite_all_subject_assignments()Design$prepare_for_resampling_replay()Design$randomization_family()Design$supports()Design$supports_randomization_draw()Design$supports_resampling()Design$supports_resampling_replay()Design$transform_y()Design$unavailable_inference_classes_due_to_missing_packages()Design$warm_all_subject_data_cache()
DesignSeqOneByOneSPBR$new()
Initialize a stratified permuted-block sequential experimental design with fixed block size (see class documentation for the exact block-refill rule).
Usage
DesignSeqOneByOneSPBR$new(
strata_cols,
block_size = 4,
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_colsA character vector of column names to use for stratification.
block_sizeThe size of the permuted blocks (fixed; see class documentation for its compatibility requirement with
prob_T).response_type"continuous", "incidence", "proportion", "count", "survival", or "ordinal".
prob_TProbability of treatment assignment.
include_is_missing_as_a_new_featureFlag for missingness indicators.
nThe sample size.
verboseA flag for verbosity.
missingness_methodHow to handle missing values in covariates.
design_formulaA formula object.
seedInteger seed for reproducibility.
DesignSeqOneByOneSPBR$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 fixed-size, randomly-ordered block first if it is empty.
Examples
seq_des = DesignSeqOneByOneSPBR$new(strata_cols = 'x1', n = 6, response_type = 'continuous')
seq_des$add_one_subject_to_experiment_and_assign(data.frame(x1 = factor(1, levels=1:2)))
#> [1] 1