
A Fixed Rerandomization Design (Rejection-Sampled on Covariate Balance)
Source:R/design_fixed_rerandomization.R
DesignFixedRerandomization.RdA fixed-sample-size DesignFixed implementing
rerandomization (Morgan and Rubin, 2012): candidate allocations \(w\) are drawn
from the design's base randomization law, complete randomization with exactly
\(n_T = \mathrm{round}(n \cdot prob\_T)\) treated subjects at every
prob_T and on every draw path, and only accepted if a covariate
imbalance criterion \(M(w)\) between the treated and control groups falls below a
threshold a (obj_val_cutoff), i.e. the accepted allocations are drawn
from the base randomization distribution truncated to \(\{w : M(w) \le a\}\).
Unlike DesignFixedGreedy/
DesignFixedGreedyDOptimal, which search for a
single well-balanced allocation, rerandomization instead filters the design's
own randomization distribution, which is what makes it directly compatible with
Fisherian/randomization-based inference (the accepted allocations remain a
well-defined — if truncated — randomization distribution, valid for randomization
tests/CIs restricted to that truncated support).
Two mutually exclusive acceptance modes are supported (specifying both errors):
obj_val_cutoff accepts/rejects each draw against a fixed threshold a;
prop_acceptable instead makes every allocation the one with the lowest
\(M(w)\) among \(k = \mathrm{round}(1 / prop\_acceptable)\) independent base draws
(best of \(k\)). The same rule gives the realized allocation and every redrawn one
(randomization p-values and CIs, bootstrap-randomization replays), so the realized
allocation and the randomization reference follow the same law and the randomization
test keeps its size. Best of \(k\) is not the base law truncated at its
prop_acceptable quantile: a best-of-\(k\) draw lies above that quantile with
probability \((1 - prop\_acceptable)^k \approx e^{-1}\). Use obj_val_cutoff for
a truncation at a fixed cutoff.
Objective \(M(w)\). objective = "mahal_dist" (default) uses the
squared Mahalanobis distance between treated and control covariate means,
\(M(w) = (\bar X_T - \bar X_C)^\top S^{-1} (\bar X_T - \bar X_C)\), where \(S\) is
the sample covariance of all covariates (ridge-regularized by \(10^{-6}I\) if
\(|\det S| < 10^{-10}\)), cached in private$S_inv and recomputed
whenever the covariate matrix changes (e.g. on a bootstrap-randomization replay).
objective = "abs_sum_diff" instead uses the sum of absolute
standardized mean differences,
\(M(w) = \sum_j |\bar X_{T,j} - \bar X_{C,j}| / s_j\), where \(s_j\) is the
sample standard deviation of covariate \(j\) over all \(n\) subjects (a
zero-variance covariate contributes nothing), with no correlation adjustment. Like
"mahal_dist", it is therefore scale-invariant: rescaling a covariate does not
change which allocations are accepted. This is the same criterion as
DesignFixedGreedy's "abs_sum_diff", and
every draw path uses it. (Through EDI 1.0.5 the pure-R path, used for odd \(n\) or
prob_T != 0.5 with obj_val_cutoff, used unstandardized differences, so
it accepted a different set of allocations than the other paths for the same cutoff.)
Only these two objectives are supported; any other value errors in the constructor.
Fast path (native C++). When prob_T = 0.5 and \(n\) is even,
candidate generation and filtering run via a parallel C++ rejection sampler
(rerandomization_search_cpp()), which internally works with a rescaled
objective \(f_{\mathrm{cpp}}\): \(f_{\mathrm{cpp}} = M(w)/4\) for
"mahal_dist" and \(f_{\mathrm{cpp}} = M(w)/2\) for "abs_sum_diff";
the user-facing obj_val_cutoff is converted to this internal scale before
being passed to C++, so the accepted allocations are those with \(M(w) \le a\),
exactly as on the other paths. One exception: if the Cholesky factorization of the
covariate covariance fails (a covariance that is not numerically positive definite),
the fast path's "mahal_dist" falls back to the standardized
"abs_sum_diff" criterion (accepting \(M_{\mathrm{abs}}(w) \le a/2\)),
whereas the other paths ridge-regularize \(S\). The
sampler draws up to max(r * 1000, 100000) candidates internally; if fewer than
r allocations are accepted within that budget (an overly tight cutoff), this
errors naming how many were actually found – loosen obj_val_cutoff or use
prop_acceptable instead. (Earlier versions silently recycled the accepted set
to pad out to r, duplicating some draws; fixed, since that meant some
"independent" replicates were literal duplicates of an accepted allocation.)
Seed reproducibility and multi-core parallelism. The C++ fast path
derives each candidate's local RNG stream from its logical draw index, rather
than from the OpenMP worker evaluating it. It evaluates deterministic,
contiguous candidate blocks in fixed-size waves and returns accepted
allocations in draw-index order. Consequently, a fixed seed returns
the same allocations at every configured core count; adding cores changes
only which worker evaluates a candidate. The package default is one core,
but this reproducibility guarantee also holds after
set_num_cores or when using a fork cluster/mirai daemons.
prop_acceptable path. Uses
complete_randomization_forced_balanced_cpp() (prob_T = 0.5 with even
\(n\)) or complete_randomization_imbalanced_cpp() (any other case, with
\(n_T = \mathrm{round}(n \cdot prob\_T)\), so n = 23 at prob_T = 0.5
has 12 treated; before v1.0.6 odd \(n\) at 0.5 had \(\lfloor n/2 \rfloor\)) to draw
\(n_{\mathrm{draw}} = r \cdot \mathrm{round}(1 / prop\_acceptable)\) candidate allocations
in one batched call, computes \(M(w)\) for all of them via
compute_objective_vals_cpp(), and returns the lowest-\(M(w)\) draw of each
consecutive group of \(k = \mathrm{round}(1 / prop\_acceptable)\) draws
(\(n_{\mathrm{draw}} = r k\)). The realized allocation is the \(r = 1\) case. Through
EDI 1.0.5 a request for \(r > 1\) draws kept the best \(r\) of all
\(\mathrm{round}(r / prop\_acceptable)\) draws, a tighter law than the realized
best-of-\(k\) allocation, so the randomization test over-rejected (about 7% at
nominal 5% in one audit); realized allocations are unchanged.
Choosing obj_val_cutoff for a target acceptance rate. The
acceptance rate of a cutoff \(a\) is \(P(M(w) \le a)\) under the base complete
randomization of the design's own covariates. For "mahal_dist", \(M(w)\)
is the Mahalanobis distance between the two means with no
\(1/n_T + 1/n_C\) factor, so Morgan and Rubin's (2012) statistic is
\(\frac{n_T n_C}{n} M(w)\), which is approximately
\(\chi^2_k\) (\(k\) = number of covariate columns used, after dummy coding),
exactly so only asymptotically or for normal covariate means. An approximate cutoff
for acceptance rate \(p_a\) is therefore
a = qchisq(p_a, df = k) * n / (n_T * n_C); e.g. \(k = 2\), \(n = 44\),
\(n_T = n_C = 22\), \(p_a = 0.01\) gives \(a \approx 0.0018\). For
"abs_sum_diff" there is no closed form. In either case the exact rate for
your data is the empirical quantile of \(M(w)\) over complete randomizations with
\(n_T\) treated, which you can simulate. prop_acceptable = p_a targets the
rate directly: each allocation is the best of \(\mathrm{round}(1 / p_a)\) draws, so
no cutoff needs to be chosen (it is a best-of-\(k\) rule, not a fixed cutoff at the
\(p_a\) quantile; see above). Very small rates make the obj_val_cutoff search slower and can hit
the max(1000 r, 1e5) candidate budget described above.
Pure-R fallback (unbalanced or odd \(n\), obj_val_cutoff mode
only). Draws candidates in vectorized batches (uniformly random subsets of size
\(n_T = \mathrm{round}(n \cdot prob\_T)\)), scores each batch at once, and keeps the first \(r\) candidates with
\(M(w) \le a\). Candidates with an empty arm are rejected. Like the C++ fast path
it stops with an error after max(1000 r, 1e5) candidates if fewer than
\(r\) are acceptable.
References
Morgan, K. L., and Rubin, D. B. (2012). "Rerandomization to improve covariate balance in experiments." The Annals of Statistics, 40(2), 1263-1282, doi:10.1214/12-AOS1008 , for the rerandomization framework and its randomization-inference validity. See also Mahalanobis distance for the default objective.
Super classes
Design -> DesignFixed -> DesignFixedRerandomization
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_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()
DesignFixedRerandomization$new()
Initialize a rerandomization fixed experimental design.
Exactly one of obj_val_cutoff/prop_acceptable must be
specified: supplying neither or both raises an error. (With neither, the design would accept every
candidate, i.e. be complete randomization with a fixed number treated; pass
prop_acceptable = 1 to ask for that explicitly.) See class documentation for the exact
acceptance semantics of each mode and the covariate-imbalance objective.
Usage
DesignFixedRerandomization$new(
response_type,
prob_T = 0.5,
obj_val_cutoff = NULL,
prop_acceptable = NULL,
objective = "mahal_dist",
include_is_missing_as_a_new_feature = TRUE,
n = NULL,
verbose = FALSE,
missingness_method = "impute",
design_formula = ~.,
seed = NULL
)Arguments
response_typeThe data type of response values.
prob_TThe probability of the treatment assignment. Every draw has exactly
round(n * prob_T)treated subjects; drawing errors if that leaves no treated or no control subject.obj_val_cutoffThe maximum allowable objective value \(a\); a candidate allocation is accepted iff \(M(w) \le a\). Exactly one of this and prop_acceptable is required. For how to pick \(a\) for a target acceptance rate, see "Choosing
obj_val_cutofffor a target acceptance rate" in the class details.prop_acceptableThe proportion of randomizations to accept, e.g.
0.1: the realized allocation and every reference allocation (randomization tests and CIs) are each the best (lowest \(M(w)\)) ofround(1 / prop_acceptable)independent base draws. Exactly one of this and obj_val_cutoff is required.objectiveThe covariate-imbalance objective \(M(w)\) to filter on: either
"mahal_dist"(default, squared Mahalanobis distance) or"abs_sum_diff"(sum of absolute standardized mean differences); see class documentation for the exact formulas. Any other value errors.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).verboseFlag for verbosity.
missingness_methodHow to handle missing values in covariates.
design_formulaA formula object.
seedInteger seed for reproducibility.
Examples
des = DesignFixedRerandomization$new(n = 10, response_type = 'continuous', prop_acceptable = 0.1)
des$add_all_subjects_to_experiment(data.frame(x1 = rnorm(10), x2 = rnorm(10)))
des$assign_w_to_all_subjects()