Skip to contents

Creates 1:1 matched pairs of vaccinated ("cases") and unvaccinated ("controls") individuals. Uses a rolling cohort design where controls must be unvaccinated and event-free at the time they are matched to a case.

Usage

match_rolling_cohort(
  data,
  outcome_time,
  exposure,
  exposure_time,
  matching_vars,
  id_name,
  replace = FALSE,
  seed = NULL
)

Arguments

data

Data frame with study population

outcome_time

Name of the time-to-event/censoring variable. Time should be measured from a given time origin (e.g. study start, enrollment, or age) for all individuals.

exposure

Name of the exposure indicator. The underlying column should be numeric (1 = exposed during follow-up, 0 = never exposed during follow-up).

exposure_time

Name of the time to exposure, measured from the chosen time origin; use NA if not exposed. Time must be measured in the same units (e.g. days) as that used for outcome_time.

matching_vars

Character vector of variables to match on exactly

id_name

Name of unique identifier variable of individuals

replace

Logical. Allow controls to be reused? Default: FALSE

seed

Integer for reproducibility. Default: NULL

Value

A list containing the following:

matched_data

Data frame of matched pairs with original variables plus:

  • match_index_time: Matching time

  • match_type: "case" or "control"

  • match_<exposure>: Treatment at matching

  • match_id: Pair identifier

n_unmatched_cases

Number of unmatched vaccinated individuals

discarded

Logical vector indicating excluded individuals

Details

For each vaccination time, newly vaccinated individuals are matched to eligible controls using exact covariate matching. Controls are eligible if unvaccinated and event-free at that time. Vaccinated individuals may appear as a control (when they are not yet vaccinated) and as a case.

Examples

matched_cohort <- match_rolling_cohort(
data = simdata,
outcome_time =  "Y",
exposure = "V",
exposure_time = "D_obs",
matching_vars = c("x1", "x2"),
id_name = "ID",
seed = 5678
)