% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cox_helpers.R
\name{score_cox}
\alias{score_cox}
\title{Compute Cox Partial Log-Likelihood Score Vector}
\usage{
score_cox(X, eta, status, y = NULL, weights = 1)
}
\arguments{
\item{X}{Design matrix (N x p), sorted by ascending event time.}

\item{eta}{Linear predictor vector \eqn{\mathbf{X}\boldsymbol{\beta}}.}

\item{status}{Event indicator (1 = event, 0 = censored).}

\item{y}{Optional numeric vector of observed event/censor times, same length
and order as \code{eta}. When supplied, tied event times are handled with
the Breslow approximation. When omitted, the function assumes there are no
ties.}

\item{weights}{Observation weights (default 1).}
}
\value{
Numeric column vector of length p (gradient).
}
\description{
Gradient of the Cox partial log-likelihood with respect to
\eqn{\boldsymbol{\beta}}. Data must be sorted by ascending event time.
}
\details{
Under the Breslow approximation, the score is
\deqn{\mathbf{u} =
  \sum_g \Bigl[\sum_{i \in D_g} w_i \mathbf{x}_i -
  d_g^{(w)} \frac{\sum_{j \in R_g} w_j e^{\eta_j}\mathbf{x}_j}
  {\sum_{j \in R_g} w_j e^{\eta_j}}\Bigr]}
where \eqn{D_g} is the tied event set at time \eqn{t_g},
\eqn{R_g = \{j : t_j \ge t_g\}} is the risk set, and
\eqn{d_g^{(w)} = \sum_{i \in D_g} w_i}.
}
\keyword{internal}
