coxphSGD: Stochastic Gradient Descent log-likelihood Estimation in Cox...

Description Usage Arguments Details Note Author(s) Examples

View source: R/coxphSGD.R

Description

coxphSGD estimates coefficients using stochastic gradient descent algorithm in Cox proportional hazards model.

Usage

1
2
coxphSGD(formula, data, learn.rates = function(x) {     1/x },
  beta.zero = 0, epsilon = 1e-05, max.iter = 500, verbose = FALSE)

Arguments

formula

a formula object, with the response on the left of a ~ operator, and the terms on the right. The response must be a survival object as returned by the Surv function.

data

a list of batch data.frames in which to interpret the variables named in the formula. See Details.

learn.rates

a function specifing how to define learning rates in steps of the algorithm. By default the f(t)=1/t is used, where t is the number of algorithm's step.

beta.zero

a numeric vector (if of length 1 then will be replicated) of length equal to the number of variables after using formula in the model.matrix function

epsilon

a numeric value with the stop condition of the estimation algorithm.

max.iter

numeric specifing maximal number of iterations.

verbose

whether to cat the number of the iteration

Details

A data argument should be a list of data.frames, where in every batch data.frame there is the same structure and naming convention for explanatory and survival (times, censoring) variables. See Examples.

Note

If one of the conditions is fullfiled (j denotes the step number)

the estimation process is stopped.

Author(s)

Marcin Kosinski, m.p.kosinski@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(survival)
set.seed(456)
x <- matrix(sample(0:1, size = 20000, replace = TRUE), ncol = 2)
head(x)
dCox <- dataCox(10^4, lambda = 3, rho = 2, x,
                beta = c(2,2), cens.rate = 5)
batch_id <- sample(1:90, size = 10^4, replace = TRUE)
dCox_split <- split(dCox, batch_id)
results <-
  coxphSGD(formula     = Surv(time, status) ~ x.1+x.2,
           data        = dCox_split,
           epsilon     = 1e-5,
           learn.rates = function(x){1/(100*sqrt(x))},
           beta.zero   = c(0,0),
           max.iter    = 10*90)
coeff_by_iteration <-
  as.data.frame(
    do.call(
      rbind,
      results$coefficients
    )
  )
head(coeff_by_iteration)

Example output

Loading required package: survival
     [,1] [,2]
[1,]    0    0
[2,]    0    1
[3,]    1    0
[4,]    1    0
[5,]    1    1
[6,]    0    0
        x.1       x.2
1 0.0000000 0.0000000
2 0.1287670 0.1505911
3 0.2077041 0.2279745
4 0.2815383 0.2849962
5 0.3466851 0.3416297
6 0.3864788 0.4102790

coxphSGD documentation built on May 1, 2019, 6:32 p.m.

Related to coxphSGD in coxphSGD...