Search

Search papers and lessons

Cox Proportional Hazards Model

Level 4 · 11 min read

The Cox model describes how covariates scale the risk of an event at every moment, and it fits that scaling without ever specifying the baseline risk over time.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Inference
  • Sign in to see your progress

TL;DR

The Cox model studies how factors such as age, a treatment or a smoking habit change the rate at which an event happens, such as death or relapse. It says each factor multiplies the hazard, the instantaneous risk, by a fixed amount at every moment in time. The fixed amount is estimated without ever specifying how the baseline risk changes over time.

That last point is the trick. Because the baseline cancels out, the model can compare groups using only the order in which events happened.

Where you'll see it: in clinical trials that report "hazard ratio 0.7" for a new drug, in survival analyses of patients after surgery, and in reliability studies of machines that fail over time.

This lesson explains a statistical method. It is education, not medical advice.

Intuition

Start from a question you already know

Two groups of patients are followed after surgery. One group had a new drug, the other a placebo. The question is simple: does the drug change how quickly the event happens? A survival curve answers "how many are still alive at each time?" (survival function), and Kaplan–Meier curves estimate it from data. But a curve does not say how much the drug changes the risk, and it is hard to adjust for age or other factors at the same time.

One multiplier for every moment

Think of the risk at each moment as a baseline risk times a multiplier. The multiplier depends on the patient's covariates, the measured factors such as treatment group, age or dose. For example, a treated patient might have a risk 0.7 times the baseline at every single moment. The key assumption is that the multiplier does not change with time. If treated patients are always at 0.7 times the baseline, the two curves are proportional in risk, and that is where the name "proportional hazards" comes from.

The model's power is that you do not need to know the baseline risk. You only need the multiplier. The baseline risk is a nuisance that cancels out of every comparison.

The math

Hazard

Definition: Hazard function

For a time TT until an event, the hazard at time tt is

h(t)=lim⁡Δ→0Pr⁡[t≤T<t+Δ∣T≥t]Δ.h(t) = \lim_{\Delta \to 0} \frac{\Pr[t \le T \lt t + \Delta \mid T \ge t]}{\Delta}.

In words, h(t) Δh(t)\,\Delta is the chance the event happens in the next small interval, given that it has not happened by time tt. The hazard is a rate, not a probability, and it can be bigger than 1. It is linked to the survival function S(t)=Pr⁡[T>t]S(t) = \Pr[T \gt t] by h(t)=−ddtlog⁡S(t)h(t) = -\frac{d}{dt}\log S(t), so the hazard and the survival curve carry the same information. See the hazard function for more on this.

The model

For a patient with covariates x=(x1,…,xp)\mathbf{x} = (x_1, \dots, x_p), such as a treatment flag, an age, or a dose, the Cox model says

h(t∣x)=h0(t) exp⁡(β⊤x).h(t \mid \mathbf{x}) = h_0(t)\, \exp(\boldsymbol{\beta}^\top \mathbf{x}).

Here h0(t)h_0(t) is the baseline hazard, the risk for a patient whose covariates are all zero. The vector β\boldsymbol{\beta} holds one coefficient per covariate, and exp⁡(β⊤x)\exp(\boldsymbol{\beta}^\top \mathbf{x}), the Exponential Function of the weighted sum β⊤x\boldsymbol{\beta}^\top \mathbf{x}, is the multiplier, always positive. Taking the ratio of hazards for two patients gives

h(t∣x1)h(t∣x2)=exp⁡(β⊤(x1−x2)).\frac{h(t \mid \mathbf{x}_1)}{h(t \mid \mathbf{x}_2)} = \exp\big(\boldsymbol{\beta}^\top(\mathbf{x}_1 - \mathbf{x}_2)\big).

The right side does not contain tt. That is the proportional hazards assumption, and it is the only real restriction the model makes. For a single binary treatment flag xx, the hazard ratio is eβe^{\beta}. If β=ln⁡2\beta = \ln 2, the treated hazard is twice the control hazard at every time.

