train_svhm: Train SVHM

View source: R/train_svhm.R

train_svhmR Documentation

Train SVHM

Description

Uses the Rmosek or osqp package to train the SVHM on a given training and test set. Names of the cencoring variable and event variable mus be death and futime

Usage

train_svhm(
  train,
  test,
  covariates,
  cost,
  k = 3,
  opt = "osqp",
  gamma_squared = 0.5
)

Arguments

train

training dataset

test

test dataset

covariates

vector of name of covariates

cost

cost parameter of the support vector machine of type numeric

k

integer of how many nearest event times are used to predict the event time (default is 3)

opt

which quadratic optimization is used (opt='mosek' or opt='osqp')

gamma_squared

width of gaussian kernel

Value

trained model with $e_vec vector indicating vector containing information if a subject is at risk or if an event happens. If n are the number of subjects and m the number of event times, then event_vec has length n*m, $k_mat kernel matrix, $sol calculated optimal solution, $t_predict test dataset with risk scores risk and t_predict, $p_corr pearson correlation of the predicted times $C_indes C-Index

Note

The mosek package requires a license

Examples

{

library(KMsurv)
library(SVHM)

data(bmt)
df<-bmt[1:40,]

# shuffle data
rows <- sample(nrow(df))
df <- df[rows, ]

covariates <- c('z3', 'z4')

# censoring variable and event variable need to have names "death" and "futime"
names(df)[names(df) == "d3"] <- "death"
names(df)[names(df) == "t2"] <- "futime"

n<-floor(nrow(df)/2)
train<- df[(1:n), ]
test<- df[-(1:n), ]

train_svhm(train, test, covariates, 10, .5, k=1, opt='osqp')
}

herglola/SVHM documentation built on March 24, 2022, 12:44 p.m.