
A Fixed, Blocked-and-Clustered Randomized Design
Source:R/design_fixed_blocked_cluster.R
DesignFixedBlockedCluster.RdA fixed-sample-size DesignFixed in which the unit of
randomization is the cluster, not the individual subject: within each block
(stratum, formed from strata_cols), whole clusters (identified by
cluster_col) are jointly randomized to treatment or control, so all subjects in
the same cluster always receive the same assignment. This is the design used when
individual-level randomization is infeasible or invalid (e.g. clusters are classrooms,
clinics, or households where within-cluster interference/spillover would violate
SUTVA under individual randomization), combined with blocking to improve precision by
comparing clusters only to other clusters in the same stratum.
Randomization mechanism. Blocking keys are computed per subject via
private$get_strata_keys() (shared with other
blocking-structure designs): categorical columns in
strata_cols are used as-is, continuous columns are discretized into
preferred_num_bins_for_continuous_covariate quantile-based bins, and multiple
strata_cols are combined into a single composite block key. Within each
resulting block, whole clusters (by cluster_col) are randomized to treatment
with probability prob_T using the same per-block law as block_and_cluster_ra
(randomizr), which performs blocked-and-clustered complete random assignment:
within each block, clusters (not subjects) are permuted so that, subject to rounding,
the target proportion prob_T of clusters in that block is treated, and every
subject in a treated cluster receives \(w = 1\). r independent replicate
allocation columns are generated by one batched block_ra_batch() pass (no per-
replicate randomizr call; there is a batch/vectorized draw path for this design, like
DesignFixedBinaryMatch).
Block and cluster sizes. Blocks need not hold the same number of subjects,
and clusters need not either: the unit randomized is the cluster, so each block treats
prob_T of its own clusters whatever the block and cluster sizes. (Unlike
DesignFixedBlocking, this class has no
equal_block_sizes or B_target argument.) Each cluster must lie within a
single block; assign_w_to_all_subjects() errors when a cluster spans two blocks.
Jackknife. The jackknife (compute_jackknife_*()) returns NA with
an edi_procedure_na_warning for unit = "auto" (which resolves to
"cluster"), "cluster" and "observation": on a blocking design whose
blocks hold more than one subject EDI has no stratified leave-one-cluster-out
jackknife, and the unstratified delete-one-cluster formula would treat the clusters as
exchangeable across blocks although they were randomized within blocks.
unit = "block" (leave-one-block-out) is computed only with at least 5 blocks
(fewer deletion units give NA, as on every design).
unit = "observation_within_block" returns a value but deletes single subjects,
ignoring the clusters, so it is not a cluster-robust variance here. Use the
randomization test or the cluster bootstrap below.
Cluster-aware bootstrap. draw_bootstrap_indices() overrides the default
subject-level bootstrap to resample at the cluster level via
resample_group_rows_cpp(): with bootstrap_type = "within_blocks"
(the default when bootstrap_type is NULL), clusters are resampled with
replacement within each block, preserving the block structure; otherwise, whole
blocks (strata) are themselves resampled with replacement. This mirrors the standard
cluster-robust bootstrap principle that resampling must occur at the level of the
randomization unit (clusters), not individual subjects, to yield a valid
variance/interval estimate under cluster-correlated outcomes.
References
Middleton, J. A., and Aronow, P. M. (2015). "Unbiased estimation of the average treatment effect in cluster-randomized experiments." Statistics, Politics and Policy, 6(1-2), 39-75, doi:10.1515/spp-2013-0002 , for blocked/clustered randomized-assignment inference; see also the randomizr package vignette for the assignment-generation conventions this design relies on, and cluster randomized controlled trial for orientation.
Super classes
Design -> DesignFixed -> DesignFixedBlockedCluster
Methods
+ inherited public methods from DesignFixed
+ inherited public methods from Design
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_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()
DesignFixedBlockedCluster$set_m()
Record explicit block identifiers, inherited from the blocking
component. On this class it does not change the randomization:
assignments are always drawn over whole clusters within the blocks formed from
strata_cols, whatever set_m() stored. The stored ids are what
$get_block_ids() (and block-aware inference that reads it) then report,
so ids that differ from the strata_cols blocks make the analysis strata
disagree with the randomization strata; there is normally no reason to call it
here. It can be called only while no block ids are stored yet: the first
$get_block_ids() call stores the covariate-derived ids, and
set_m() errors after that.
DesignFixedBlockedCluster$is_a_cluster_capable()
Characterization: this design randomizes whole clusters (see class documentation), so it is cluster-structured by construction.
DesignFixedBlockedCluster$new()
Initialize a blocked and cluster randomized fixed experimental design.
Usage
DesignFixedBlockedCluster$new(
strata_cols,
cluster_col,
response_type,
prob_T = 0.5,
include_is_missing_as_a_new_feature = TRUE,
n = NULL,
preferred_num_bins_for_continuous_covariate = 2,
num_bins_for_continuous_covariate = NULL,
verbose = FALSE,
missingness_method = "impute",
design_formula = ~.,
seed = NULL
)Arguments
strata_colsA character vector of column names to use for stratification (blocks).
cluster_colThe column name in the data that identifies the cluster for each subject.
response_typeThe data type of response values.
prob_TThe target probability that a given cluster within a block is assigned to treatment (subjects inherit their cluster's assignment). It is the share of clusters treated in each block, not of subjects: with unequal cluster sizes the share of subjects treated varies from draw to draw around it.
include_is_missing_as_a_new_featureFlag for missingness indicators.
nThe sample size. If
NULL(default),nis set tonrow(X_all)when the subjects are added withadd_all_subjects_to_experiment(); a givennmust equalnrow(X_all). Assigning before the subjects are added needsn(a covariate-free design such as iBCRD or Bernoulli can then assign withoutX).preferred_num_bins_for_continuous_covariateThe number of quantile bins to use for continuous strata. Default is 2.
num_bins_for_continuous_covariateDeprecated alias for `preferred_num_bins_for_continuous_covariate`.
verboseFlag for verbosity.
missingness_methodHow to handle missing values in covariates.
design_formulaA formula object.
seedInteger seed for reproducibility.