# NOT RUN {
library(mlr3)
library(mlr3pipelines)
# these methods are generally only successful if censoring is not too high
# create survival task by undersampling
set.seed(1)
task = tsk("rats")$filter(
c(which(tsk("rats")$truth()[,2]==1),
sample(which(tsk("rats")$truth()[,2]==0), 42))
)
# deletion
po = po("trafotask_survregr", method = "delete")
po$train(list(task, NULL))[[1]] # 42 deleted
# omission
po = po("trafotask_survregr", method = "omit")
po$train(list(task, NULL))[[1]]
# ipcw with Akritas
po = po("trafotask_survregr", method = "ipcw", estimator = "akritas", lambda = 0.4, alpha = 0)
new_task = po$train(list(task, NULL))[[1]]
print(new_task)
new_task$weights
# mrl with Kaplan-Meier
po = po("trafotask_survregr", method = "mrl")
new_task = po$train(list(task, NULL))[[1]]
data.frame(new = new_task$truth(), old = task$truth())
# Buckley-James imputation
po = po("trafotask_survregr", method = "bj")
new_task = po$train(list(task, NULL))[[1]]
data.frame(new = new_task$truth(), old = task$truth())
# reorder - in practice this will be only be used in a few graphs
po = po("trafotask_survregr", method = "reorder", features = c("sex", "rx", "time", "status"),
target = "litter")
new_task = po$train(list(task, NULL))[[1]]
print(new_task)
# reorder using another task for feature names
po = po("trafotask_survregr", method = "reorder", target = "litter")
new_task = po$train(list(task, task))[[1]]
print(new_task)
# }
Run the code above in your browser using DataLab