Xsurv: This function can fit the survival data with different model...

View source: R/Xsurv.R

XsurvR Documentation

This function can fit the survival data with different model including xgboost,lightgbm,random forests, and gbm.

Description

This function can fit the survival data with different model including xgboost,lightgbm,random forests, and gbm.

Usage

Xsurv(
  datax,
  datay,
  top_n = NULL,
  option = c("defaut", "xgb", "lgb", "gbm", "rf"),
  method = c("defaut", "pl", "C"),
  nfolds = 5,
  nround = NULL,
  lambda = NULL,
  alpha = NULL,
  eta = NULL,
  early_stopping_rounds = NULL,
  gtree = NULL,
  ncores = NULL,
  gfrac = NULL,
  gsh = NULL,
  rfnsp = NULL,
  cp = NULL,
  maxdpth = NULL
)

Arguments

datax

X data set

datay

Y data set including time and event status

top_n

number of top features for survival tree fitting(avaliable for xgb and lgb)

option

model fitting option,defaut is xgb

method

fitting metohd,defaut is 'pl' means using loss function:coxph likelihood

nfolds

number of folds for crossvalidation

lambda

l1 penalty parameter

alpha

l2 penalty parameter

eta

learning rate

early_stopping_rounds

force a stopping round

gtree

number of trees using in gbm model

ncores

number of cores using in gbm

gfrac

bag fraction in gbm with defaut 0.5

gsh

shrinkage paramter in gbm with defaut 0.001

rfnsp

number of splits in random forests

number

of rounds

Value

a list object containing:model,cindex,tree,SHAP and risk

Examples

#example
library(survival)
library(Xsurv)
data(lung)

mydata<-(lung[,-1])
mydata[,2]<-mydata[,2]-1
length(mydata[,1])
names(mydata)<-colnames(mydata)
datay_train<-mydata[1:180,c(1,2)]
datax_train<-mydata[1:180,-c(1,2)]
datay_test<-mydata[181:228,c(1,2)]
datax_test<-mydata[181:228,-c(1,2)]
xs<-Xsurv(datax_train,datay_train,top_n = 5,cp=0.01)

#xs<-Xsurv.cv(datax_train,datay_train,top_n=5)
xm<-xs$model
xtree<-xs$tree
x_ctree<-xtree$tree2
#plot(x_ctree)
shap=xs$SHAP

shap

risk=xs$risk
fit=risk$fit

#plot(fit)
#prediction

pre_time<-pre<-Xsurv_predict(xm,datax_train,datay_train,datax_test)

#predict survival probabilty

pre_x<-Xsurv_predict_sv(xm,datax_train,datay_train,datax_test[1,])

plot(pre_x)


topycyao/Xsurv documentation built on Aug. 6, 2022, 9:06 p.m.