Skip to contents

Computes two empirical probability distributions used to marginalize time- and covariate- specific cumulative incidences:

  • \(g(d \mid x)\): the distribution of exposure eval_times within each covariate subgroup of exposed individuals who remain at risk tau days after exposure.

  • \(p(x)\): the distribution of covariates among exposed individuals who remain at risk tau days after exposure.

Called internally by nomatchVE(). Provided as an example of the structure needed if a user passes in custom_weights.

Usage

get_observed_weights(
  data,
  outcome_time,
  exposure,
  exposure_time,
  covariates,
  tau
)

Arguments

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.

covariates

Character vector of covariates to adjust for when fitting the hazard models. These covariates should include all known confounders of exposure and censoring measured at the chosen time origin.

tau

Numeric. Only vaccinated who are at-risk tau days after vaccination are included.

Value

A list with two data frames:

  • g_weights: covariate-conditional exposure time probabilities (\(g(d \mid x)\))

  • p_weights: covariate probabilities (\(p(x)\))

    Each data frame includes all variables in covariates, and a prob column with empirical probabilities. g_weights additionally includes a <exposure_time> column for exposure eval_times.

Examples

weights <- get_observed_weights(simdata, "Y", "V", "D_obs",
                                   c("x1", "x2"), tau = 14)
str(weights)
#> List of 2
#>  $ g_weights:'data.frame':	1010 obs. of  4 variables:
#>   ..$ x1   : int [1:1010] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ x2   : int [1:1010] 5 5 5 5 5 5 5 5 5 5 ...
#>   ..$ D_obs: num [1:1010] 2 3 4 5 6 7 8 9 10 11 ...
#>   ..$ prob : num [1:1010] 0.0256 0.022 0.011 0.0586 0.0183 ...
#>  $ p_weights:'data.frame':	14 obs. of  3 variables:
#>   ..$ x1  : int [1:14] 0 0 0 0 0 0 0 1 1 1 ...
#>   ..$ x2  : int [1:14] 5 6 7 8 9 10 11 5 6 7 ...
#>   ..$ prob: num [1:14] 0.0675 0.0672 0.0705 0.064 0.0796 ...