Coxnet fits a Cox model regularized with net, elastic-net or lasso penalty, and their adaptive forms, such as adaptive lasso and net adjusting for signs of linked coefficients.
Moreover, it treats the number of non-zero coefficients as another tuning parameter and simultaneously selects with the regularization parameter lambda.
loCoxnet fits a varying coefficient Cox model by kernel smoothing, incorporated with the aforementioned penalties.
The package uses one-step coordinate descent algorithm and runs extremely fast by taking into account the sparsity structure of coefficients.Coxnet(x, y, Omega = NULL, penalty = c("Lasso", "Enet", "Net"),
alpha = 1, lambda = NULL, nlambda = 50, rlambda = NULL, nfolds = 1, foldid = NULL,
inzero = TRUE, adaptive = c(FALSE, TRUE), aini = NULL, isd = FALSE,
ifast = TRUE, keep.beta = FALSE, thresh = 1e-6, maxit = 1e+5)
loCoxnet(x, y, w, w0 = NULL, h = NULL, hnext = NULL, Omega = NULL,
penalty = c("Lasso", "Enet", "Net"), alpha = 1, lambda = NULL,
nlambda = 50, rlambda = NULL, nfolds = 1, foldid = NULL,
adaptive = c(FALSE, TRUE), aini = NULL, isd = FALSE, keep.beta = FALSE,
thresh = 1e-6, thresh2 = 1e-10, maxit = 1e+5)y should be a two-column matrix with columns named `time' and `status'. The latter is a binary variable, with `1' indicating event, and `0' indicating right censored.y. The coefficients vary with w.w0. If w0 = NULL, w0 is generated as 10 equally spaced points in the range of w.h. Default is 0.01.penalty = "Net" to calculate Laplacian matrix."Net", "Enet" and "Lasso". For "Net", need to specify Omega; otherwises, "Enet" is performed."Net", or between L1 and L2 for "Enet". Can be zero and one. For penalty = "Net", the penalty is defined as $$\lambda*{\alpha*||\beta||_1+(1-\alpha)/2*(\beta^{T}L\beta)},$$
where $lambda = NULL, a sequency of lambda is generated based on nlambda and rlambda. Supplying a value of lambda overrides this.lambda values. Default is 50.lambda.max to determine the smallest value for lambda. The default is rlambda = 0.0001 when the number of observations is larger than or equal to the number of variables; otherwise, rlambda = 0.01nfolds = 1 and foldid = NULL and cross-validation is not performed. For cross-validation, smallest value allowable is nfolds = 3. Specifying foldid overrisdes this.nfolds specifying which fold each observation is in.lambda. Default is inzero = TRUE.adaptive = c(FALSE, TRUE). The first element is for adaptive on $\beta$ in L1 and the second for adjusting for signs of linked coefficients in Laplacian matrix.wbeta for adaptive L1 and sgn for adjusting Laplacian matrix. wbeta is the absolute value of inverse initial estimates. If aini = NULL x is always standardized prior to fitting the model. Default is isd = FALSE, returning $\beta$ on the original scale.ifast = TRUE.lambda values. For keep.beta = FALSE, only return the estimate with the largest cross-validation partial likelihood.1E-6.lambda value for local methods. The algorithm computes along a sequence of lambda value until any absolute value of the second derivative is smaller than thresh2. The estimates are r10^5.Coxnet outputs an object with S3 class "Coxnet".inzero = TRUE.lambda and the number of non-zero coefficients nzero. For cross-validation, additional results are reported, such as average cross-validation partial likelihood cvm and its standard error cvse, and index with max indicating the largest cvm.lambda, cvm and nzero based on inzero = TRUE.lambda that gives maximum cvm.lambda based on inzero = TRUE.cvm with length of number of non-zero components of Beta0. The kth value of cv.nzero corresponds to retaining the k largest non-zero coefficients (absolute values) in Beta0. The optimal number of non-zero is selected by the maximum value of cv.nzero at lambda = lambda.opt.flag = 0 means converged.loCoxnet outputs an object with S3 class "Coxnet" and "loCoxnet".lambda. If there are more than one w0 value, each element of the list is a matrix with p rows and the number of columns is the length of w0. If there is one w0, Beta is a matrix rather than a list, with p rows and nlambda columns.lambda and the number of non-zero coefficients nzero. For cross-validation, additional results are reported, such as average cross-validation partial likelihood cvm and its standard error cvse, and index with max indicating the largest cvm.lambda that gives maximum cvm.cvm and cvse.flag = 0 means converged.lambda. ifast = TRUE adopts an efficient way to update risk set and sometimes the algorithm ends before all nlambda values of lambda have been evaluated. To evaluate small values of lambda, use ifast = FALSE. The two methods only affect the efficiency of algorithm, not the estimates.
Cross-validation partial likelihood is used for tuning parameters. For inzero = TRUE, we further select the number of non-zero coefficients obtained from regularized Cox model at each lambda. This is motivated by formulating L0 variable selection in ADMM form.
For vayring coefficients methods, the bandwidth is selected by cross-validation. We recommend to check whether a small increase of h, say h+hnext, will improve the current cvm.print.Coxnet, coxsplitset.seed(1213)
N=100;p=30;p1=5
x=matrix(rnorm(N*p),N,p)
beta=rnorm(p1)
xb=x[,1:p1]ty=rexp(N,exp(xb))
tcens=rbinom(n=N,prob=.3,size=1) # censoring indicator
y=cbind(time=ty,status=1-tcens)
fiti=Coxnet(x,y,penalty="Lasso",nlambda=10,nfolds=10) # Lasso
# attributes(fiti)Run the code above in your browser using DataLab