Partial likelihood

The baseline h0(t)h_0(t) is never specified. Cox's idea was to build a likelihood that ignores it. Order the event times t(1)<t(2)<…t_{(1)} \lt t_{(2)} \lt \dots (assume no ties for now). At time t(j)t_{(j)}, the risk set RjR_j is the set of subjects still under observation and not yet failed just before that time. Given that one event happens at t(j)t_{(j)} to someone in RjR_j, the chance that it is subject ii is

h0(t(j)) eβ⊤xi∑k∈Rjh0(t(j)) eβ⊤xk=eβ⊤xi∑k∈Rjeβ⊤xk.\frac{h_0(t_{(j)})\, e^{\boldsymbol{\beta}^\top \mathbf{x}_i}}{\sum_{k \in R_j} h_0(t_{(j)})\, e^{\boldsymbol{\beta}^\top \mathbf{x}_k}} = \frac{e^{\boldsymbol{\beta}^\top \mathbf{x}_i}}{\sum_{k \in R_j} e^{\boldsymbol{\beta}^\top \mathbf{x}_k}}.

The baseline h0(t(j))h_0(t_{(j)}) appears in top and bottom and cancels. Multiplying these conditional probabilities over all event times gives the partial likelihood

L(β)=∏jeβ⊤x(j)∑k∈Rjeβ⊤xk,L(\boldsymbol{\beta}) = \prod_{j} \frac{e^{\boldsymbol{\beta}^\top \mathbf{x}_{(j)}}}{\sum_{k \in R_j} e^{\boldsymbol{\beta}^\top \mathbf{x}_k}},

where x(j)\mathbf{x}_{(j)} is the covariate vector of the subject who failed at t(j)t_{(j)}. Censored subjects enter the risk sets while they are under observation, and they are never the failing subject. This is how censoring is handled without estimating h0h_0.

Taking the Logarithm gives the function we maximise, the log partial likelihood:

ℓ(β)=∑j[β⊤x(j)−log⁡∑k∈Rjeβ⊤xk].\ell(\boldsymbol{\beta}) = \sum_{j} \Big[\boldsymbol{\beta}^\top \mathbf{x}_{(j)} - \log \sum_{k \in R_j} e^{\boldsymbol{\beta}^\top \mathbf{x}_k}\Big].

Setting the derivative to zero gives the estimate β^\hat{\boldsymbol{\beta}}. This is the usual maximum likelihood recipe, applied to the partial likelihood. Standard software solves it with repeated Newton steps, and the function is concave in β\boldsymbol{\beta}, meaning it has a single peak, so the search does not get stuck.

Worked examples

Example
Example 1: evaluate the partial likelihood by hand

Three subjects. Subject A has covariate x=1x = 1 (treated), subjects B and C have x=0x = 0 (control). There is no censoring. The events happen in this order:

  • t=1t = 1: B fails. The risk set is {A,B,C}\{A, B, C\}.
  • t=2t = 2: A fails. The risk set is {A,C}\{A, C\}.
  • t=3t = 3: C fails. The risk set is {C}\{C\}.

Write u=eβu = e^{\beta}. The three factors of the partial likelihood are:

  1. At t=1t = 1: B's factor is 1u+1+1=1u+2\dfrac{1}{u + 1 + 1} = \dfrac{1}{u+2}.
  2. At t=2t = 2: A's factor is uu+1\dfrac{u}{u + 1}.
  3. At t=3t = 3: C's factor is 11=1\dfrac{1}{1} = 1.

So L(β)=u(u+2)(u+1)L(\beta) = \dfrac{u}{(u+2)(u+1)}.

Evaluate at two values of β\beta:

  • At β=0\beta = 0 (u=1u = 1): L=13⋅2=16≈0.1667L = \dfrac{1}{3 \cdot 2} = \dfrac{1}{6} \approx 0.1667.
  • At β=12ln⁡2\beta = \tfrac{1}{2}\ln 2 (u=2≈1.4142u = \sqrt{2} \approx 1.4142): L=1.41423.4142×2.4142≈0.1716L = \dfrac{1.4142}{3.4142 \times 2.4142} \approx 0.1716.

