library(data.table)
library(concrete)
data <- as.data.table(survival::pbc)
data <- data[1:200, .SD, .SDcols = c("id", "time", "status", "trt", "age", "sex")]
data[, trt := sample(0:1, nrow(data), TRUE)]
# makeITT() creates a list of functions to specify intent-to-treat
# regimes for a binary, single, point treatment variable
intervention <- makeITT()
# formatArguments() returns correctly formatted arguments for doConcrete()
# If no input is provided for the Model argument, a default will be generated
concrete.args <- formatArguments(DataTable = data,
EventTime = "time",
EventType = "status",
Treatment = "trt",
ID = "id",
TargetTime = 2500,
TargetEvent = c(1, 2),
Intervention = intervention,
CVArg = list(V = 2))
# Alternatively, estimation algorithms can be provided as a named list
model <- list("trt" = c("SL.glm", "SL.glmnet"),
"0" = list(Surv(time, status == 0) ~ .),
"1" = list(Surv(time, status == 1) ~ .),
"2" = list(Surv(time, status == 2) ~ .))
concrete.args <- formatArguments(DataTable = data,
EventTime = "time",
EventType = "status",
Treatment = "trt",
ID = "id",
TargetTime = 2500,
TargetEvent = c(1, 2),
Intervention = intervention,
CVArg = list(V = 2),
Model = model)
# 'ConcreteArgs' output can be modified and passed back through formatArguments()
# examples of modifying the censoring and failure event candidate regressions
concrete.args[["Model"]][["0"]] <-
list(Surv(time, status == 0) ~ trt:sex + age)
concrete.args[["Model"]][["1"]] <-
list("mod1" = Surv(time, status == 1) ~ trt,
"mod2" = Surv(time, status == 1) ~ .)
formatArguments(concrete.args)
Run the code above in your browser using DataLab