Skip to contents

create_time_varying_data Converts events and cohort data into a time-varying dataset, where each row represents a time interval per patient and columns indicate which treatments are active during that interval.

Usage

create_time_varying_data(
  events,
  med_names_list,
  index_var = "index_date",
  tx_name = "tx_name",
  tx_start = "tx_start",
  tx_stop = "tx_stop",
  id_var = "patient_id",
  stages = NULL,
  on_med_tx_end = FALSE,
  med_levels = NULL
)

Arguments

events

A long format tibble with patient id, index date, state (i.e. treatment/medication), and start/stop columns. Its purpose is to provide event data for each id to the Sankey package, so that nsSank can determine what state(s) each id is in at each time point.

med_names_list

A character vector specifying which medications from the tx_name column to include in the analysis. Any medication not in this vector will be ignored.

index_var

A string specifying the column name in events holding patients' index dates (default value: "index_date")

tx_name

A string specifying the column name in events holding treatment names (default value: "tx_name")

tx_start

A string specifying the column name in events with treatment start dates (default value: "tx_start")

tx_stop

A string specifying the column name in events with treatment stop dates (default value: "tx_stop")

id_var

A string specifying the column name in events holding patient IDs (default value: "patient_id")

stages

A numeric vector specifying time points (days from index date) at which to evaluate medication status. If NULL (default value), time points are automatically determined from treatment start/stop dates in the data. Example: c(0, 45, 90) checks medication status at baseline, day 45, and day 90.

on_med_tx_end

A logical value indicating whether a patient is considered on treatment on their tx_stop date. If TRUE, tx_stop is the last day ON treatment (inclusive); if FALSE, tx_stop is the first day OFF treatment (exclusive). (Default value: FALSE)

med_levels

A named list of character vectors specifying levels for leveled medications or treatments (e.g., med_levels = list(statin = c("low_intensity_statin", "moderate_intensity_statin", "high_intensity_statin"))). Any medication name listed here (e.g. statin) must be present in med_names_list. Medications not listed here but present in med_names_list are treated as binary (on/off).

Value

A tibble where each row represents a time interval per patient and columns indicate which treatments are active during that interval. More specifically, the time interval is depicted as start and stop columns, and the treatment indicator columns inform if a patient is on treatment during the interval [start, stop).