coxnet.deviance.RdCompute the deviance (-2 log partial likelihood) for Cox model.
coxnet.deviance(
pred = NULL,
y,
x = NULL,
offset = NULL,
weights = NULL,
std.weights = TRUE,
beta = NULL
)Fit vector or matrix (usually from glmnet at a particular lambda or a sequence of lambdas).
Survival response variable, must be a Surv or
stratifySurv object.
Optional x matrix, to be supplied if pred = NULL.
Optional offset vector.
Observation weights (default is all equal to 1).
If TRUE (default), observation weights are standardized to sum to 1.
Optional coefficient vector/matrix, to be supplied if
pred = NULL.
A vector of deviances, one for each column of predictions.
Computes the deviance for a single set of predictions, or for a matrix
of predictions. The user can either supply the predictions
directly through the pred option, or by supplying the x matrix
and beta coefficients. Uses the Breslow approach to ties.
The function first checks if pred is passed: if so, it is used as
the predictions. If pred is not passed but x and beta
are passed, then these values are used to compute the predictions. If
neither x nor beta are passed, then the predictions are all
taken to be 0.
coxnet.deviance() is a wrapper: it calls the appropriate internal
routine based on whether the response is right-censored data or
(start, stop] survival data.
coxgrad
set.seed(1)
eta <- rnorm(10)
time <- runif(10, min = 1, max = 10)
d <- ifelse(rnorm(10) > 0, 1, 0)
y <- survival::Surv(time, d)
coxnet.deviance(pred = eta, y = y)
#> [1] 23.53084
# if pred not provided, it is set to zero vector
coxnet.deviance(y = y)
#> [1] 24.66365
# example with x and beta
x <- matrix(rnorm(10 * 3), nrow = 10)
beta <- matrix(1:3, ncol = 1)
coxnet.deviance(y = y, x = x, beta = beta)
#> [1] 27.84795
# example with (start, stop] data
y2 <- survival::Surv(time, time + runif(10), d)
coxnet.deviance(pred = eta, y = y2)
#> [1] 5.859333
# example with strata
y2 <- stratifySurv(y, rep(1:2, length.out = 10))
coxnet.deviance(pred = eta, y = y2)
#> [1] 13.05457