
Prediction Object for Survival
PredictionSurv.Rd
This object stores the predictions returned by a learner of class LearnerSurv.
The task_type
is set to "surv"
.
For accessing survival and hazard functions, as well as other complex methods from a PredictionSurv object, see public methods of survDistr and example below.
Super class
mlr3::Prediction
-> PredictionSurv
Active bindings
truth
(
Surv
)
True (observed) outcome.crank
(
numeric()
)
Access the stored predicted continuous ranking.distr
(survdistr::survDistr)
Returns the stored survival predictions as a survDistr distribution object. ThesurvDistr
API provides methods to transform survival data into other quantities such as cumulative hazard, hazard, probability density, and cumulative distribution functions.lp
(
numeric()
)
Access the stored predicted linear predictor.response
(
numeric()
)
Access the stored predicted survival time.
Methods
Method new()
Creates a new instance of this R6 class.
Usage
PredictionSurv$new(
task = NULL,
row_ids = task$row_ids,
truth = task$truth(),
crank = NULL,
distr = NULL,
lp = NULL,
response = NULL,
check = TRUE,
data_type = "surv",
interp_meth = "const_surv"
)
Arguments
task
(TaskSurv)
Task, used to extract defaults forrow_ids
andtruth
.row_ids
(
integer()
)
Row ids of the predicted observations, i.e. the row ids of the test set.truth
(
survival::Surv()
)
True (observed) response.crank
(
numeric()
)
Numeric vector of predicted continuous rankings (or relative risks). One element for each observation in the test set. For a pair of continuous ranks, a higher rank indicates that the observation is more likely to experience the event.distr
(
matrix()
)
A matrix of predicted survival probabilities, where rows = observations and columns correspond to time points.lp
(
numeric()
)
Numeric vector of linear predictor scores. One element for each observation in the test set. \(lp = X\beta\) where \(X\) is a matrix of covariates and \(\beta\) is a vector of estimated coefficients.response
(
numeric()
)
Numeric vector of predicted survival times. One element for each observation in the test set.check
(
logical(1)
)
IfTRUE
, performs argument checks and predict type conversions.data_type
(
character(1)
)
Type of data (e.g. survival or hazard) stored indistr
.interp_meth
(
character(1)
)
Type of interpolation used in subsequent methods of thesurvDistr
object.
Examples
library(mlr3)
task = tsk("lung")
learner = lrn("surv.kaplan")
part = partition(task)
p = learner$train(task, part$train)$predict(task, part$test)
head(as.data.table(p))
#> row_ids time status crank distr
#> <int> <num> <lgcl> <num> <list>
#> 1: 15 371 TRUE 81.78041 <list[1]>
#> 2: 16 520 TRUE 81.78041 <list[1]>
#> 3: 18 118 TRUE 81.78041 <list[1]>
#> 4: 20 12 TRUE 81.78041 <list[1]>
#> 5: 29 460 TRUE 81.78041 <list[1]>
#> 6: 30 153 TRUE 81.78041 <list[1]>
p$distr # survDistr
#> A [55 x 107] survival matrix
#> Number of observations: 55
#> Number of time points: 107
#> Interpolation method: Piece-wise Constant Survival
# survival probabilities of the 4 test observations at two time points
p$distr$survival(times = c(80, 100))[1:4, ]
#> 80 100
#> [1,] 0.9026549 0.8584071
#> [2,] 0.9026549 0.8584071
#> [3,] 0.9026549 0.8584071
#> [4,] 0.9026549 0.8584071