tfCox: Fit the additive trend filtering Cox model with a range of...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/Rfunctions.R

Description

Fit additive trend filtering Cox model where each component function is estimated to be piecewise constant or polynomial.

Usage

1
2
tfCox(dat, ord=0, alpha=1, lambda.seq=NULL, discrete=NULL, n.lambda=30,
lambda.min.ratio = 0.01, tol=1e-6, niter=1000, stepSize=25, backtracking=0)

Arguments

dat

A list that contains time, status and X. time is failure or censoring time, status is failure indicator with 1 indicating failure and 0 indicating censoring, and X is n x p design matrix and may have p > n. Missing data are not allowed in time, status and X. X should be numeric.

ord

The polynomial order of the trend filtering fit; a non-negative interger (ord>= 3 is not recommended). For instance, ord=0 will produce piewise constant fit, ord=1 will produce piewise linear fit, and ord=2 will produce piewise quadratic fit.

alpha

The trade-off between trend filtering penalty and group lasso penalty. It must be in [0,1]. alpha=1 corresponds to the case with only trend filtering penalty to produce piecewise polynomial, and alpha=0 corresponds to the case with only group lasso penalty to produce sparsity of the functions. alpha between 0 and 1 is the tradeoff between the strength of these two penalties. For p < n, we suggest using 1.

lambda.seq

A vector of non-negative tuning parameters. If provided, lambda.seq should be a decreasing sequence of values since tfCox uses warm starts for speed. If lambda.seq=NULL, the default will calculate lambda.seq using lambda.min.ratio and n.lambda.

discrete

A vector of covariate/feature indice that are discrete. Discrete covariates are not penalized in the model. Default NULL means that none of the covariates are discrete thus all covariates will be penalized in the model.

n.lambda

The number of lambda values to consider and the default is 30.

lambda.min.ratio

Smallest value for lambda.seq, as a fraction of the maximum lambda value, which is the smallest value such that the penalty term is zero. The default is 0.01.

tol

Convergence criterion for estimates.

niter

Maximum number of iterations.

stepSize

Initial step size. Default is 25.

backtracking

Whether backtracking should be used 1 (TRUE) or 0 (FALSE). Default is 0 (FALSE).

Details

The optimization problem has the form

l(θ)+αλ∑_{j=1}^p |D_jP_jθ_j|_1+(1-α)λ∑_{j=1}^p|θ_j|_2

where l is the loss function defined as the negative log partial likelihood divided by n, and α provides a trade-off between trend filtering penalty and group lasso penalty. Covariate matrix X is not standardized before solving the optimization problem.

Value

An object with S3 class "tfCox".

ord

the polynomial order of the trend filtering fit. Specified by user (or default).

alpha

as specified by user (or default).

lambda.seq

vector of lambda values considered.

theta.list

list of estimated theta matrices of dimension n x p. Each component in the list corresponds to the fit from lambda.seq.

num.knots

vector of number of knots of the estimated theta. Each component corresponds to the fit from lambda.seq.

num.nonsparse

vector of proportion of non-sparse/non-zero covariates/features. Each component corresponds to the fit from lambda.seq.

dat

as specified by user.

Author(s)

Jiacheng Wu

References

Jiacheng Wu & Daniela Witten (2019) Flexible and Interpretable Models for Survival Data, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2019.1592758

See Also

summary.tfCox, predict.tfCox, plot.tfCox, cv_tfCox

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
###################################################################
#constant trend filtering (fused lasso) with adaptively chosen knots
#generate data from simulation scenario 1 with piecewise constant functions
set.seed(1234)
dat = sim_dat(n=100, zerof=0, scenario=1)

#fit piecewise constant for alpha=1 and a range of lambda
fit = tfCox(dat, ord=0, alpha=1)
summary(fit)
#plot the fit of lambda index 15 and the first predictor
plot(fit, which.lambda=15, which.predictor=1)

#cross-validation to choose the tuning parameter lambda with fixed alpha=1
cv = cv_tfCox(dat, ord=0, alpha=1, n.fold=2)
summary(cv)
cv$best.lambda
#plot the cross-validation curve
plot(cv)

#fit the model with the best tuning parameter chosen by cross-validation
one.fit = tfCox(dat, ord=0, alpha=1, lambda.seq=cv$best.lambda)
#predict theta from the fitted tfCox object
theta_hat = predict(one.fit, newX=dat$X, which.lambda=1)

#plot the fitted theta_hat (line) with the true theta (dot)
for (i in 1:4) {
  ordi = order(dat$X[,i])
  plot(dat$X[ordi,i], dat$true_theta[ordi,i],
    xlab=paste("predictor",i), ylab="theta" )
  lines(dat$X[ordi,i], theta_hat[ordi,i], type="s")
}


#################################################################
#linear trend filtering with adaptively chosen knots
#generate data from simulation scenario 3 with piecewise linear functions
set.seed(1234)
dat = sim_dat(n=100, zerof=0, scenario=3)

#fit piecewise constant for alpha=1 and a range of lambda
fit = tfCox(dat, ord=1, alpha=1)
summary(fit)
#plot the fit of lambda index 15 and the first predictor
plot(fit, which.lambda=15, which.predictor=1)

#cross-validation to choose the tuning parameter lambda with fixed alpha=1
cv = cv_tfCox(dat, ord=1, alpha=1, n.fold=2)
summary(cv)
#plot the cross-validation curve
plot(cv)

#fit the model with the best tuning parameter chosen by cross-validation
one.fit = tfCox(dat, ord=1, alpha=1, lambda.seq=cv$best.lambda)
#predict theta from the fitted tfCox object
theta_hat = predict(one.fit, newX=dat$X, which.lambda=1)

#plot the fitted theta_hat (line) with the true theta (dot)
for (i in 1:4) {
  ordi = order(dat$X[,i])
  plot(dat$X[ordi,i], dat$true_theta[ordi,i],
       xlab=paste("predictor",i), ylab="theta" )
  lines(dat$X[ordi,i], theta_hat[ordi,i], type="l")
}

tfCox documentation built on Aug. 1, 2019, 5:07 p.m.