Skip to contents

A fixed-sample-size DesignFixed that combines DesignFixedBinaryMatch's non-bipartite matched-pair structure with DesignFixedGreedy's greedy imbalance-minimization search, restricted so every move respects the pairing: subjects are first paired by covariate closeness (as in DesignFixedBinaryMatch), guaranteeing exactly one treated and one control subject per pair; then, rather than assigning within-pair treatment status by a coin flip, the greedy search (greedy_design_search_cpp(), pair-constrained mode) chooses which member of each pair is treated so as to directly minimize the same aggregate covariate-imbalance objective as DesignFixedGreedy (squared Mahalanobis distance or sum of absolute standardized mean differences between the treated and control group means) across the whole sample, not just within each pair. This targets both close within-pair matches (from the matching step) and low aggregate covariate imbalance (from the greedy refinement) simultaneously — a strictly more constrained search than plain DesignFixedGreedy, since only the \(2^{n/2}\) which-member-treated assignments consistent with the fixed pairing are considered, rather than all \(\binom{n}{n/2}\) balanced allocations.

Search algorithm. Pairing is computed by compute_binary_match_structure() exactly as in DesignFixedBinaryMatch (Mahalanobis or Euclidean distance per objective), lazily on first draw and cached in private$bms. Given the pairing, each replicate search initializes with a random coin flip per pair (which member starts treated), then in exhaustive mode (n_iter = Inf, default) repeatedly finds and applies the single pair-flip that most decreases the imbalance objective, stopping at a strict local optimum (or runs exactly n_iter random-pair stochastic flip-if-improving steps otherwise, with no early stopping) — the same two search modes as DesignFixedGreedy, but with moves restricted to "flip which side of a given pair is treated" rather than "swap any treated/control pair of subjects." Random initialization and swap selection are seeded from R's own RNG (via greedy_design_search_cpp(), which derives one stream per draw index from a master seed), so seed governs reproducibility here and the draws are the same at every set_num_cores() setting.

Pair-preserving bootstrap. draw_bootstrap_indices() resamples whole matched pairs (via draw_matching_bootstrap_sample_cpp()) rather than individual subjects, since the greedy search only ever flips which member of a pair is treated (never crosses pairs), so \(w\) always has exactly one treated subject per pair — the pair, not the subject, is the exchangeable resampling unit.

Constraints. Allocation is always 1:1 (there is no prob_T argument), and n must be divisible by 4 (draw_ws_raw() errors otherwise). DesignFixedBinaryMatch requires only even n (forming n/2 matched pairs); this class additionally requires n to be divisible by 4.

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 ; Greevy, R., Lu, B., Silber, J. H., and Rosenbaum, P. (2004). "Optimal multivariate matching before randomization." Biostatistics, 5(2), 263-275, doi:10.1093/biostatistics/5.2.263 , for the matched-pair design this class refines.

Super classes

Design -> DesignFixed -> DesignFixedMatchingGreedyPairSwitching

Methods

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


DesignFixedMatchingGreedyPairSwitching$new()

Initialize a fixed design that performs binary matching followed by greedy which-member-treated optimization (see class documentation). n must be divisible by 4. There is no prob_T argument: allocation is always 1:1 (prob_T = 0.5) because each matched pair gets one treated and one control subject.

Usage

DesignFixedMatchingGreedyPairSwitching$new(
  response_type,
  include_is_missing_as_a_new_feature = TRUE,
  n,
  verbose = FALSE,
  objective = "mahal_dist",
  match_objective = c("distance", "squared_distance"),
  n_iter = Inf,
  missingness_method = "impute",
  design_formula = ~.,
  seed = NULL
)

Arguments

response_type

The data type of response values.

include_is_missing_as_a_new_feature

Flag for missingness indicators.

n

The sample size; must be divisible by 4.

verbose

A flag for verbosity.

objective

The covariate-imbalance objective to minimize when choosing which pair member is treated: either "mahal_dist" (default, squared Mahalanobis distance between treated/control means, also used as the matching distance) or "abs_sum_diff" (sum of absolute standardized mean differences); see class documentation for the exact criteria.

match_objective

Matching objective used to form pairs. "distance" (default) minimizes the total unsquared distance, as nbpMatching does; "squared_distance" reproduces EDI through version 1.0.4. The default changed in 1.0.5 and alters about 22% of matched pairs relative to 1.0.x (measured at n = 1000, p = 4).

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 flip only if it improves the objective.

missingness_method

How to handle missing values in covariates.

design_formula

A formula object.

seed

Integer seed for reproducibility.

Returns

A new DesignFixedMatchingGreedyPairSwitching object.


DesignFixedMatchingGreedyPairSwitching$supports_batch_w_pregeneration()

Returns TRUE so the calling framework pre-generates all replicate w vectors for a simulation cell in one batched call to greedy_design_search_cpp(), paying the one-time nbpMatching pairing cost once per cell (cached in private$bms) and reusing it across all replicates and the OpenMP-parallelized greedy searches, rather than recomputing the pairing per replicate.

Usage

DesignFixedMatchingGreedyPairSwitching$supports_batch_w_pregeneration()

Returns

Always TRUE for this class.


DesignFixedMatchingGreedyPairSwitching$get_matching_cluster_ids()

Cluster ids implied by the matching: the two members of matched pair k share id k, and every unmatched (reservoir) subject gets its own singleton id, numbered after the largest pair id. Use these ids wherever pair membership is needed, for example to cluster standard errors or to cross-check a matched-pairs analysis outside EDI.

Usage

DesignFixedMatchingGreedyPairSwitching$get_matching_cluster_ids(
  m_vec = private$m
)

Arguments

m_vec

Optional integer match vector, one entry per subject: the pair id, or 0 / NA for an unmatched subject. Defaults to this design's own match vector.

Returns

An integer vector of length n.


DesignFixedMatchingGreedyPairSwitching$clone()

The objects of this class are cloneable with this method.

Usage

DesignFixedMatchingGreedyPairSwitching$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

des = DesignFixedMatchingGreedyPairSwitching$new(n = 12, response_type = 'continuous')
# \donttest{
# (the pairing step loads the nbpMatching package, which takes a few seconds)
if (requireNamespace("nbpMatching", quietly = TRUE)) {
  des$add_all_subjects_to_experiment(data.frame(x1 = rnorm(12), x2 = rnorm(12)))
  des$assign_w_to_all_subjects()
}
# }