compute_km_weights_controls: Compute Kaplan-Meier type weights for newly collected NCC...

View source: R/km_type_weights.R

compute_km_weights_controlsR Documentation

Compute Kaplan-Meier type weights for newly collected NCC controls

Description

Compute Kaplan-Meier type weights for newly collected NCC controls

Usage

compute_km_weights_controls(
  ncc_controls,
  risk_table_manual,
  t_start_name = NULL,
  t_name,
  match_var_names = NULL,
  n_per_case,
  km_names = c("km_prob", "km_weight")
)

Arguments

ncc_controls

Newly collected NCC controls, where each row corresponds to a unique subject. Make sure this dataset does not include any subject that later became cases. This data should include the actual event/censoring time of each subject. A data.frame or a matrix with column names.

risk_table_manual

Number of subjects at risk at time of each cases in the NCC, prepared using function match_risk_table.

t_start_name

Name of the variable in ncc_controls for the start time of follow-up. A string. Default is NULL, i.e., every subject started the follow-up at time 0.

t_name

Name of the variable in ncc_controls for the time of censoring (coarsening not yet supported). A string.

match_var_names

Name(s) of the match variable(s) in ncc_controls used when drawing the NCC. A string vector. Default is NULL, i.e., the NCC was only time-matched. The corresponding column in risk_table_manual must have the same name.

n_per_case

Number of controls matched to each case.

km_names

Column names for the KM-type probability (the first element) and weight (the second element) computed. Default is c("km_prob", "km_weight").

See Also

match_risk_table, compute_km_weights

Examples

library(SamplingDesignTools)
# Load mini cohort
data("mini_cohort")
mini_cohort
# For illustrative purpose, assume subjects 5, 7 and 10 are newly collected
# controls, so that the resulting Kaplan-Meier type weights are identical to
# examples for compute_km_weights():
ncc_controls <- mini_cohort[c(5, 7, 10), c("id", "t")]
ncc_controls
# To use these newly sampled controls with existing cases, we need to have the 
# number of subjects at risk at event times in mini_cohort:
risk_table <- compute_risk_table(cohort = mini_cohort, t_name = "t", 
                                 y_name = "status")
# The following command computes the Kaplan-Meier type weights for the newly
# sampled controls:
ncc_controls <- compute_km_weights_controls(
  ncc_controls = ncc_controls, risk_table_manual = risk_table, 
  t_name = "t", n_per_case = 1
)
ncc_controls

nyilin/SamplingDesignTools documentation built on Nov. 20, 2022, 8:07 a.m.