| loglik_cox | R Documentation |
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.
loglik_cox(eta, status, y = NULL, weights = 1)
eta |
Numeric vector of linear predictors |
status |
Integer/logical vector of event indicators (1 = event,
0 = censored), same length and order as |
y |
Optional numeric vector of observed event/censor times, same length
and order as |
weights |
Optional numeric vector of observation weights (default 1). |
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.
Scalar partial log-likelihood value.
set.seed(1234)
eta <- rnorm(50)
status <- rbinom(50, 1, 0.6)
y <- rexp(50)
loglik_cox(eta, status, y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.