Interpretation: the second value makes the observed order of failures more probable, so it fits better than β=0\beta = 0.

Example
Example 2: the maximum, for the same three subjects

Continue with Example 1. Take the log-likelihood ℓ=log⁡u−log⁡(u+2)−log⁡(u+1)\ell = \log u - \log(u+2) - \log(u+1) with u=eβu = e^\beta. Setting its derivative with respect to β\beta to zero:

  1. dℓdβ=1−uu+2−uu+1=0\dfrac{d\ell}{d\beta} = 1 - \dfrac{u}{u+2} - \dfrac{u}{u+1} = 0.
  2. Rearrange: 2u+2=uu+1\dfrac{2}{u+2} = \dfrac{u}{u+1}.
  3. Cross-multiply: 2(u+1)=u(u+2)2(u+1) = u(u+2), so 2u+2=u2+2u2u + 2 = u^2 + 2u.
  4. Hence u2=2u^2 = 2, so u=2u = \sqrt{2} and β^=12ln⁡2≈0.347\hat\beta = \tfrac{1}{2}\ln 2 \approx 0.347.
  5. The estimated hazard ratio is eβ^=2≈1.41e^{\hat\beta} = \sqrt{2} \approx 1.41.

Check: the second derivative is −2u(u+2)2−u(u+1)2<0-\dfrac{2u}{(u+2)^2} - \dfrac{u}{(u+1)^2} \lt 0 for all u>0u \gt 0, so this stationary point is the maximum.

Interpretation: the treated subject failed later than the control subject B but earlier than the control subject C, so the data suggest a hazard about 41% higher for the treated group. With three subjects this is a toy, but the algebra is exactly the algebra used on real data.

Example
Example 3: turning a hazard ratio into survival curves (illustrative numbers)

Suppose a large study fits β^\hat\beta for a treatment, and the hazard ratio is eβ^=2e^{\hat\beta} = 2. The numbers below are illustrative, not from a real study.

  1. Since S(t)=e−H(t)S(t) = e^{-H(t)} with cumulative hazard HH, and the model multiplies the hazard, and so HH, by exp⁡(βx)\exp(\beta x), the survival curves satisfy S(t∣x)=S0(t)exp⁡(βx)S(t \mid x) = S_0(t)^{\exp(\beta x)}, where S0S_0 is the baseline survival.
  2. Say the baseline survival at five years is S0(5)=0.80S_0(5) = 0.80.
  3. For the treated group, the multiplier is 2, so S(5∣treated)=0.802=0.64S(5 \mid \text{treated}) = 0.80^2 = 0.64.
  4. Check the hazards: −log⁡S(5∣treated)=2⋅(−log⁡0.80)-\log S(5 \mid \text{treated}) = 2 \cdot (-\log 0.80), so the cumulative hazard doubles, matching the hazard ratio.
  5. Note what changes: the gap between the curves depends on S0S_0, but the ratio of hazards does not.

Interpretation: a hazard ratio of 2 does not mean the treated group has twice the risk of dying in five years. Here the five-year death risk goes from 20% to 36%, which is not a doubling. Hazard ratios describe rates, and absolute risks need the baseline curve too.

Tradeoffs and failure modes

SituationProblemBetter choice
Survival curves crossThe proportional hazards assumption fails, so one hazard ratio misleadsTime-varying coefficients, or stratify by the offending covariate
Many tied event timesThe partial likelihood formula above needs a correctionEfron or Breslow tie handling, built into standard software
You need absolute risks or the full baselineThe model never estimates h0h_0A fully parametric survival model, or the Breslow baseline estimate after fitting
Covariate effects are nonlinearThe model assumes the log hazard is linear in x\mathbf{x}Splines or transformations of covariates
Few events for many covariatesEstimates overfit and become unstableFewer covariates; a common rule of thumb is roughly ten events per covariate
Censoring depends on the outcomeThe partial likelihood assumes censoring is not informativeModel the censoring process, or change the study design

