Cox regression (proportional hazards) explained, with an example

Updated

Cox regression, or the proportional hazards model, relates the risk of failure to predictors such as operating condition, supplier or a measured variable, using times to failure that may be censored. It does not assume a Weibull or any other life distribution. Instead it estimates hazard ratios: how many times higher the failure rate is under one condition than another, at any point in time.

When to use it

  • You have field or test data with failure times, some censored, and several factors that may affect life.
  • You care about which factors raise the risk and by how much, more than about predicting a B10 life.
  • No life distribution fits well, or different units were observed over very different periods.
  • You need to adjust one comparison for another factor, for example service type adjusted for installation quality.

How it works

The model says the hazard of unit i at time t is a common baseline hazard h₀(t), multiplied by a factor that depends on its predictors:

h(t | x) = h₀(t) · exp(β₁x₁ + β₂x₂ + …)

The baseline h₀(t) can have any shape and is never estimated directly. The coefficients are found by maximizing the partial likelihood: at each failure time, it asks how likely it was that the unit that failed, rather than any other unit still at risk, was the one to fail. Censored units count in the risk sets up to the time they leave the study. When several units fail at the same time, the risk set is shared; this example uses Breslow's method for those ties.

Each coefficient turns into a hazard ratio:

HR = exp(β)

An HR of 2 for a yes/no factor means units with the factor fail at twice the rate of units without it, at every age. For a numeric predictor, the HR applies per unit of that predictor. Tests use the z statistic β / SE(β) for each term and a likelihood ratio test for the whole model.

The key assumption is in the name: the hazards are proportional, so the ratio between two groups stays the same over time.

Example

A refinery tracks 20 identical process pumps for two years (730 days) after a seal upgrade. Ten pumps run in clean service and ten in abrasive slurry. At installation, the maintenance crew records each pump's vibration (mm/s). The outcome is days to the first seal failure; pumps without a failure are censored (+) at the end of the study or when they were taken out of service.

Clean: daysVibrationSlurry: daysVibration
1104.13682.5
2224.21704.0
1193.874.0
730+1.61401.7
411.754.4
632+2.51592.5
1704.14382.0
1344.4173.1
730+3.1243.4
521+3.9730+1.6

There are 15 seal failures. The Kaplan-Meier survival estimates already show the difference between services:

Fraction of pumps without a seal failure0.250.500.751.00SurvivalClean serviceSlurry service0100200300400500600700Days in service
Fraction of pumps without a seal failure

The Cox model with both predictors:

TermCoefficientSEzpHazard ratio95% CI
Slurry service1.4530.6022.410.0164.281.31 to 13.9
Vibration (mm/s)0.8550.3362.540.0112.351.22 to 4.54

The likelihood ratio test for the model is χ² = 9.03 with 2 degrees of freedom, p = 0.011.

  • A pump in slurry service has about 4.3 times the seal failure rate of a pump in clean service with the same installed vibration.
  • Each extra 1 mm/s of vibration at installation multiplies the failure rate by about 2.35. A pump installed at 4 mm/s carries 2.35² ≈ 5.5 times the risk of one installed at 2 mm/s.

Adjustment matters here. Fitted alone, service type gives an HR of only 2.04 with p = 0.18. The slurry pumps happened to be installed with lower vibration (mean 2.92 mm/s against 3.34 mm/s), which hid part of the slurry effect until vibration entered the model.

How to read the results

  • Read hazard ratios, not coefficients. An HR above 1 raises risk; below 1 lowers it. An interval that excludes 1 means the effect is statistically clear.
  • Look at the interval width. With 15 failures, the slurry HR could be anywhere from 1.3 to 14. The direction is clear; the size is not.
  • Check proportional hazards. Plot ln(−ln S(t)) against ln(t) for each group: roughly parallel curves support the model. Formal checks use scaled Schoenfeld residuals.
  • Remember what the model does not give. There is no B10 life without estimating the baseline hazard; for life percentiles, use Weibull regression.

Common mistakes

  • Comparing groups without adjusting. As the example shows, an uneven second factor can hide or exaggerate an effect.
  • Ignoring crossing survival curves. If one group fails early and the other late, hazards are not proportional and a single HR misleads.
  • Treating censored units as failures or dropping them. Pumps removed for other reasons count in the risk sets until they leave.
  • Fitting many predictors to few failures. A common guide is at least ten failures per predictor; this example, with 15 failures and two predictors, is already at the limit.

Frequently asked questions

What is the difference between a hazard ratio and a relative risk?

A hazard ratio compares instantaneous failure rates among units still running. A relative risk compares the probability of failing by a fixed time. They are close when failures are rare and drift apart as failures accumulate.

Why is Cox regression called semi-parametric?

The effect of the predictors is parametric (the exp(βx) factor), but the baseline hazard is left completely free. That is why it is robust to the shape of the life distribution.

Can Cox regression handle predictors that change over time?

Yes, with time-varying covariates, such as a pump's load each month. The data are then split into intervals, one row per interval, which needs care in setting up.

When should I prefer a Weibull model instead?

When the data follow a Weibull well and you need predictions such as B10 life or the reliability at a mission time, or when you must extrapolate beyond the observed times.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab