Cox Proportional Hazards › Formula
Machine Learning from ScratchAll chapters Cox Proportional Hazards › FormulaSection view · Sections in this chapter4 / 10 ↓
Reading tools Definitions, links & notes
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The Cox model makes two intertwined claims at once. First, covariates multiply the hazard through an exponential function of a linear predictor. Second, the effect of every covariate is the same at every time. Both claims appear in the same equation, so let us unpack them separately before we introduce any optimization machinery.
Proportional hazards and covariate effects
We start from the hazard function, which we introduced in the previous chapter. The hazard at time is the instantaneous rate of an event among survivors:
Here is the random event time, is a covariate vector for the individual, and is a small time increment. The hazard tells us how many events per unit time occur among those still at risk; the survival function , in contrast, tells us what fraction survive past . They are related by .
Why model the hazard rather than the survival probability directly? A hazard is a nonnegative rate, so a multiplicative model keeps every fitted hazard nonnegative automatically. It also has a natural "events per unit time among survivors" interpretation, which is often exactly the quantity a clinician, engineer, or product manager wants to reason about. Cox's claim is that this rate factors into a piece that depends only on and a piece that depends only on :
The function is the baseline hazard, defined as the hazard of an individual with , so every new symbol here is accounted for. The exponential does two jobs at once: it maps any real linear predictor to a positive multiplier, and it turns additive changes in into multiplicative changes in the hazard. A one-unit increase in covariate multiplies the hazard by at every time.
where:
- : time since the start of follow-up, measured in the same units as
- : the covariate vector for the individual
- : the coefficient vector, with the coefficient on covariate
- : the baseline hazard, the hazard of an individual whose covariates are all zero
- : the individual-specific multiplier that scales the baseline hazard up or down
The model becomes clear when we compare two individuals at the same instant. Taking the ratio of their hazards gives
The baseline cancels. That cancellation is the entire reason the Cox model is practical: the ratio of hazards depends only on and covariate differences, not on time. This is exactly the proportional hazards assumption, and the quantity is called the hazard ratio.
where:
- : the covariate vector for individual
- : the covariate vector for individual
- : the coefficient vector shared by all individuals
- : the ratio of the two individuals' hazards at time
For fixed covariates and times with positive baseline hazard, for a single binary covariate with , a unit change in the covariate halves the hazard at every point in time. The "proportional" in the name refers to this ratio: the two hazard curves may have any common shape , but their vertical ratio is fixed.
Let us be precise about what a hazard ratio is not. For the Cox model the survival function has a very specific form. In the previous chapter we saw that , where is the cumulative hazard. Substituting the Cox hazard gives
where is the baseline survival function and is the baseline cumulative hazard.
where:
- : time since the start of follow-up
- : the covariate vector for the individual
- : the baseline hazard at time
- : the baseline cumulative hazard, the total accumulated hazard up to time
- : the baseline survival function, the survival probability when all covariates are zero
- : the individual-specific multiplier that scales the cumulative hazard
- : the survival probability of an individual with covariates
The ratio of survival probabilities between two individuals is therefore
which depends on through .
where:
- : the covariate vectors of the two individuals being compared
- : the baseline cumulative hazard up to time
- : the coefficient vector shared by all individuals
- : the ratio of the two individuals' survival probabilities at time
A hazard ratio of does not mean "survival is 50% higher" or "the event is twice as likely"; it means "the instantaneous event rate is half as large at every moment." The survival gap can change over time. If the cumulative baseline hazard grows without bound, both survival probabilities tend to zero and their difference eventually vanishes; finite follow-up or a finite limiting cumulative hazard need not show that full pattern. Use the survival curves to explain how a hazard ratio differs from a survival-probability comparison.
Risk sets and partial likelihood
The proportional hazards equation describes the model, but it still contains the unknown function . If we tried to maximize an ordinary likelihood, we would need to specify and estimate that function at every time. Cox's second insight avoids this entirely by asking a conditional question at each event time. The object that makes the question precise is the risk set. At any time , the risk set is the set of individuals who have not yet experienced an event and have not yet been censored. Equivalently,
Here is the observed duration, is the latent event time and is the censoring time. Everyone enters at time zero in this implementation. Individuals censored at an event time are included in the risk set immediately before that time, with events processed before censoring at the same recorded time.
where:
- : a time point at which we evaluate who is still under observation
- : an index running over the subjects in the study
- : the observed event or censoring duration of subject
- : the risk set, the set of subjects still at risk (not yet failed and not yet censored) at time
A censored subject remains in every risk set up to their censoring time, even though they never contribute a numerator term. This is why survival data cannot be reduced to ordinary classification: dropping censored rows would discard the very information that tells us who was still at risk when later events occurred.
Suppose the observed event times are , with the number of distinct event times (for now we assume no ties). Let be the individual who failed at . Cox's idea is to ask a conditional question at each event time: given that some individual in the risk set failed at , what is the probability that it was individual in particular? The probability is
where:
- : the -th distinct event time
- : the individual who fails at
- : the covariate vector of the failing individual
- : the risk set at event time
- : the hazard of individual at time
- : the conditional probability that the failing individual was , given that exactly one individual in the risk set failed at
Pulling out the factor , which appears in every term in the numerator and denominator, gives
The baseline hazard vanished. This is the partial likelihood contribution at time . It is a "partial" likelihood because it models only the identity of the failure within the risk set, not the absolute time at which the failure occurred. Multiplying contributions across event times gives the partial likelihood
where:
- : the number of distinct event times
- : the -th distinct event time, with
- : the individual who fails at
- : the covariate vector of the failing individual at
- : the risk set at event time
- : the coefficient vector to be estimated
- : the partial likelihood, a function of after the baseline hazard has cancelled
Taking logs turns the product into a sum and the fractions into differences:
Each event contributes a numerator term (the log weight of the individual that failed) minus a denominator term (the log of the total weight of everyone who was at risk). Maximizing therefore means finding the that makes the observed failures look as likely as possible given who was at risk when they happened. Increasing , holding the other coefficients fixed, raises the relative weight of higher- individuals. An event’s derivative with respect to this coefficient is positive when the failing individual exceeds the current weighted risk-set mean. Information also depends on covariate spread and weights: a one-subject risk set contributes none, but the number of alternatives alone does not determine the strength of evidence.
The partial likelihood is not the joint density of the observed data: it models the identities of failures conditional on the risk sets, rather than the full distribution of observed event and censoring times. Cox (1975) outlined why partial likelihood supports likelihood-like large-sample inference. Under suitable regularity and sampling conditions, the Cox partial-likelihood estimator is consistent and asymptotically normal (Andersen and Gill, 1982), and inverse observed information provides an approximate model-based covariance. To derive the score equations, treat exactly as you would treat a log-likelihood.
In matrix form, if we let be the event indicator for individual and the at-risk indicator, the log partial likelihood can be written
where:
- : the number of individuals in the study
- : the event indicator for individual (1 if the event was observed, 0 if censored)
- : the at-risk indicator for individual , equal to 1 if is still at risk at time
- : the observed event or censoring time of individual
- : the covariate vectors of individuals and
- : the coefficient vector to be estimated
This form makes it clear that only individuals who have contribute numerator terms, while censored individuals still appear in the denominator of every risk set that includes them. The risk-set denominator is the mechanism that lets censored observations speak: they do not need an event to influence the fit, because their presence tells us which covariate profiles were available to fail.
Coefficient fitting, ties, and baseline estimation
To maximize we take derivatives. For the -th component of , differentiate the numerator to get , and for the log-sum-exp use the chain rule: the derivative of is the weighted average of using the exponential weights. The result is the score function
Each event's contribution is exactly "the observed covariate of the failing individual minus the risk-set average of that covariate." Setting the score to zero is what fitting means in the Cox model, and it is a clean "observed minus expected" condition that mirrors ordinary MLE. An event contributes positively when the failing individual has a larger covariate value than the weighted risk-set mean. A positive total score component means that an infinitesimal increase in that coefficient, holding the others fixed, raises the log partial likelihood. A multivariable Newton update couples coordinates through the Hessian, so its individual coefficient changes need not follow the signs of the score components.
The Hessian is obtained by differentiating once more. Writing for the risk-set weighted mean with weights , we get
where:
- : the log partial likelihood
- : the -th and -th components of the coefficient vector
- : an index running over the distinct event times
- : the -th distinct event time
- : the risk set at event time
- : the weight of individual in the risk set
- : the risk-set weighted mean of covariate
- : the risk-set weighted mean of the product
The bracket is a weighted covariance matrix and is therefore positive semidefinite, which makes the Hessian negative semidefinite. That is, is concave. Concavity rules out a stationary point with a lower objective than an attainable global maximum. Strict concavity can give uniqueness when a finite maximum exists, but full design rank alone does not establish finite estimability. Separation or lack of risk-set variation can prevent a finite unique estimate, and unmodified Newton steps have no arbitrary-start convergence guarantee. Unlike ordinary least squares, this fit generally requires iterative optimization. Concavity does not establish an OLS-style closed-form solution, equal computational cost, or convergence of arbitrary Newton steps.
Real data often produce ties, in which several individuals record an event at the same time. With events at time and event set , the untied expression no longer specifies an ordering within the tied group. Exact tie treatments depend on whether times are modeled as discrete or as coarsened continuous observations and can be expensive. Two approximations are common. The Breslow approximation treats each tied event as if the others were still at risk:
where:
- : an index over the distinct event times that carry ties
- : a distinct event time at which events are recorded
- : the set of individuals who fail at time , with
- : the number of tied events at time
- : the risk set at time
- : the covariate vectors of individuals and
- : the coefficient vector
The Efron approximation accounts for depletion of the tied event set because it gradually removes events from the denominator as we imagine the tie broken:
where:
- : an index over the distinct event times that carry ties
- : a distinct event time at which events are recorded
- : the set of individuals who fail at time , with
- : the number of tied events at time
- : the risk set at time
- : an index running from to that progressively removes tied failures from the denominator
- : the covariate vectors of individuals and
- : the coefficient vector
With one event at a time the two formulas coincide. With multiple tied events they can differ, and the difference depends on the event weights as well as the tie count. Efron is often used for coarsened continuous times; genuinely discrete-time data can call for a different model. We specify the tie method explicitly rather than relying on a software default.
The final ingredient is the baseline hazard. Cox's partial likelihood deliberately hides , but to turn coefficients into survival curves we need to recover it. The standard estimator is Breslow's:
Each event time contributes the number of events divided by the total at-risk weight at that time. Summing these increments accumulates an estimate of the cumulative baseline hazard. Given , individual survival follows from
where:
- : time since the start of follow-up
- : the covariate vector for the individual
- : the Breslow estimate of the baseline cumulative hazard up to time
- : the fitted coefficient vector
- : the estimated survival probability for an individual with covariates
Because is a step function, is a step function too; between event times, survival is treated as constant.
Mathematical Properties
Three properties guide the fit. First, the log partial likelihood is concave, but a finite identifiable optimum and adequate risk-set covariate variation still matter; full column rank alone does not guarantee a finite estimate or global Newton convergence. Second, the time-invariant hazard multiplier applies to fixed covariates under proportional hazards. Third, inverse observed information gives an approximate model-based covariance under regularity conditions, rather than an exact finite-sample uncertainty guarantee.
There is also an important invariance we will use implicitly later. Because the partial likelihood depends on covariate values only through differences within each risk set, adding a constant shift to any covariate in has no effect on , only on the baseline, which absorbs the shift. A constant intercept is not separately identified from the Cox baseline hazard. This differs from ordinary logistic regression, where an intercept usually is identifiable.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!