Skip to contents

A 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


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.

Usage

DesignFixedBlockedCluster$set_m(m)

Arguments

m

A non-negative-integer vector of block ids, one per subject.

Returns

Invisibly returns self.


DesignFixedBlockedCluster$is_a_cluster_capable()

Characterization: this design randomizes whole clusters (see class documentation), so it is cluster-structured by construction.

Usage

DesignFixedBlockedCluster$is_a_cluster_capable()

Returns

Always TRUE for this class.


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_cols

A character vector of column names to use for stratification (blocks).

cluster_col

The column name in the data that identifies the cluster for each subject.

response_type

The data type of response values.

prob_T

The 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_feature

Flag for missingness indicators.

n

The sample size. If NULL (default), n is set to nrow(X_all) when the subjects are added with add_all_subjects_to_experiment(); a given n must equal nrow(X_all). Assigning before the subjects are added needs n (a covariate-free design such as iBCRD or Bernoulli can then assign without X).

preferred_num_bins_for_continuous_covariate

The number of quantile bins to use for continuous strata. Default is 2.

num_bins_for_continuous_covariate

Deprecated alias for `preferred_num_bins_for_continuous_covariate`.

verbose

Flag for verbosity.

missingness_method

How to handle missing values in covariates.

design_formula

A formula object.

seed

Integer seed for reproducibility.

Returns

A new `DesignFixedBlockedCluster` object


DesignFixedBlockedCluster$clone()

The objects of this class are cloneable with this method.

Usage

DesignFixedBlockedCluster$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

des = DesignFixedBlockedCluster$new(n = 20, response_type = 'continuous',
  strata_cols = 'x2', cluster_col = 'cl')
X = data.frame(x1 = rnorm(20), x2 = factor(rep(1:2, each = 10)), cl = factor(rep(1:10, each = 2)))
des$add_all_subjects_to_experiment(X)
des$assign_w_to_all_subjects()