Compute the deviance (-2 log partial likelihood) for Cox model. This is a pared down version of `glmnet`'s `coxnet.deviance` with one big difference: here, `pred` is on the scale of `y` (`mu`) while in `glmnet`, `pred` is the linear predictor (`eta`).

coxnet.deviance(pred = NULL, y, weights = NULL, std.weights = TRUE)

Arguments

pred

Fit vector or matrix. If `NULL`, it is set to all ones.

y

Survival response variable, must be a Surv or stratifySurv object.

weights

Observation weights (default is all equal to 1).

std.weights

If TRUE (default), observation weights are standardized to sum to 1.

Value

A vector of deviances, one for each column of predictions.

Details

Computes the deviance for a single set of predictions, or for a matrix of predictions. Uses the Breslow approach to ties.

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.

Examples

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 = exp(eta), y = y)
#> [1] 23.53084
# if pred not provided, it is set to ones vector coxnet.deviance(y = y)
#> [1] 24.66365
# example with (start, stop] data y2 <- survival::Surv(time, time + runif(10), d) coxnet.deviance(pred = exp(eta), y = y2)
#> [1] 7.436026