orsf_control_custom: Custom ORSF control

View source: R/orsf_control.R

orsf_control_customR Documentation

Custom ORSF control

Description

Custom ORSF control

Usage

orsf_control_custom(beta_fun, ...)

Arguments

beta_fun

(function) a function to define coefficients used in linear combinations of predictor variables. beta_fun must accept three inputs named x_node, y_node and w_node, and should expect the following types and dimensions:

  • x_node (matrix; n rows, p columns)

  • y_node (matrix; n rows, 2 columns)

  • w_node (matrix; n rows, 1 column)

In addition, beta_fun must return a matrix with p rows and 1 column. If any of these conditions are not met, orsf_control_custom() will let you know.

...

Further arguments passed to or from other methods (not currently used).

Value

an object of class 'orsf_control', which should be used as an input for the control argument of orsf.

Examples

Two customized functions to identify linear combinations of predictors are shown here.

  • The first uses random coefficients

  • The second derives coefficients from principal component analysis.

Random coefficients

f_rando() is our function to get the random coefficients:

f_rando <- function(x_node, y_node, w_node){
 matrix(runif(ncol(x_node)), ncol=1) 
}

We can plug f_rando into orsf_control_custom(), and then pass the result into orsf():

library(aorsf)

fit_rando <- orsf(pbc_orsf,
                  Surv(time, status) ~ . - id,
                  control = orsf_control_custom(beta_fun = f_rando),
                  n_tree = 500)

fit_rando
## ---------- Oblique random survival forest
## 
##      Linear combinations: Custom user function
##           N observations: 276
##                 N events: 111
##                  N trees: 500
##       N predictors total: 17
##    N predictors per node: 5
##  Average leaves per tree: 20
## Min observations in leaf: 5
##       Min events in leaf: 1
##           OOB stat value: 0.83
##            OOB stat type: Harrell's C-statistic
##      Variable importance: anova
## 
## -----------------------------------------

Principal components

Follow the same steps as above, starting with the custom function:

f_pca <- function(x_node, y_node, w_node) { 
 
 # estimate two principal components.
 pca <- stats::prcomp(x_node, rank. = 2)
 # use the second principal component to split the node
 pca$rotation[, 2L, drop = FALSE]
 
}

Then plug the function into orsf_control_custom() and pass the result into orsf():

fit_pca <- orsf(pbc_orsf,
                Surv(time, status) ~ . - id,
                control = orsf_control_custom(beta_fun = f_pca),
                n_tree = 500)

Evaluate

How well do our two customized ORSFs do? Let’s compute their indices of prediction accuracy based on out-of-bag predictions:

library(riskRegression)
## riskRegression version 2023.09.08
library(survival)

risk_preds <- list(rando = 1 - fit_rando$pred_oobag,
                    pca = 1 - fit_pca$pred_oobag)

sc <- Score(object = risk_preds, 
            formula = Surv(time, status) ~ 1, 
            data = pbc_orsf, 
            summary = 'IPA',
            times = fit_pca$pred_horizon)

The PCA ORSF does quite well! (higher IPA is better)

sc$Brier
## 
## Results by model:
## 
##         model times  Brier  lower  upper    IPA
## 1: Null model  1788 20.479 18.090 22.868  0.000
## 2:      rando  1788 11.748  9.702 13.793 42.636
## 3:        pca  1788 12.884 10.906 14.862 37.088
## 
## Results of model comparisons:
## 
##    times model  reference delta.Brier   lower  upper            p
## 1:  1788 rando Null model      -8.731 -10.932 -6.531 7.346799e-15
## 2:  1788   pca Null model      -7.595  -9.243 -5.947 1.666843e-19
## 3:  1788   pca      rando       1.136   0.265  2.008 1.061347e-02

## 
## NOTE: Values are multiplied by 100 and given in %.

## NOTE: The lower Brier the better, the higher IPA the better.

See Also

linear combination control functions orsf_control_cph(), orsf_control_fast(), orsf_control_net()


aorsf documentation built on Oct. 26, 2023, 5:08 p.m.