getFit: Fit logit model using cross-validation

Description Usage Arguments Details Examples

Description

Fit logit model using cross-validation

Usage

1
2
3
getFit(formula, trainData, index, metric = c("prAUC", "rocAUC"), cv = TRUE,
  lasso = F, llength = NULL, lmax = NULL, seed, lambda = NULL,
  verbose = TRUE)

Arguments

formula

char or formula object

trainData

dataframe, rows are samples to be classified, columns are features including sample ids

index

list of ints, each element is an array, see index

metric

char, see aucs

lasso

logical, whether to use lasso regularization

llength

num, number of lambdas to consider up to lmax

lmax

num, maximum lambda to consider, cannot be NULL if lambda is NULL

seed

int, seed for split

lambda

num, consider one lambda, lmax should be NULL if this has a value

verbose
folds

int, number of folds for cross-validation

Details

Trains logits using glmnet and caret

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# use training partition to create folds for CV
data("features_ratechange_sup0.4g60l2z2") # features and labels for each clinical visit
t <- 'rate'
maxgap <- 60
maxlen <- 2

# format
names <- colnames(feats)
feats <- data.frame(id=row.names(feats),feats)
colnames(feats) <- c('id',names)
feats <- prepLaterality(feats)
feats <- prepLocation(feats)
feats <- removeVisits(feats,
                     maxgap=maxgap,
                     maxlength=maxlen,
                     tType=t,
                     save=F,
                     outDir=NA)
labels <- getClassLabels()
needToRemove <- c('id','iois','eventID', # remove ids
                  labels, # remove labels
                  'IDH1') # not interested

# data partitions
train.ids <- sample(feats$id, size=floor(0.80*nrow(feats)), replace = F) # random
feats <- feats[feats$id %in% train.ids,] #training data
ind <- getTrainingFolds(trainEvents=feats,
                        folds=3,
                        seed=1,
                        verbose=T)
feats <- prepLogitData(data = feats,
                      formula = 'survivalIn60 ~ .',
                      labelName = 'survivalIn60',
                      needToRemove=needToRemove)

# logit
fit <- getFit(formula = 'survivalIn60 ~ .',
              trainData = feats,
              index = ind,
              lasso = TRUE,
              llength = 100,
              lmax = 0.2,
              metric = 'rocAUC',
              seed = 1,
              verbose = T)
              

novasmedley/gbmSpm documentation built on May 17, 2019, 10:39 a.m.