Generate censoring logic for scenario A

create_censoring_logics_A(
  arms,
  treatment,
  time_to_treatment,
  grace_period,
  followup,
  clone_censoring = ".censoring",
  clone_uncensored_followup = ".fup_uncensored"
)

Arguments

arms

A character vector of length 2. The first element represents a name of the untreated arm, and the second element represents a name of the treated arm.

treatment

A name of variable that represents whether each observation was treated or not in observational data. The treatment variable should exists in data frame that the return value of this function will be applied, and the treatment variable value in the data frame should be either 0 and 1, i.e. binary treatment.

time_to_treatment

A name of variable that represent time to treatment in the observational data. The time-to-treatment variable should exists in data frame that the return value of this function will be applied, and the value in the data frame should be either numeric value or NA if the observation was untreated in the observational data.

grace_period

A numeric value to represent grace period of treatment. Treatment policy is assumed to be "provide treatment within the grace period."

followup

A name of variable that represent follow up time in the observational data. The follow up time variable should exists in data frame that the return value of this function will be applied, and the follow up time variable value in the data frame should be numeric.

clone_censoring

A name of binary indicator variable to be newly created to represent whether the observation violates arm's policy or not. The new variable name should not already exist in the data frame that the return value of this function will be applied, to avoid accidental overwriting.

clone_uncensored_followup

A name of variable to be newly created to represent the earliest time that the value of the emulated censoring binary indicator (i.e. variable to be named according to clone_censoring argument) value can be determined for each observation. The new variable name should not already exist in the data frame that the return value of this function will be applied, to avoid accidental overwriting.

Value

A nested list. The first element of the outer list represents untreated arm, while the second element of the outer list represents treated arm. For each element of outer list, the first element of the inner list represents emulated censoring binary indicator (0/1) that represents whether the observation violated the arm's policy or not within the grace period, and the second. The second element of the inner list represents the earliest time that the value of the emulated censoring binary indicator can be determined for each observation. Each element of the inner list represents a sequence of logics to be passed into case_when() when creating new variables for emulated censoring indicator and censoring time.

Examples

arms <- c("Control", "Surgery")
censoring_logics <- create_censoring_logics_A(
  arms,
  treatment = "surgery",
  time_to_treatment = "timetosurgery",
  grace_period = 182.62,
  followup = "fup_obs",
  clone_censoring = "censoring",
  clone_uncensored_followup = "fup_uncensored"
)