Skip to contents

Flexible parametric spline learner. Calls flexsurv::flexsurvspline() from flexsurv.

Dictionary

This Learner can be instantiated via lrn():

lrn("surv.flexible")

Meta Information

  • Task type: “surv”

  • Predict Types: “crank”, “distr”, “lp”

  • Feature Types: “logical”, “integer”, “numeric”, “factor”

  • Required Packages: mlr3, mlr3proba, mlr3extralearners, flexsurv

Parameters

IdTypeDefaultLevelsRange
formulauntyped--
bhazarduntyped--
kinteger0\([0, \infty)\)
knotsuntyped--
bknotsuntyped--
scalecharacterhazardhazard, odds, normal-
timescalecharacterloglog, identity-
splinecharacterrprp, splines2ns-
rtruncuntyped--
initsuntyped--
fixedparsuntyped--
clnumeric0.95\([0, 1]\)
ancuntyped--
maxiterinteger30\((-\infty, \infty)\)
rel.tolerancenumeric1e-09\((-\infty, \infty)\)
toler.cholnumeric1e-10\((-\infty, \infty)\)
debuginteger0\([0, 1]\)
outer.maxinteger10\((-\infty, \infty)\)

Prediction types

This learner returns three prediction types:

  1. lp: a vector containing the linear predictors (relative risk scores), where each score corresponds to a specific test observation. Calculated using flexsurv::flexsurvspline() and the estimated coefficients. For fitted coefficients, \(\hat{\beta} = (\hat{\beta_0},...,\hat{\beta_P})\), and the test data covariates \(X^T = (X_0,...,X_P)^T\), where \(X_0\) is a column of \(1\)s and \(\hat{\beta_0} = \hat{\gamma_0}\), the linear predictor vector is \(lp = \hat{\beta} X^T\).

  2. distr: a survival matrix in two dimensions, where observations are represented in rows and time points in columns. Calculated using predict.flexsurvreg(type = "survival", ...).

  3. crank: same as lp.

  4. response: mean survival time calculated using predict.flexsurvreg(type = "response", ...)

Initial parameter values

  • k:

    • Actual default: 0

    • Initial value: 1

    • Reason for change: The default value of 0 is equivalent to, and a much less efficient implementation of, LearnerSurvParametric.

References

Royston, Patrick, Parmar, KB M (2002). “Flexible parametric proportional-hazards and proportional-odds models for censored survival data, with application to prognostic modelling and estimation of treatment effects.” Statistics in medicine, 21(15), 2175–2197.

See also

Author

RaphaelS1

Super classes

mlr3::Learner -> mlr3proba::LearnerSurv -> LearnerSurvFlexible

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.

Usage


Method clone()

The objects of this class are cloneable with this method.

Usage

LearnerSurvFlexible$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

library(survival)

# Define the task, split to train/test set
task = tsk("lung")
set.seed(42)
part = partition(task)

# Define the learner
learner = lrn("surv.flexible", k = 1,
  formula = Surv(time, status) ~ age + ph.karno + sex,
  anc = list(gamma1 = ~ sex))

# Train the learner on the training ids
learner$train(task, part$train)
print(learner$model)
#> Call:
#> flexsurv::flexsurvspline(formula = form, data = task$data(), 
#>     k = 1L, anc = list(gamma1 = ~sex), sr.control = list(iter.max = 30, 
#>         rel.tolerance = 1e-09, toler.chol = 1e-10, debug = 0, 
#>         maxiter = 30, outer.max = 10))
#> 
#> Estimates: 
#>               data mean  est        L95%       U95%       se         exp(est) 
#> gamma0               NA   -8.73038  -13.77364   -3.68713    2.57314         NA
#> gamma1               NA    1.15817    0.29894    2.01741    0.43839         NA
#> gamma2               NA   -0.05009   -0.11585    0.01567    0.03355         NA
#> age            63.39823    0.00878   -0.01982    0.03737    0.01459    1.00882
#> ph.karno       82.30088   -0.00192   -0.02008    0.01624    0.00926    0.99808
#> sexm            0.61947    2.30274   -1.45935    6.06482    1.91947   10.00151
#> gamma1(sexm)    0.61947   -0.29320   -0.90598    0.31957    0.31265    0.74587
#>               L95%       U95%     
#> gamma0               NA         NA
#> gamma1               NA         NA
#> gamma2               NA         NA
#> age             0.98037    1.03808
#> ph.karno        0.98012    1.01637
#> sexm            0.23239  430.44606
#> gamma1(sexm)    0.40415    1.37654
#> 
#> N = 113,  Events: 80,  Censored: 33
#> Total time at risk: 34858
#> Log-likelihood = -554.9652, df = 7
#> AIC = 1123.93
#> 

# Make predictions for the test rows
predictions = learner$predict(task, part$test)
print(predictions)
#> 
#> ── <PredictionSurv> for 55 observations: ───────────────────────────────────────
#>  row_ids time status     crank        lp response     distr
#>        7  166   TRUE -6.026908 -6.026908 338.0766 <list[1]>
#>        8  170   TRUE -6.081253 -6.081253 351.0301 <list[1]>
#>       11  707   TRUE -5.970881 -5.970881 325.1780 <list[1]>
#>      ---  ---    ---       ---       ---      ---       ---
#>      158  185  FALSE -5.995166 -5.995166 330.7130 <list[1]>
#>      160  183   TRUE -5.914491 -5.914491 312.6467 <list[1]>
#>      161  211  FALSE -8.250652 -8.250652 440.6995 <list[1]>

# Score the predictions
predictions$score()
#> surv.cindex 
#>   0.5855263