loglik_cox: Compute Cox Partial Log-Likelihood

View source: R/cox_helpers.R

loglik_coxR Documentation

Compute Cox Partial Log-Likelihood

Description

Evaluates the Cox partial log-likelihood for a given coefficient vector, using the Breslow approximation for tied event times.

Observations must be sorted in ascending order of survival time before calling this function. The internal helpers handle sorting automatically; this function is exposed for diagnostics and testing.

Usage

loglik_cox(eta, status, y = NULL, weights = 1)

Arguments

eta

Numeric vector of linear predictors \mathbf{X}\boldsymbol{\beta}, length N, sorted by ascending event time.

status

Integer/logical vector of event indicators (1 = event, 0 = censored), same length and order as eta.

y

Optional numeric vector of observed event/censor times, same length and order as eta. When supplied, tied event times are handled by the Breslow approximation using a common risk-set denominator within each tied event-time block. When omitted, the function assumes there are no ties (or that ties have already been expanded appropriately).

weights

Optional numeric vector of observation weights (default 1).

Details

The partial log-likelihood (Breslow) is

\ell(\boldsymbol{\beta}) = \sum_{g} \Bigl[\sum_{i \in D_g} w_i \eta_i - d_g^{(w)} \log\Bigl(\sum_{j \in R_g} w_j \exp(\eta_j)\Bigr)\Bigr]

where D_g is the event set at tied event time t_g, R_g = \{j : t_j \ge t_g\} is the corresponding risk set, and d_g^{(w)} = \sum_{i \in D_g} w_i.

Value

Scalar partial log-likelihood value.

Examples

set.seed(1234)
eta <- rnorm(50)
status <- rbinom(50, 1, 0.6)
y <- rexp(50)
loglik_cox(eta, status, y)


lgspline documentation built on May 8, 2026, 5:07 p.m.