prepare_risk_table: Prepare a template risk table given a nested case-control...

View source: R/km_type_weights.R

prepare_risk_tableR Documentation

Prepare a template risk table given a nested case-control sample

Description

Given a nested case-control (NCC) data, create a template for users to fill in the number of subjects at risk in the cohort at each event time within each sampling stratum (if applicable).

Usage

prepare_risk_table(
  ncc,
  t_match_name,
  y_name,
  match_var_names = NULL,
  csv_file = NULL
)

Arguments

ncc

Nested case-control data. A data.frame or a matrix with column names.

t_match_name

Name of the column of event time in each matched set in ncc. A string. Time should be recorded in a reasonable resolution of measurement (e.g., in months or years) such that the number of subjects at risk in the cohort is available.

y_name

Name of the case/control indicator in ncc, with 1 for case and 0 for control A string.

match_var_names

Name(s) of the match variable(s) used when drawing the NCC. A string vector. Default is NULL, i.e., the NCC was only time-matched.

csv_file

Name of CSV file to write the template to. If left unspecified, the template will be returned as a data.frame instead.

Value

If csv_file is not supplied, this function returns a data.frame that contains the unique event times, additional matching variables (if match_var_names is supplied), and an empty column named n.risk. Column names in this data.frame should not be modified. If csv_file is supplied, this function write the data.frame to the designated file instead. Users should fill this column with the number of subjects at risk at each time point in the stratum, and later use this data.frame or file to compute the KM-type weights for the subjects in the NCC data.

Examples

library(SamplingDesignTools)
data("ncc_2")
risk_table <- prepare_risk_table(ncc = ncc_2, t_match_name = "Time", y_name = "Fail",
                                 match_var_names = c("age_cat", "gender"))
head(risk_table)

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