R: Survival Task

TaskSurv {mlr3proba} | R Documentation

## Survival Task

### Description

This task specializes mlr3::Task and mlr3::TaskSupervised for possibly-censored survival problems. The target is comprised of survival times and an event indicator. Predefined tasks are stored in mlr3::mlr_tasks.

The `task_type` is set to `"surv"`.

### Super classes

`mlr3::Task` -> `mlr3::TaskSupervised` -> `TaskSurv`

### Active bindings

`censtype`

  `character(1)`
  Returns the type of censoring, one of "right", "left", "counting", "interval", or "mstate".

### Methods

#### Public methods

- `TaskSurv$new()`

- `TaskSurv$truth()`

- `TaskSurv$formula()`

- `TaskSurv$times()`

- `TaskSurv$status()`

- `TaskSurv$unique_times()`

- `TaskSurv$unique_event_times()`

- `TaskSurv$risk_set()`

- `TaskSurv$clone()`

Inherited methods

- `mlr3::Task$add_strata()`

- `mlr3::Task$cbind()`

- `mlr3::Task$data()`

- `mlr3::Task$droplevels()`

- `mlr3::Task$filter()`

- `mlr3::Task$format()`

- `mlr3::Task$head()`

- `mlr3::Task$help()`

- `mlr3::Task$levels()`

- `mlr3::Task$missings()`

- `mlr3::Task$print()`

- `mlr3::Task$rbind()`

- `mlr3::Task$rename()`

- `mlr3::Task$select()`

- `mlr3::Task$set_col_roles()`

- `mlr3::Task$set_row_roles()`

#### Method `new()`

Creates a new instance of this R6 class.

##### Usage

    TaskSurv$new(
      id,
      backend,
      time = "time",
      event = "event",
      time2,
      type = c("right", "left", "interval", "counting", "interval2", "mstate")
    )

##### Arguments

`id`

  (`character(1)`)
  Identifier for the new instance.

`backend`

  (DataBackend)
  Either a DataBackend, or any object which is convertible to a DataBackend with `as_data_backend()`. E.g., a `data.frame()` will be converted to a DataBackendDataTable.

`time`

  (`character(1)`)
  Name of the column for event time if data is right censored, otherwise starting time if interval censored.

`event`

  (`character(1)`)
  Name of the column giving the event indicator. If data is right censored then "0"/`FALSE` means alive (no event), "1"/`TRUE` means dead (event). If `type` is `"interval"` then "0" means right censored, "1" means dead (event), "2" means left censored, and "3" means interval censored. If `type` is `"interval2"` then `event` is ignored.

`time2`

  (`character(1)`)
  Name of the column for ending time for interval censored data, otherwise ignored.

`type`

  (`character(1)`)
  Name of the column giving the type of censoring. Default is 'right' censoring.

#### Method `truth()`

True response for specified `row_ids`. Format depends on the task type. Defaults to all rows with role "use".

##### Usage

    TaskSurv$truth(rows = NULL)

##### Arguments

`rows`

  `integer()`
  Row indices.

##### Returns

`numeric()`.

#### Method `formula()`

Creates a formula for survival models with survival::Surv on the LHS.

##### Usage

    TaskSurv$formula(rhs = NULL)

##### Arguments

`rhs`

  If `NULL` RHS is `.`, otherwise gives RHS of formula.

##### Returns

`numeric()`.

#### Method `times()`

Returns the (unsorted) outcome times.

##### Usage

    TaskSurv$times(rows = NULL)

##### Arguments

`rows`

  `integer()`
  Row indices.

##### Returns

`numeric()`

#### Method `status()`

Returns the event indicator (aka censoring/survival indicator). If `censtype` is `"right"` or `"left"` then `1` is event and `0` is censored. If `censtype` is `"mstate"` then `0` is censored and all other values are different events. If `censtype` is `"interval"` then `0` is right-censored, `1` is event, `2` is left-censored, `3` is interval-censored. See survival::Surv.

##### Usage

    TaskSurv$status(rows = NULL)

##### Arguments

`rows`

  `integer()`
  Row indices.

##### Returns

`integer()`

#### Method `unique_times()`

Returns the sorted unique outcome times for 'right', 'left', and 'mcstate'.

##### Usage

    TaskSurv$unique_times(rows = NULL)

##### Arguments

`rows`

  `integer()`
  Row indices.

##### Returns

`numeric()`

#### Method `unique_event_times()`

Returns the sorted unique event (or failure) outcome times.

##### Usage

    TaskSurv$unique_event_times(rows = NULL)

##### Arguments

`rows`

  `integer()`
  Row indices.

##### Returns

`numeric()`

#### Method `risk_set()`

Returns the `row_ids` of the observations 'at risk' (not dead or censored) at `time`.

##### Usage

    TaskSurv$risk_set(time = NULL)

##### Arguments

`time`

  (`numeric(1)`)
  Time to return risk set for, if `NULL` returns all `row_ids`.

##### Returns

`integer()`

#### Method `clone()`

The objects of this class are cloneable with this method.

##### Usage

    TaskSurv$clone(deep = FALSE)

##### Arguments

`deep`

  Whether to make a deep clone.

### See Also

Other Task: `TaskDens`

### Examples

    library(mlr3)
    lung = survival::lung
    lung$status = (lung$status == 2L)
    task = TaskSurv$new("lung",
      backend = lung, time = "time",
      event = "status")

    # meta data
    task$target_names
    task$feature_names
    task$formula()

    # survival data
    task$truth()
    task$times()
    task$status()
    task$unique_times()
    task$unique_event_times()
    task$risk_set(time = 700)

[Package mlr3proba version 0.4.2 Index]