Skip to contents

An 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


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.

Usage

ObservationalDesignMatching$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.


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

n

The sample size; must be even (subjects 2k - 1/2k form pair k, so an odd n would leave one subject unpaired).

include_is_missing_as_a_new_feature

Flag for missingness indicators.

verbose

A 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 `ObservationalDesignMatching` object


ObservationalDesignMatching$clone()

The objects of this class are cloneable with this method.

Usage

ObservationalDesignMatching$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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