netcox_cv {netcox} | R Documentation |
cross-validation for netcox
Description
Conduct cross-validation (cv) for netcox
.
Usage
netcox_cv(
x,
ID,
time,
time2,
event,
lambda,
group,
group_variable,
penalty_weights,
par_init,
nfolds = 10,
stepsize_init = 1,
stepsize_shrink = 0.8,
tol = 1e-05,
maxit = 1000L,
verbose = FALSE
)
Arguments
x |
Predictor matrix with dimension |
ID |
The ID of each subjects, each subject has one ID (many rows in |
time |
Represents the start of each time interval. |
time2 |
Represents the stop of each time interval. |
event |
Indicator of event. |
lambda |
Sequence of regularization coefficients |
group |
|
group_variable |
|
penalty_weights |
Optional, vector of length |
par_init |
Optional, vector of initial values of the optimization algorithm. Default initial value is zero for all |
nfolds |
Optional, the folds of cross-validation. Default is 10. |
stepsize_init |
Initial value of the stepsize of the optimization algorithm. Default is 1. |
stepsize_shrink |
Factor in |
tol |
Convergence criterion. Algorithm stops when the |
maxit |
Maximum number of iterations allowed. |
verbose |
Logical, whether progress is printed. |
Details
For each lambda, 10 folds cross-validation (by default) is performed. The cv error is defined as follows. Suppose we perform K
-fold cross-validation, denote \hat{\beta}^{-k}
by the estimate obtained from the rest of K-1
folds (training set). The error of the k
-th fold (test set) is defined as 2(P-Q)
divided by R
, where P
is the log partial likelihood evaluated at \hat{\beta}^{-k}
using the entire dataset, Q is the log partial likelihood evaluated at \hat{\beta}^{-k}
using the training set, and R is the number of events in the test set. We do not use the negative log partial likelihood evaluated at \hat{\beta}^{-k}
using the test set because the former definition can efficiently use the risk set, and thus it is more stable when the number of events in each test set is small (think of leave-one-out). The cv error is used in parameter tuning. To account for balance in outcomes among the randomly formed test set, we divide the deviance 2(P-Q)
by R.
To get the estimated coefficients that has the minimum cv error, use netcox()$Estimates[netcox()$Lambdas==netcox_cv()$lambda.min]
. To apply the 1-se rule, use netcox()$Estimates[netcox()$Lambdas==netcox_cv()$lambda.1se]
.
Value
A list.
lambdas |
A vector of lambda used for each cross-validation. |
cvm |
The cv error averaged across all folds for each lambda. |
cvsd |
The standard error of the cv error for each lambda. |
cvup |
The cv error plus its standard error for each lambda. |
cvlo |
The cv error minus its standard error for each lambda. |
nzero |
The number of non-zero coefficients at each lambda. |
netcox.fit |
A netcox fit for the full data at all lambdas. |
lambda.min |
The lambda such that the |
lambda.1se |
The maximum of lambda such that the |
See Also
Examples
grp <- matrix(c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
1, 1, 0, 0, 0,
0, 0, 0, 0, 0,
0, 1, 0, 1, 0),
ncol = 5, byrow = TRUE)
grp.var <- matrix(c(1, 0, 0, 0, 0, #A1
1, 0, 0, 0, 0, #A2
0, 0, 0, 1, 0, #C1
0, 0, 0, 1, 0, #C2
0, 1, 0, 0, 0, #B
0, 0, 1, 0, 0, #A1B
0, 0, 1, 0, 0, #A2B
0, 0, 0, 0, 1, #C1B
0, 0, 0, 0, 1 #C2B
), ncol = 5, byrow = TRUE)
eta_g <- rep(1, 5)
x <- as.matrix(sim[, c("A1","A2","C1","C2","B",
"A1B","A2B","C1B","C2B")])
lam.seq <- 10^seq(0, -2, by = -0.2)
cv <- netcox_cv(x = x,
ID = sim$Id,
time = sim$Start,
time2 = sim$Stop,
event = sim$Event,
lambda = lam.seq,
group = grp,
group_variable = grp.var,
penalty_weights = eta_g,
nfolds = 5,
tol = 1e-4,
maxit = 1e3,
verbose = FALSE)