
A Fixed Observational (Non-Randomized) Matched-Pair Design
Source:R/design_observational_matching.R
ObservationalDesignMatching.RdAn ObservationalDesign whose \(n\) subjects
are organized into \(n/2\) matched pairs, each of size exactly 2. This is a
convenience wrapper: it builds the canonical pair-membership vector
\(m = (1, 1, 2, 2, \dots, n/2, n/2)\) internally – subject \(2k - 1\) and subject
\(2k\) are pair \(k\) – and installs it via set_m(), so the caller need
only supply subjects (and, later, responses) in that paired order; there is no
separate m argument to get wrong.
Why not just ObservationalDesignBlocks with block size 2? It would
look equivalent but silently behave differently: matching is a distinct capability
(private$matching_capable, checked via is_matching_design()) from
generic blocking, and several Inference components (jackknife, nonparametric
bootstrap, Bayesian bootstrap, exchangeable-resampling-unit selection) branch on it to
use pair-preserving resampling (MatchingStructure's
draw_bootstrap_indices(), via draw_matching_bootstrap_sample_cpp())
instead of generic per-stratum resampling. ObservationalDesignBlocks overrides
draw_bootstrap_indices() with the generic stratified version, so subclassing it
here would advertise is_matching_design() == TRUE while still running the
wrong bootstrap underneath. This class instead extends
ObservationalDesign directly – the same
relationship DesignFixedBinaryMatch has to
DesignFixed – so it inherits
MatchingStructure's matched-pair bootstrap machinery unmodified.
Super classes
Design -> DesignFixed -> ObservationalDesign -> ObservationalDesignMatching
Methods
+ inherited public methods from ObservationalDesign
+ 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_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_resampling()Design$transform_y()Design$unavailable_inference_classes_due_to_missing_packages()Design$warm_all_subject_data_cache()
ObservationalDesignMatching$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.
ObservationalDesignMatching$new()
Initialize a fixed observational (non-randomized) design whose
subjects are organized into n / 2 matched pairs of size 2 (subjects
2k - 1 and 2k form pair k). Unlike
ObservationalDesignBlocks
there is no separate m argument — the pair structure is fixed by
subject order and installed automatically via set_m(), and
private$matching_capable is set so downstream Inference
classes use pair-preserving (not generic stratified) resampling (see class
documentation). As with every ObservationalDesign, \(w\) itself is
supplied afterward via
assign_w_to_all_subjects(w_precomputed = ...), in the same paired
subject order.
Usage
ObservationalDesignMatching$new(
response_type,
n,
include_is_missing_as_a_new_feature = TRUE,
verbose = FALSE,
missingness_method = "impute",
design_formula = ~.,
seed = NULL
)Arguments
response_type"continuous", "incidence", "proportion", "count", "survival", or "ordinal".
nThe sample size; must be even (subjects
2k - 1/2kform pairk, so an oddnwould leave one subject unpaired).include_is_missing_as_a_new_featureFlag for missingness indicators.
verboseA flag for verbosity.
missingness_methodHow to handle missing values in covariates.
design_formulaA formula object.
seedInteger seed for reproducibility.
Examples
des = ObservationalDesignMatching$new(response_type = 'continuous', n = 6)
des$add_all_subjects_to_experiment(data.frame(x1 = rnorm(6)))
des$assign_w_to_all_subjects(w_precomputed = c(1, 0, 0, 1, 1, 0))