The proportional hazards assumption is the one to check first. Plot log⁡(−log⁡S(t))\log(-\log S(t)) against log⁡t\log t for each group: parallel lines are consistent with proportional hazards. Crossing or diverging lines are a warning. Formal tests of the assumption also exist, but a plot shows the reason for a failure.

Failure is also quiet. The software returns a hazard ratio for any input, so the checks above are the only guard against a misleading one.

History

David Cox introduced the model in 1972 in "Regression Models and Life-Tables", presented to the Royal Statistical Society. The problem was medical follow-up: how to adjust survival comparisons for several factors without assuming a shape for the baseline risk. Earlier methods either assumed a parametric form for the time dependence or only compared groups in tables.

Cox's 1975 paper "Partial likelihood" gave the conditional likelihood that makes the method work without estimating the baseline. The model caught on quickly because clinical trials needed a single, interpretable number, the hazard ratio, that could be reported across studies. It became one of the most cited methods in medical statistics.

Recap

The Cox model writes the hazard as a baseline times exp⁡(β⊤x)\exp(\boldsymbol{\beta}^\top \mathbf{x}). The proportional hazards assumption means the covariate multiplier does not depend on time. Partial likelihood compares the subject who failed with the others still at risk at each event time, so the baseline cancels and censored subjects contribute through the risk sets. Maximising it gives β^\hat{\boldsymbol{\beta}} and hazard ratios eβ^e^{\hat\beta}. Interpret hazard ratios as rate multipliers, and check the proportional hazards assumption before trusting them.

Check yourself

QuestionIn the model h(t∣x)=h0(t)exp⁡(βx)h(t \mid x) = h_0(t)\exp(\beta x) for a binary xx, why does the hazard ratio between x=1x = 1 and x=0x = 0 not depend on tt?Show answer

Both hazards share the same baseline h0(t)h_0(t), which appears as a factor in each. In the ratio h0(t)eβh0(t)e0\dfrac{h_0(t)e^{\beta}}{h_0(t)e^{0}} the baseline cancels, leaving eβe^{\beta} at every tt. That constant ratio is the proportional hazards assumption.

QuestionUsing Example 1, what is the partial likelihood factor at t=1t = 1 if β=ln⁡3\beta = \ln 3, so u=3u = 3?Show answer

Subject B fails at t=1t = 1, and the risk set is {A,B,C}\{A, B, C\} with multipliers u=3u = 3 for A and 11 for both B and C. B's factor is 13+1+1=15=0.2\dfrac{1}{3 + 1 + 1} = \dfrac{1}{5} = 0.2.

QuestionWhy are censored subjects kept in the risk sets, instead of being dropped from the analysis?Show answer

A censored subject was still under observation at the time of each earlier event, so it was a possible failure at those times. Dropping it would make the others look more likely to fail, biasing the estimate. The subject's censoring time is the point after which it leaves the risk sets.

QuestionA study reports a hazard ratio of 0.5 for a drug. A reader says the drug halves the chance of dying. What is wrong with that reading, and what would you need to say it?Show answer

A hazard ratio compares rates at every moment, not the probability of an event over a period. Halving the hazard at every time does not halve the cumulative probability, because the survival curves also depend on the baseline. To state a risk reduction, you need the baseline survival or the survival curves for both groups, for example a five-year survival of 0.80 under control, which a hazard ratio of 0.5 turns into 0.800.5≈0.890.80^{0.5} \approx 0.89 under treatment, a death risk falling from 20% to about 11%, not from 20% to 10%.

QuestionTwo groups have survival curves that cross at three years. What does this suggest about the Cox model's hazard ratio, and what should you do?Show answer

Crossing curves mean the hazard ratio changes over time, so the proportional hazards assumption likely fails. A single hazard ratio would summarise two different effects and could mislead. Check the assumption with a log-log plot or a formal test, and consider time-varying coefficients or stratification by the group before reporting one number.

Sources