survTreeLaplaceHazardRanger {discSurv} | R Documentation |
Laplace Hazards for a Competing Risk Survival Tree Object
Description
Predicts the laplace-smoothed hazards of discrete survival data based on a survival tree from class "ranger". Currently only single-risk data is supported.
Usage
survTreeLaplaceHazardRanger(treeModel, rangerdata, newdata, lambda)
Arguments
treeModel |
Fitted tree object as generated by "ranger" ("class data.frame"). Must be a single ranger tree. |
rangerdata |
Original training data with which treeModel was fitted ("class data.frame"). Must be in long format. |
newdata |
Data in long format for which hazards are to be computed ("class data.frame"). Must contain the same columns that were used for tree fitting. |
lambda |
Smoothing parameter for laplace-smoothing ("class data.frame"). Must be a non-negative number. A value of zero corresponds to no smoothing. |
Value
A m by k matrix with m being the length of newdata and k being the number of classes in treeModel. Each row corresponds to the smoothed hazard of the respective observation.
Examples
library(pec)
library(caret)
library(ranger)
data(cost)
# Take subsample and convert time to years
cost$time <- ceiling(cost$time/365)
costSubTrain <- cost[1:50,]
costSubTest <- cost[51:70,]
# Specify column names for data augmentation
timeColumn<-"time"
eventColumn<-"status"
costSubTrainLong <- dataLong(costSubTrain, timeColumn, eventColumn)
costSubTestLong <- dataLong(costSubTest, timeColumn, eventColumn)
#create tree
formula <- y ~ timeInt + diabetes + prevStroke + age + sex
rangerTree <- ranger(formula, costSubTrainLong, num.trees = 1, mtry = 5,
classification = TRUE, splitrule = "hellinger", replace = FALSE,
sample.fraction = 1, max.depth = 5)
#compute laplace-smoothed hazards
laplHaz <- survTreeLaplaceHazardRanger(rangerTree, costSubTrainLong,
costSubTestLong, lambda = 1)
laplHaz