tfCox_choose_lambda {tfCox} | R Documentation |
Choose the tuning parameter lambda using training and testing dataset
Description
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).
Usage
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)
Arguments
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). |
Value
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. |
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
predict_best_lambda
, negloglik
Examples
#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)