survTreeLaplaceHazard: Laplace Hazards for a Competing Risk Survival Tree Object

View source: R/survTreeLaplaceHazards.R

survTreeLaplaceHazardR Documentation

Laplace Hazards for a Competing Risk Survival Tree Object

Description

Predicts the laplace-smoothed hazards of discrete survival tree. Can be used for single-risk or competing risk discrete survival data.

Usage

survTreeLaplaceHazard(treeModel, newdata, lambda)

Arguments

treeModel

Fitted tree object as generated by "rpart" ("class rpart").

newdata

Data in long format for which hazards are to be computed. Must contain the same columns that were used for tree fitting("class data.frame").

lambda

Smoothing parameter for laplace-smoothing. Must be a non-negative number. A value of 0 corresponds to no smoothing ("numeric vector").

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)
# Example data
data(cost)
# Convert time to years and select training and testing subsample
cost$time <- ceiling(cost$time/365)
costTrain <- cost[1:100, ]
costTest  <- cost[101:120, ]
# Convert to long format
timeColumn <- "time"
eventColumn <- "status"
costTrainLong <- dataLong(dataShort=costTrain, timeColumn = "time", 
                          eventColumn = "status")
costTestLong  <- dataLong(dataShort=costTest, timeColumn = "time", 
                          eventColumn = "status")
head(costTrainLong)
# Fit a survival tree
costTree <- rpart(formula = y ~ timeInt + prevStroke + age + sex, data = costTrainLong, 
                  method = "class")
# Compute smoothed hazards for test data
predictedhazards <- survTreeLaplaceHazard(costTree, costTestLong, 1)
predictedhazards

discSurv documentation built on March 18, 2022, 7:12 p.m.