Skip to contents

A fixed-sample-size DesignFixed that searches, among allocations with exactly \(n_T = \mathrm{round}(n \cdot \mathrm{prob}_T)\) treated subjects, for one that directly minimizes a covariate imbalance criterion \(f(d)\), \(d = M(2w - 1)\), via a native C++ (RcppEigen + OpenMP) greedy pairwise-swap search (greedy_design_search_cpp()). Unlike DesignFixedGreedyDOptimal, which optimizes a model-based information-matrix criterion (D-/A-optimality) implied by an assumed linear model, this design optimizes a direct covariate-distance criterion between the treated and control group means/covariance, with no linear-model assumption: the two supported objectives are

  • "mahal_dist" (default): \(d = L^{-1} X^\top (2w-1) / n\) where \(\Sigma = LL^\top\) is the Cholesky factor of the covariate covariance matrix, and \(f(d) = \lVert d \rVert_2^2\) — the squared Mahalanobis distance between the treated and control covariate means, accounting for covariate correlation/scale. Falls back to "abs_sum_diff" if the covariate covariance matrix is (numerically) singular, since the Cholesky factorization then fails.

  • "abs_sum_diff": \(d = X_{\mathrm{std}}^\top (2w-1) / n\) (covariates standardized to unit variance, no correlation adjustment) and \(f(d) = \lVert d \rVert_1\) — the sum of absolute standardized mean differences across covariates.

Search algorithm. Starting from a random (Fisher-Yates) allocation with \(n_T\) treated, the search runs in one of two modes selected by n_iter: Inf (default) runs exhaustive best-improvement search — each round scans every (treated, control) pair, applies the single globally best improving swap, and repeats until no swap improves \(f(d)\), guaranteeing convergence to a strict local optimum; a positive integer instead runs exactly that many stochastic steps, each picking a uniformly random (treated, control) pair and accepting the swap only if it improves \(f(d)\), with no early stopping. r independent design searches (one per requested replicate) run in parallel via OpenMP, each with its own random-number stream. This search's randomization is reproducible via the constructor's seed argument: one master seed is drawn from R's own RNG state (GetRNGstate()/unif_rand()) before the parallel region begins, and each replicate's stream is derived from that seed and the replicate's index, so private$maybe_set_seed() does govern the resulting allocation, independent of the number of OpenMP threads used.

Same draws as DesignFixedGreedyDOptimal at the defaults. With objective = "mahal_dist" and n_iter = Inf (the defaults), this class returns exactly the same allocations as DesignFixedGreedyDOptimal with its defaults (objective = "D", no prior_precision) for the same seed. Despite the "no linear-model assumption" framing above, the default criterion coincides with D-optimality: with the number of treated subjects fixed, the information about the treatment effect in the linear model \(y = \beta_T w + \beta_0 + X \gamma + \epsilon\) equals a constant minus a positive multiple of the squared Mahalanobis distance between the treated and control covariate means. Both criteria therefore rank every allocation the same way, and the same swap search from the same starting allocation reaches the same allocation (the derivation is in DesignFixedGreedyDOptimal's documentation). The draws differ when this class uses objective = "abs_sum_diff", a finite n_iter, or the "abs_sum_diff" fallback after a failed Cholesky factorization, and when DesignFixedGreedyDOptimal uses objective = "A" with interest = "all" or a covariate subset, or a prior_precision. Ties are the exception: the two searches compute their criteria differently in floating point, so when covariates have ties and several swaps improve the criterion by the same amount, they can break the tie differently and stop at different allocations with nearly the same balance. In one example with weights rounded to 0.1 and ages in whole weeks, 10 of 20 draws agreed.

Unequal arms. Any prob_T in \((0, 1)\) is supported; the search keeps the treated count fixed at \(n_T = \mathrm{round}(n \cdot \mathrm{prob}_T)\), and drawing errors if that leaves no treated or no control subject. The kernel centers \(X\), so \(M(2w - 1) = 2Mw\), a fixed positive multiple of the half treated-minus-control mean difference at every \(n_T\): both objectives keep their balance meaning without any change to the swap update.

Constraints and fallbacks. If no covariates are available, the search degenerates to pure Fisher-Yates randomization with \(n_T\) treated (no swap search, since there is nothing to balance on). greedy_design_search_cpp()'s output is trusted unvalidated – it guarantees exactly n x r valid \(\{0,1\}\) columns with \(n_T\) treated subjects per column by construction (see fix_design_hierarchy.md, "AllocationMatrixValidation").

References

Krieger, A. M., Azriel, D., and Kapelner, A. (2019). "Nearly random designs with greatly improved balance." Biometrika, 106(3), 695-701, doi:10.1093/biomet/asz026 , for the greedy-swap balance-optimization approach this class implements. See also Mahalanobis distance for orientation on the default objective.

Super classes

Design -> DesignFixed -> DesignFixedGreedy

Methods

+ inherited public methods from DesignFixed
+ inherited public methods from Design


DesignFixedGreedy$new()

Initialize a greedy pairwise-swap search fixed experimental design. Any prob_T in \((0, 1)\) is supported (see class documentation).

Usage

DesignFixedGreedy$new(
  response_type,
  prob_T = 0.5,
  objective = "mahal_dist",
  n_iter = Inf,
  include_is_missing_as_a_new_feature = TRUE,
  n = NULL,
  verbose = FALSE,
  missingness_method = "impute",
  design_formula = ~.,
  seed = NULL
)

Arguments

response_type

The data type of response values.

prob_T

The probability of the treatment assignment; the search fixes the treated count at round(n * prob_T).

objective

The covariate-imbalance objective to minimize: either "mahal_dist" (default, squared Mahalanobis distance between treated and control covariate means) or "abs_sum_diff" (sum of absolute standardized mean differences); see class documentation for the exact criteria.

n_iter

Number of swap iterations. Inf (default) uses exhaustive best-improvement search guaranteed to reach a strict local optimum. A positive integer runs exactly that many stochastic random-pair iterations (no early stopping), each accepting the swap only if it improves the objective.

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).

verbose

Flag for verbosity.

missingness_method

How to handle missing values in covariates.

design_formula

A formula object.

seed

Integer seed for reproducibility. This design's search is reproducible via seed (see class documentation).

Returns

A new `DesignFixedGreedy` object


DesignFixedGreedy$supports_batch_w_pregeneration()

Returns TRUE so the calling framework pre-generates all replicate w vectors for a simulation cell in a single batched call to greedy_design_search_cpp() (which parallelizes the r independent searches over OpenMP threads internally), rather than issuing r separate single-replicate C++ calls.

Usage

DesignFixedGreedy$supports_batch_w_pregeneration()

Returns

Always TRUE for this class.


DesignFixedGreedy$clone()

The objects of this class are cloneable with this method.

Usage

DesignFixedGreedy$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

des = DesignFixedGreedy$new(n = 10, response_type = 'continuous')
des$add_all_subjects_to_experiment(data.frame(x1 = rnorm(10), x2 = rnorm(10)))
des$assign_w_to_all_subjects()