% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cox_helpers.R
\name{loglik_cox}
\alias{loglik_cox}
\title{Compute Cox Partial Log-Likelihood}
\usage{
loglik_cox(eta, status, y = NULL, weights = 1)
}
\arguments{
\item{eta}{Numeric vector of linear predictors \eqn{\mathbf{X}\boldsymbol{\beta}},
length N, sorted by ascending event time.}

\item{status}{Integer/logical vector of event indicators (1 = event,
0 = censored), same length and order as \code{eta}.}

\item{y}{Optional numeric vector of observed event/censor times, same length
and order as \code{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).}

\item{weights}{Optional numeric vector of observation weights (default 1).}
}
\value{
Scalar partial log-likelihood value.
}
\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.
}
\details{
The partial log-likelihood (Breslow) is
\deqn{\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 \eqn{D_g} is the event set at tied event time \eqn{t_g},
\eqn{R_g = \{j : t_j \ge t_g\}} is the corresponding risk set, and
\eqn{d_g^{(w)} = \sum_{i \in D_g} w_i}.
}
\examples{
set.seed(1234)
eta <- rnorm(50)
status <- rbinom(50, 1, 0.6)
y <- rexp(50)
loglik_cox(eta, status, y)

}
