knitr::opts_chunk$set(
  collapse = TRUE,
  fig.width = 12, fig.height=7,
  comment = "#>",
  fig.path = "man/figures/"
)

require(tidyverse,quietly=TRUE)
require(party,quietly=TRUE)
require(randomForestSRC,quietly=TRUE)
require(pec,quietly=TRUE)
require(survival,quietly=TRUE)
require(CoxBoost,quietly=TRUE)
require(obliqueRSF,quietly=TRUE)
require(ggthemes, quietly=TRUE)

nboots=5

obliqueRSF is deprecated

The aorsf package has superseded obliqueRSF. If you would like to do an analysis with oblique random survival forests, I highly recommend you use aorsf: https://github.com/bcjaeger/aorsf

Overview

Oblique random survival forest (ORSFs) are ensembles for right-censured survival data that use linear combinations of input variables to recursively partition a set of training data. Regularized Cox proportional hazard models identify optimal linear combinations of input variables in each recursive partitioning step while building survival trees.

Installation

You can install obliqueRSF from github with:

# install.packages("devtools")
devtools::install_github("bcjaeger/obliqueRSF")

Usage

The ORSF function is the center piece of the obliqueRSF package

data("pbc",package='survival')

# event is death
# censor study participants at time of last contact or transplant
pbc$status[pbc$status>=1]=pbc$status[pbc$status>=1]-1

# format categorical variables as factors
# if we don't do this, missforest will not impute 0/1 variables 
# in the way that we would like it to.
pbc = pbc %>% 
  dplyr::select(-id)%>%
  mutate(
    trt=factor(trt),
    ascites=factor(ascites),
    hepato=factor(hepato),
    spiders=factor(spiders),
    edema=factor(edema),
    stage=factor(stage,ordered=TRUE),
    time=time/365.25
  ) 

orsf <- ORSF(
  data=pbc, # data to fit trees with
  ntree=100, # number of trees to fit
  eval_times=c(1:10), # when will predictions be made?
  # note: eval_times will be used to make figures
  verbose=T,# suppresses console output
  compute_oob_predictions = TRUE # return OOB preds
) 

The vdplot function allows you to quickly look at the patterns in the predictions from an ORSF.

# Variable dependence plot (vdplot)

# Survival probabilities for a continuous variable
# note the use of sub_times, which allows you to pick
# one or more times in the evaluation times of an ORSF object

vdplot(object=orsf, xvar='bili', xlab='Bilirubin levels', 
       xvar_units = 'mg/dl', sub_times = 5)

here is another application of vdplot with a continuous x-variable, but this time we will show predictions at three times: 1 year, 3 years, and 5 years since baseline.

vdplot(object=orsf, xvar='albumin', xlab='Serum albumin', 
       xvar_units = 'g/dl', sub_times = c(1,3,5))

The vdplot function also supports categorical x-variables. Setting the x-variable to sex, and the facet variable to hepato, we find a clear interaction between sex and the presence of an enlarged liver (i.e., hepato=1).

vdplot(object=orsf, xvar='sex', xlab=c("Sex"), xlvls=c("Male","Female"),
       fvar='hepato',flab=c("Normal size liver","Enlarged liver"))

Is this interaction something that is purely explained by sex, or is it a confounding effect from other variables that are not the same between the two sexes? We can address this using the partial dependence plot (pdplot) function:

pdplot(object=orsf, xvar='sex',xlab='Sex', xlvls=c("Male","Female"),
       fvar='hepato',flvls=c("Normal size liver","Enlarged liver"),
       sub_times=c(1,3,5,7,9))

Taking into account the effects of other variables in the data, the interaction between sex and hepato is attenuated.



bcjaeger/obliqueRSF documentation built on Sept. 5, 2022, 3:07 a.m.