Title: | Fits Piecewise Polynomial with Data-Adaptive Knots in Cox Model |
---|---|
Description: | In Cox's proportional hazard model, covariates are modeled as linear function and may not be flexible. This package implements additive trend filtering Cox proportional hazards model as proposed in Jiacheng Wu & Daniela Witten (2019) "Flexible and Interpretable Models for Survival Data", Journal of Computational and Graphical Statistics, <DOI:10.1080/10618600.2019.1592758>. The fitted functions are piecewise polynomial with adaptively chosen knots. |
Authors: | Jiacheng Wu [aut, cre], Daniela Witten [aut], Taylor Arnold [ctb], Veeranjaneyulu Sadhanala [ctb], Ryan Tibshirani [ctb] |
Maintainer: | Jiacheng Wu <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.0 |
Built: | 2025-02-27 03:00:05 UTC |
Source: | https://github.com/cran/tfCox |
This package is called tfCox or trend filtering for Cox model, which is proposed in Jiacheng Wu & Daniela Witten (2019) Flexible and Interpretable Models for Survival Data, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2019.1592758. It provides an approach to fit additive Cox model in which each component function is estimated to be piecewise polynomial with adaptively-chosen knots.
Function tfCox
fits the trend filtering Cox model for a range of tuning parameters. Function cv_tfCox
returns the optimal tuning parameter selected by K-fold cross validation.
Package: | tfCox |
Type: | Package |
Version: | 0.1.0 |
Date: | 2019-05-20 |
License: | GPL (>= 2) |
The package includes the following functions:
tfCox
, cv_tfCox
, plot.tfCox
, plot.cv_tfCox
, predict.tfCox
, summary.tfCox
, summary.cv_tfCox
, sim_dat
, plot.sim_dat
.
Jiacheng Wu Maintainer: Jiacheng Wu <[email protected]>
Jiacheng Wu & Daniela Witten (2019) Flexible and Interpretable Models for Survival Data, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2019.1592758
Fit additive trend filtering Cox model where each component function is estimated to be piecewise constant or polynomial. Tuning parameter is selected via k-fold cross-validation.
cv_tfCox(dat, ord=0, alpha=1, discrete=NULL, lambda.seq=NULL, lambda.min.ratio=0.01, n.lambda=30, n.fold=5, seed=NULL, tol=1e-6, niter=1000, stepSize=25, backtracking=0)
cv_tfCox(dat, ord=0, alpha=1, discrete=NULL, lambda.seq=NULL, lambda.min.ratio=0.01, n.lambda=30, n.fold=5, seed=NULL, tol=1e-6, niter=1000, stepSize=25, backtracking=0)
dat |
A list that contains |
ord |
The polynomial order of the trend filtering fit; a non-negative interger ( |
alpha |
The trade-off between trend filtering penalty and group lasso penalty. It must be in [0,1]. |
discrete |
A vector of covariate/feature indice that are discrete. Discrete covariates are not penalized in the model. Default |
lambda.seq |
The sequence of positive lambda values to consider. The default is |
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. |
n.lambda |
The number of lambda values to consider. Default is 30. |
n.fold |
The number of folds for cross-validation of |
seed |
An optional number used with |
tol |
Convergence criterion for estimates. |
niter |
Maximum number of iterations. |
stepSize |
Iniitial step size. Default is 25. |
backtracking |
Whether backtracking should be used 1 (TRUE) or 0 (FALSE). Default is 0 (FALSE). |
Note that cv_tfCox
does not cross-validate over alpha
, and alpha
should be provided. However, if the user would like to cross-validate over alpha
, then cv_tfCox
should be called multiple times for different values of alpha
and the same seed
. This ensures that the cross-validation folds (fold
) remain the same for the different values of alpha
. See the example below for details.
An object with S3 class "cv_tfCox".
best.lambda |
Optional lambda value chosen by cross-dalidation. |
lambda.seq |
lambda sequence considered. |
mean.cv.error |
vector of average cross validation error with the same length as |
Jiacheng Wu
Jiacheng Wu & Daniela Witten (2019) Flexible and Interpretable Models for Survival Data, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2019.1592758
summary.cv_tfCox
, plot.cv_tfCox
, tfCox
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) #fit piecewise constant functions #cross-validation to choose the tuning parameter lambda with fixed alpha=1 cv = cv_tfCox(dat, ord=0, alpha=1, n.fold=2, seed=123) plot(cv, showSE=TRUE)
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) #fit piecewise constant functions #cross-validation to choose the tuning parameter lambda with fixed alpha=1 cv = cv_tfCox(dat, ord=0, alpha=1, n.fold=2, seed=123) plot(cv, showSE=TRUE)
Calculate the negative log likelihood from Cox model from the estimated coefficient matrix theta.
negloglik(dat, theta)
negloglik(dat, theta)
dat |
A list that contains |
theta |
An n x p matrix of coefficients corresponding to covariates |
Jiacheng Wu
Jiacheng Wu & Daniela Witten (2019) Flexible and Interpretable Models for Survival Data, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2019.1592758
predict_best_lambda
, tfCox_choose_lambda
#generate training and testing data dat = sim_dat(n=100, zerof=0, scenario=1) test_dat = sim_dat(n=100, zerof=0, scenario=1) #choose the optimal tuning parameter cv = tfCox_choose_lambda(dat, test_dat, ord=0, alpha=1) plot(cv$lam_seq, cv$loss) #optimal tuning parameter cv$best_lambda #predict the coefficients of testing covariates from the optimal tuning parameter #from tfCox_choose_lambda object. theta_hat = predict_best_lambda(cv, test_dat$X) #calculate the loss in the testing data based on the estimated coefficients theta negloglik(test_dat, theta_hat)
#generate training and testing data dat = sim_dat(n=100, zerof=0, scenario=1) test_dat = sim_dat(n=100, zerof=0, scenario=1) #choose the optimal tuning parameter cv = tfCox_choose_lambda(dat, test_dat, ord=0, alpha=1) plot(cv$lam_seq, cv$loss) #optimal tuning parameter cv$best_lambda #predict the coefficients of testing covariates from the optimal tuning parameter #from tfCox_choose_lambda object. theta_hat = predict_best_lambda(cv, test_dat$X) #calculate the loss in the testing data based on the estimated coefficients theta negloglik(test_dat, theta_hat)
This function plots the cross-validation curve for models fitted by a range of tuning parameter lambda using cv_tfCox
. The cross-validation error with +/-1 standard error is plotted for each value of lambda. The dotted vertical line indicates the chosen lambda corresponding to the minimum cross-validation error.
## S3 method for class 'cv_tfCox' plot(x, showSE=F, ...)
## S3 method for class 'cv_tfCox' plot(x, showSE=F, ...)
x |
an object of class "cv_tfCox" |
showSE |
a logical (TRUE or FALSE) for whether the standard errors of the curve should be plotted |
... |
additional arguments to be passed. These are ignored in this function. |
Jiacheng Wu
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) #fit piecewise constant functions #cross-validation to choose the tuning parameter lambda with fixed alpha=1 cv = cv_tfCox(dat, ord=0, alpha=1, n.fold=2, seed=123) plot(cv, showSE=TRUE)
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) #fit piecewise constant functions #cross-validation to choose the tuning parameter lambda with fixed alpha=1 cv = cv_tfCox(dat, ord=0, alpha=1, n.fold=2, seed=123) plot(cv, showSE=TRUE)
This function plots the functional form of covariate effects in four simulation scenarios.
## S3 method for class 'sim_dat' plot(x, which.predictor = NULL, n.plot = 4, ...)
## S3 method for class 'sim_dat' plot(x, which.predictor = NULL, n.plot = 4, ...)
x |
an object of class "sim_dat" |
which.predictor |
a vector of predictor index that indicates which predictor function to plot. The vector should have integer values from 1 to p where p is the number of predictors. |
n.plot |
the number of predictors to be plotted (default is 4). If |
... |
additional arguments to be passed. These are ignored in this function. |
Jiacheng Wu
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) #plot X versus the true theta plot.sim_dat(dat)
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) #plot X versus the true theta plot.sim_dat(dat)
This function plots the fitted functions from a model estimated by tfCox
.
## S3 method for class 'tfCox' plot(x, which.lambda=1, which.predictor = NULL, n.plot = 4, ...)
## S3 method for class 'tfCox' plot(x, which.lambda=1, which.predictor = NULL, n.plot = 4, ...)
x |
an object of class "tfCox" |
which.lambda |
the index for the model of interest to be plotted. |
which.predictor |
a vector of predictor index that indicates which predictor function to plot. The vector should have integer values from 1 to p where p is the number of predictors. |
n.plot |
the number of predictors to be plotted (default is 4). Note that only those non-zero estimated functions will be plotted. If |
... |
additional arguments to be passed. These are ignored in this function. |
Jiacheng Wu
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) fit = tfCox(dat, ord=0, alpha=1, lambda.seq=0.04) plot(fit, n.plot=4)
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) fit = tfCox(dat, ord=0, alpha=1, lambda.seq=0.04) plot(fit, n.plot=4)
Estimate the corresponding theta values from the optimal tuning parameter obtained by tfCox_choose_lambda
.
predict_best_lambda(cv, newX)
predict_best_lambda(cv, newX)
cv |
An object from tfCox_choose_lambda. |
newX |
The new covariate values. |
Estimated theta values.
Jiacheng Wu
Jiacheng Wu & Daniela Witten (2019) Flexible and Interpretable Models for Survival Data, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2019.1592758
tfCox_choose_lambda
, negloglik
#generate training and testing data dat = sim_dat(n=100, zerof=0, scenario=1) test_dat = sim_dat(n=100, zerof=0, scenario=1) #choose the optimal tuning parameter cv = tfCox_choose_lambda(dat, test_dat, ord=0, alpha=1) plot(cv$lam_seq, cv$loss) #optimal tuning parameter cv$best_lambda #Estimate the theta values of testing covariates from the optimal tuning parameter #from tfCox_choose_lambda object. theta_hat = predict_best_lambda(cv, test_dat$X)
#generate training and testing data dat = sim_dat(n=100, zerof=0, scenario=1) test_dat = sim_dat(n=100, zerof=0, scenario=1) #choose the optimal tuning parameter cv = tfCox_choose_lambda(dat, test_dat, ord=0, alpha=1) plot(cv$lam_seq, cv$loss) #optimal tuning parameter cv$best_lambda #Estimate the theta values of testing covariates from the optimal tuning parameter #from tfCox_choose_lambda object. theta_hat = predict_best_lambda(cv, test_dat$X)
tfCox
This function makes predictions from a specified covariate matrix for a fit of the class "tfCox".
## S3 method for class 'tfCox' predict(object, newX, which.lambda=1, ...)
## S3 method for class 'tfCox' predict(object, newX, which.lambda=1, ...)
object |
an object of the class "tfCox" |
newX |
a n x p covariate matrix |
which.lambda |
the index for the model of interest to be plotted. |
... |
additional arguments to be passed. These are ignored in this function. |
Prediction for the new data point is implemented by constant or linear interpolation. 0th order trend filtering will have constant interpolation, and 1th or higher order trend filtering will have linear interpolation.
A n x p matrix containing the fitted theta values.
Jiacheng Wu
This function generates survival data according to the simulation scenarios considered in Section 4 of Wu, J., and Witten, D. (2019) Flexible and interpretable models for survival data. Cox model has the form
. Failure time is generated by Weibull distribution with baseline hazard
. In the paper, however, failure time is generated by a simplied weibull distribution: exponential(1) baseline hazard corresponding to shape=1
and scale=1
. Censoring time is generated independently by exponential distribution with intensity censoring.rate
. Thus the observed time is the minimum of failure time and censoring time. Each scenario has four covariates that have some non-linear association with the outcome. There is the option to also generate a user-specified number of covariates that have no association with the outcome.
sim_dat(n, zerof=0, scenario=1, scale=1, shape=1, censoring.rate=0.01, n.discrete=0)
sim_dat(n, zerof=0, scenario=1, scale=1, shape=1, censoring.rate=0.01, n.discrete=0)
n |
number of observations. |
scenario |
Simulation scenario. Options are 1, 2, 3, 4. Scenario 1 corresponds to piecewise constant functions, scenario 2 corresponds to smooth functions, scenario 3 corresponds to piecewise linear functions, and scenario 4 corresponds to functions that have varying degrees of smoothness. Each scenario has four covariates that have some non-linear association with the outcome. |
zerof |
Number of additional covariates that have no association with the outcome. The total number of covariates is |
scale |
scale parameter as in |
shape |
shape parameter as in |
censoring.rate |
censoring intensity. Censoring time is generated by exponential distribution with intensity |
n.discrete |
The number of binary covariates and default is zero binary covariate. |
time |
failure or censoring time whichever comes first. |
status |
censoring indicator. 1 denotes censoring and 0 denotes failure. |
X |
n x p covariate matrix. |
true_theta |
n x p matrix. |
Jiacheng Wu
Jiacheng Wu & Daniela Witten (2019) Flexible and Interpretable Models for Survival Data, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2019.1592758
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) #plot X versus the true theta plot.sim_dat(dat)
#generate data set.seed(123) dat = sim_dat(n=100, zerof=0, scenario=1) #plot X versus the true theta plot.sim_dat(dat)
cv_tfCox
object
This function summarizes cv_tfCox
object and identifies the tuning parameter chosen by cross-validation.
## S3 method for class 'cv_tfCox' summary(object, ...)
## S3 method for class 'cv_tfCox' summary(object, ...)
object |
an object of class "cv_tfCox" |
... |
additional arguments to be passed. These are ignored in this function. |
Jiacheng Wu
#generate data set.seed(1234) dat = sim_dat(n=100, zerof=0, scenario=1) #cross-validation to choose the tuning parameter lambda with fixed alpha=1 cv = cv_tfCox(dat, ord=0, alpha=1, n.fold=2) #summarize the cross-validation summary(cv) #plot the cross-validation curve plot(cv)
#generate data set.seed(1234) dat = sim_dat(n=100, zerof=0, scenario=1) #cross-validation to choose the tuning parameter lambda with fixed alpha=1 cv = cv_tfCox(dat, ord=0, alpha=1, n.fold=2) #summarize the cross-validation summary(cv) #plot the cross-validation curve plot(cv)
tfCox
object
This function summarizes tfCox
object
## S3 method for class 'tfCox' summary(object, ...)
## S3 method for class 'tfCox' summary(object, ...)
object |
an object of class "tfCox" |
... |
additional arguments to be passed. These are ignored in this function. |
Summarize the fit by the number of knots and percent sparsity achieved. Percent sparsity is the percentage of features estimated to have no relationship with the outcome.
Jiacheng Wu
#generate data 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) #summarize the fit by the number of knots and percent sparsity achieved. #Percent sparsity is the percentage of features estimated to have #no relationship with outcome summary(fit)
#generate data 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) #summarize the fit by the number of knots and percent sparsity achieved. #Percent sparsity is the percentage of features estimated to have #no relationship with outcome summary(fit)
Fit additive trend filtering Cox model where each component function is estimated to be piecewise constant or polynomial.
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)
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)
dat |
A list that contains |
ord |
The polynomial order of the trend filtering fit; a non-negative interger ( |
alpha |
The trade-off between trend filtering penalty and group lasso penalty. It must be in [0,1]. |
lambda.seq |
A vector of non-negative tuning parameters. If provided, |
discrete |
A vector of covariate/feature indice that are discrete. Discrete covariates are not penalized in the model. Default |
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). |
The optimization problem has the form
where 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.
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 |
num.knots |
vector of number of knots of the estimated theta. Each component corresponds to the fit from |
num.nonsparse |
vector of proportion of non-sparse/non-zero covariates/features. Each component corresponds to the fit from |
dat |
as specified by user. |
Jiacheng Wu
Jiacheng Wu & Daniela Witten (2019) Flexible and Interpretable Models for Survival Data, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2019.1592758
summary.tfCox
, predict.tfCox
, plot.tfCox
, cv_tfCox
################################################################### #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") }
################################################################### #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") }
Fit additive trend filtering Cox model where each component function is estimated to be piecewise constant or polynomial. Tuning parameter is selected via training and testing dataset described in Wu and Witten (2019). Training data is used to build the model, and testing data is used for selecting tuning parameter based on log likelihood. It is a convenience function to replicate the simulation results in Wu and Witten (2019).
tfCox_choose_lambda(dat, test_dat, ord = 0, alpha = 1, discrete = NULL, lam_seq = NULL, nlambda = 30, c = NULL, tol = 1e-06, niter=1000, stepSize=25, backtracking=0)
tfCox_choose_lambda(dat, test_dat, ord = 0, alpha = 1, discrete = NULL, lam_seq = NULL, nlambda = 30, c = NULL, tol = 1e-06, niter=1000, stepSize=25, backtracking=0)
dat |
A list that contains |
test_dat |
Same list frame as before. This is the testing data that will be used for selecting tuning parameter based on the log likelihood fit. |
ord |
The polynomial order of the trend filtering fit; a non-negative interger ( |
alpha |
The trade-off between trend filtering penalty and group lasso penalty. It must be in [0,1]. |
discrete |
A vector of covariate/feature indice that are discrete. Discrete covariates are not penalized in the model. Default |
lam_seq |
The sequence of positive lambda values to consider. The default is |
nlambda |
The number of lambda values to consider. Default is 30. |
c |
Smallest value for lam_seq, as a fraction of the maximum lambda value, which is the smallest value such that the penalty term is zero. The default is NULL. |
tol |
Convergence criterion for estimates. |
niter |
Maximum number of iterations. |
stepSize |
Iniitial step size. Default is 25. |
backtracking |
Whether backtracking should be used 1 (TRUE) or 0 (FALSE). Default is 0 (FALSE). |
lam_seq |
Lambda sequence considered. |
loss |
Loss based on the testing data with the same length as |
knots |
Number of knots from the training data with the same length as |
paramfit |
Mean square error between the estimated and true theta for the testing data. |
best_lambda |
The lambda that achieves the minimum loss for testing data. |
Jiacheng Wu
Jiacheng Wu & Daniela Witten (2019) Flexible and Interpretable Models for Survival Data, Journal of Computational and Graphical Statistics, DOI: 10.1080/10618600.2019.1592758
predict_best_lambda
, negloglik
#generate training and testing data dat = sim_dat(n=100, zerof=0, scenario=1) test_dat = sim_dat(n=100, zerof=0, scenario=1) #choose the optimal tuning parameter cv = tfCox_choose_lambda(dat, test_dat, ord=0, alpha=1) plot(cv$lam_seq, cv$loss) #optimal tuning parameter cv$best_lambda #predict the coefficients of testing covariates from the optimal tuning parameter #from tfCox_choose_lambda object. theta_hat = predict_best_lambda(cv, test_dat$X) #calculate the loss in the testing data based on the estimated coefficients theta negloglik(test_dat, theta_hat)
#generate training and testing data dat = sim_dat(n=100, zerof=0, scenario=1) test_dat = sim_dat(n=100, zerof=0, scenario=1) #choose the optimal tuning parameter cv = tfCox_choose_lambda(dat, test_dat, ord=0, alpha=1) plot(cv$lam_seq, cv$loss) #optimal tuning parameter cv$best_lambda #predict the coefficients of testing covariates from the optimal tuning parameter #from tfCox_choose_lambda object. theta_hat = predict_best_lambda(cv, test_dat$X) #calculate the loss in the testing data based on the estimated coefficients theta negloglik(test_dat, theta_hat)